Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
10fc441c
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
10fc441c
编写于
5月 26, 2020
作者:
G
GitLab Bot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add latest changes from gitlab-org/security/gitlab@12-10-stable-ee
上级
4cc9d3e2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
3 deletion
+59
-3
changelogs/unreleased/216528-confidential-issue.yml
changelogs/unreleased/216528-confidential-issue.yml
+5
-0
lib/gitlab/static_site_editor/config.rb
lib/gitlab/static_site_editor/config.rb
+5
-1
lib/gitlab/url_sanitizer.rb
lib/gitlab/url_sanitizer.rb
+7
-2
spec/lib/gitlab/static_site_editor/config_spec.rb
spec/lib/gitlab/static_site_editor/config_spec.rb
+18
-0
spec/lib/gitlab/url_sanitizer_spec.rb
spec/lib/gitlab/url_sanitizer_spec.rb
+24
-0
未找到文件。
changelogs/unreleased/216528-confidential-issue.yml
0 → 100644
浏览文件 @
10fc441c
---
title
:
Add an extra validation to Static Site Editor payload
merge_request
:
author
:
type
:
security
lib/gitlab/static_site_editor/config.rb
浏览文件 @
10fc441c
...
...
@@ -21,7 +21,7 @@ module Gitlab
project_id:
project
.
id
,
project:
project
.
path
,
namespace:
project
.
namespace
.
path
,
return_url:
return_url
,
return_url:
sanitize_url
(
return_url
)
,
is_supported_content:
supported_content?
}
end
...
...
@@ -47,6 +47,10 @@ module Gitlab
def
file_exists?
commit_id
.
present?
&&
repository
.
blob_at
(
commit_id
,
file_path
).
present?
end
def
sanitize_url
(
url
)
url
if
Gitlab
::
UrlSanitizer
.
valid_web?
(
url
)
end
end
end
end
lib/gitlab/url_sanitizer.rb
浏览文件 @
10fc441c
...
...
@@ -3,6 +3,7 @@
module
Gitlab
class
UrlSanitizer
ALLOWED_SCHEMES
=
%w[http https ssh git]
.
freeze
ALLOWED_WEB_SCHEMES
=
%w[http https]
.
freeze
def
self
.
sanitize
(
content
)
regexp
=
URI
::
DEFAULT_PARSER
.
make_regexp
(
ALLOWED_SCHEMES
)
...
...
@@ -12,17 +13,21 @@ module Gitlab
content
.
gsub
(
regexp
,
''
)
end
def
self
.
valid?
(
url
)
def
self
.
valid?
(
url
,
allowed_schemes:
ALLOWED_SCHEMES
)
return
false
unless
url
.
present?
return
false
unless
url
.
is_a?
(
String
)
uri
=
Addressable
::
URI
.
parse
(
url
.
strip
)
ALLOWED_SCHEMES
.
include?
(
uri
.
scheme
)
allowed_schemes
.
include?
(
uri
.
scheme
)
rescue
Addressable
::
URI
::
InvalidURIError
false
end
def
self
.
valid_web?
(
url
)
valid?
(
url
,
allowed_schemes:
ALLOWED_WEB_SCHEMES
)
end
def
initialize
(
url
,
credentials:
nil
)
%i[user password]
.
each
do
|
symbol
|
credentials
[
symbol
]
=
credentials
[
symbol
].
presence
if
credentials
&
.
key?
(
symbol
)
...
...
spec/lib/gitlab/static_site_editor/config_spec.rb
浏览文件 @
10fc441c
...
...
@@ -57,5 +57,23 @@ describe Gitlab::StaticSiteEditor::Config do
it
{
is_expected
.
to
include
(
is_supported_content:
false
)
}
end
context
'when return_url is not a valid URL'
do
let
(
:return_url
)
{
'example.com'
}
it
{
is_expected
.
to
include
(
return_url:
nil
)
}
end
context
'when return_url has a javascript scheme'
do
let
(
:return_url
)
{
'javascript:alert(document.domain)'
}
it
{
is_expected
.
to
include
(
return_url:
nil
)
}
end
context
'when return_url is missing'
do
let
(
:return_url
)
{
nil
}
it
{
is_expected
.
to
include
(
return_url:
nil
)
}
end
end
end
spec/lib/gitlab/url_sanitizer_spec.rb
浏览文件 @
10fc441c
...
...
@@ -60,6 +60,30 @@ describe Gitlab::UrlSanitizer do
end
end
describe
'.valid_web?'
do
where
(
:value
,
:url
)
do
false
|
nil
false
|
''
false
|
'123://invalid:url'
false
|
'valid@project:url.git'
false
|
'valid:pass@project:url.git'
false
|
%w(test array)
false
|
'ssh://example.com'
false
|
'ssh://:@example.com'
false
|
'ssh://foo@example.com'
false
|
'ssh://foo:bar@example.com'
false
|
'ssh://foo:bar@example.com/group/group/project.git'
false
|
'git://example.com/group/group/project.git'
false
|
'git://foo:bar@example.com/group/group/project.git'
true
|
'http://foo:bar@example.com/group/group/project.git'
true
|
'https://foo:bar@example.com/group/group/project.git'
end
with_them
do
it
{
expect
(
described_class
.
valid_web?
(
url
)).
to
eq
(
value
)
}
end
end
describe
'#sanitized_url'
do
context
'credentials in hash'
do
where
(
username:
[
'foo'
,
''
,
nil
],
password:
[
'bar'
,
''
,
nil
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录