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
15bb7e97
Commit
15bb7e97
authored
May 10, 2016
by
Rubén Dávila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mask credentials in URLs instead of remove them.
Also refactored Project#safe_import_url
parent
776f3c1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
13 deletions
+15
-13
app/models/project.rb
app/models/project.rb
+1
-6
lib/gitlab/url_sanitizer.rb
lib/gitlab/url_sanitizer.rb
+8
-1
spec/lib/gitlab/url_sanitizer_spec.rb
spec/lib/gitlab/url_sanitizer_spec.rb
+6
-6
No files found.
app/models/project.rb
View file @
15bb7e97
...
...
@@ -519,12 +519,7 @@ class Project < ActiveRecord::Base
end
def
safe_import_url
result
=
URI
.
parse
(
self
.
import_url
)
result
.
password
=
'*****'
unless
result
.
password
.
nil?
result
.
user
=
'*****'
unless
result
.
user
.
nil?
||
result
.
user
==
"git"
#tokens or other data may be saved as user
result
.
to_s
rescue
self
.
import_url
Gitlab
::
UrlSanitizer
.
new
(
import_url
).
masked_url
end
def
mirror_updated?
...
...
lib/gitlab/url_sanitizer.rb
View file @
15bb7e97
...
...
@@ -3,7 +3,7 @@ module Gitlab
def
self
.
sanitize
(
content
)
regexp
=
URI
::
Parser
.
new
.
make_regexp
([
'http'
,
'https'
,
'ssh'
,
'git'
])
content
.
gsub
(
regexp
)
{
|
url
|
new
(
url
).
sanitiz
ed_url
}
content
.
gsub
(
regexp
)
{
|
url
|
new
(
url
).
mask
ed_url
}
end
def
initialize
(
url
,
credentials:
nil
)
...
...
@@ -15,6 +15,13 @@ module Gitlab
@sanitized_url
||=
safe_url
.
to_s
end
def
masked_url
url
=
@url
.
dup
url
.
password
=
"*****"
unless
url
.
password
.
nil?
url
.
user
=
"*****"
unless
url
.
user
.
nil?
url
.
to_s
end
def
credentials
@credentials
||=
{
user:
@url
.
user
,
password:
@url
.
password
}
end
...
...
spec/lib/gitlab/url_sanitizer_spec.rb
View file @
15bb7e97
...
...
@@ -31,16 +31,16 @@ describe Gitlab::UrlSanitizer, lib: true do
}
)
end
it
'
remov
e credentials from HTTP URLs'
do
expect
(
filtered_content
).
to
include
(
"http://test.com/root/repoC.git/"
)
it
'
mask th
e credentials from HTTP URLs'
do
expect
(
filtered_content
).
to
include
(
"http://
*****:*****@
test.com/root/repoC.git/"
)
end
it
'
remov
e credentials from HTTPS URLs'
do
expect
(
filtered_content
).
to
include
(
"https://test.com/root/repoA.git/"
)
it
'
mask th
e credentials from HTTPS URLs'
do
expect
(
filtered_content
).
to
include
(
"https://
*****:*****@
test.com/root/repoA.git/"
)
end
it
'
remove
credentials from SSH URLs'
do
expect
(
filtered_content
).
to
include
(
"ssh://host.test/path/to/repo.git"
)
it
'
mask
credentials from SSH URLs'
do
expect
(
filtered_content
).
to
include
(
"ssh://
*****@
host.test/path/to/repo.git"
)
end
it
'does not modify Git URLs'
do
...
...
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