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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
9401c137
Commit
9401c137
authored
Sep 29, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Just allow the scheme we want!
parent
f7fd36f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
7 deletions
+6
-7
lib/gitlab/url_sanitizer.rb
lib/gitlab/url_sanitizer.rb
+5
-3
spec/lib/gitlab/url_sanitizer_spec.rb
spec/lib/gitlab/url_sanitizer_spec.rb
+1
-4
No files found.
lib/gitlab/url_sanitizer.rb
View file @
9401c137
module
Gitlab
class
UrlSanitizer
ALLOWED_SCHEMES
=
%w[http https ssh git]
def
self
.
sanitize
(
content
)
regexp
=
URI
::
Parser
.
new
.
make_regexp
(
%w(http https ssh git)
)
regexp
=
URI
::
Parser
.
new
.
make_regexp
(
ALLOWED_SCHEMES
)
content
.
gsub
(
regexp
)
{
|
url
|
new
(
url
).
masked_url
}
rescue
Addressable
::
URI
::
InvalidURIError
...
...
@@ -11,9 +13,9 @@ module Gitlab
def
self
.
valid?
(
url
)
return
false
unless
url
.
present?
Addressable
::
URI
.
parse
(
url
.
strip
)
uri
=
Addressable
::
URI
.
parse
(
url
.
strip
)
true
ALLOWED_SCHEMES
.
include?
(
uri
.
scheme
)
rescue
Addressable
::
URI
::
InvalidURIError
false
end
...
...
spec/lib/gitlab/url_sanitizer_spec.rb
View file @
9401c137
...
...
@@ -40,7 +40,7 @@ describe Gitlab::UrlSanitizer do
false
|
''
false
|
'123://invalid:url'
false
|
'valid@project:url.git'
true
|
'valid:pass@project:url.git'
false
|
'valid:pass@project:url.git'
true
|
'ssh://example.com'
true
|
'ssh://:@example.com'
true
|
'ssh://foo@example.com'
...
...
@@ -117,9 +117,6 @@ describe Gitlab::UrlSanitizer do
'http://@example.com'
|
{
user:
nil
,
password:
nil
}
'http://example.com'
|
{
user:
nil
,
password:
nil
}
# Credentials from SCP-style URLs are not supported at present
'foo:bar@example.com:path'
|
{
user:
nil
,
password:
nil
}
# Other invalid URLs
nil
|
{
user:
nil
,
password:
nil
}
''
|
{
user:
nil
,
password:
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