diff options
author | Robert Speicher <robert@gitlab.com> | 2016-05-19 03:00:01 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-05-19 03:00:01 +0000 |
commit | 4607323e130fe5b04e830f7a6de8083b070808f1 (patch) | |
tree | a00611843950a53a5963e5a2a31e748e11102246 /lib | |
parent | 26eb3dd731c8eb8ade81a77f34c0444d693ac22a (diff) | |
parent | 0c47b68d0474b595bb03a49ce755c96f5d00fbf1 (diff) | |
download | gitlab-ce-4607323e130fe5b04e830f7a6de8083b070808f1.tar.gz |
Merge branch 'issue_17560' into 'master'
Mask credentials from URL when the import of project has failed.
REF: #17560
See merge request !4185
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/url_sanitizer.rb (renamed from lib/gitlab/import_url.rb) | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/gitlab/import_url.rb b/lib/gitlab/url_sanitizer.rb index d23b013c1f5..c59d53b941a 100644 --- a/lib/gitlab/import_url.rb +++ b/lib/gitlab/url_sanitizer.rb @@ -1,7 +1,13 @@ module Gitlab - class ImportUrl + class UrlSanitizer + def self.sanitize(content) + regexp = URI::Parser.new.make_regexp(['http', 'https', 'ssh', 'git']) + + content.gsub(regexp) { |url| new(url).masked_url } + end + def initialize(url, credentials: nil) - @url = URI.parse(URI.encode(url)) + @url = Addressable::URI.parse(URI.encode(url)) @credentials = credentials end @@ -9,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 |