Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
10fc441c
Commit
10fc441c
authored
May 26, 2020
by
GitLab Bot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latest changes from gitlab-org/security/gitlab@12-10-stable-ee
parent
4cc9d3e2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
3 deletions
+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
No files found.
changelogs/unreleased/216528-confidential-issue.yml
0 → 100644
View file @
10fc441c
---
title
:
Add an extra validation to Static Site Editor payload
merge_request
:
author
:
type
:
security
lib/gitlab/static_site_editor/config.rb
View file @
10fc441c
...
@@ -21,7 +21,7 @@ module Gitlab
...
@@ -21,7 +21,7 @@ module Gitlab
project_id:
project
.
id
,
project_id:
project
.
id
,
project:
project
.
path
,
project:
project
.
path
,
namespace:
project
.
namespace
.
path
,
namespace:
project
.
namespace
.
path
,
return_url:
return_url
,
return_url:
sanitize_url
(
return_url
)
,
is_supported_content:
supported_content?
is_supported_content:
supported_content?
}
}
end
end
...
@@ -47,6 +47,10 @@ module Gitlab
...
@@ -47,6 +47,10 @@ module Gitlab
def
file_exists?
def
file_exists?
commit_id
.
present?
&&
repository
.
blob_at
(
commit_id
,
file_path
).
present?
commit_id
.
present?
&&
repository
.
blob_at
(
commit_id
,
file_path
).
present?
end
end
def
sanitize_url
(
url
)
url
if
Gitlab
::
UrlSanitizer
.
valid_web?
(
url
)
end
end
end
end
end
end
end
lib/gitlab/url_sanitizer.rb
View file @
10fc441c
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
module
Gitlab
module
Gitlab
class
UrlSanitizer
class
UrlSanitizer
ALLOWED_SCHEMES
=
%w[http https ssh git]
.
freeze
ALLOWED_SCHEMES
=
%w[http https ssh git]
.
freeze
ALLOWED_WEB_SCHEMES
=
%w[http https]
.
freeze
def
self
.
sanitize
(
content
)
def
self
.
sanitize
(
content
)
regexp
=
URI
::
DEFAULT_PARSER
.
make_regexp
(
ALLOWED_SCHEMES
)
regexp
=
URI
::
DEFAULT_PARSER
.
make_regexp
(
ALLOWED_SCHEMES
)
...
@@ -12,17 +13,21 @@ module Gitlab
...
@@ -12,17 +13,21 @@ module Gitlab
content
.
gsub
(
regexp
,
''
)
content
.
gsub
(
regexp
,
''
)
end
end
def
self
.
valid?
(
url
)
def
self
.
valid?
(
url
,
allowed_schemes:
ALLOWED_SCHEMES
)
return
false
unless
url
.
present?
return
false
unless
url
.
present?
return
false
unless
url
.
is_a?
(
String
)
return
false
unless
url
.
is_a?
(
String
)
uri
=
Addressable
::
URI
.
parse
(
url
.
strip
)
uri
=
Addressable
::
URI
.
parse
(
url
.
strip
)
ALLOWED_SCHEMES
.
include?
(
uri
.
scheme
)
allowed_schemes
.
include?
(
uri
.
scheme
)
rescue
Addressable
::
URI
::
InvalidURIError
rescue
Addressable
::
URI
::
InvalidURIError
false
false
end
end
def
self
.
valid_web?
(
url
)
valid?
(
url
,
allowed_schemes:
ALLOWED_WEB_SCHEMES
)
end
def
initialize
(
url
,
credentials:
nil
)
def
initialize
(
url
,
credentials:
nil
)
%i[user password]
.
each
do
|
symbol
|
%i[user password]
.
each
do
|
symbol
|
credentials
[
symbol
]
=
credentials
[
symbol
].
presence
if
credentials
&
.
key?
(
symbol
)
credentials
[
symbol
]
=
credentials
[
symbol
].
presence
if
credentials
&
.
key?
(
symbol
)
...
...
spec/lib/gitlab/static_site_editor/config_spec.rb
View file @
10fc441c
...
@@ -57,5 +57,23 @@ describe Gitlab::StaticSiteEditor::Config do
...
@@ -57,5 +57,23 @@ describe Gitlab::StaticSiteEditor::Config do
it
{
is_expected
.
to
include
(
is_supported_content:
false
)
}
it
{
is_expected
.
to
include
(
is_supported_content:
false
)
}
end
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
end
end
spec/lib/gitlab/url_sanitizer_spec.rb
View file @
10fc441c
...
@@ -60,6 +60,30 @@ describe Gitlab::UrlSanitizer do
...
@@ -60,6 +60,30 @@ describe Gitlab::UrlSanitizer do
end
end
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
describe
'#sanitized_url'
do
context
'credentials in hash'
do
context
'credentials in hash'
do
where
(
username:
[
'foo'
,
''
,
nil
],
password:
[
'bar'
,
''
,
nil
])
where
(
username:
[
'foo'
,
''
,
nil
],
password:
[
'bar'
,
''
,
nil
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment