Skip to content
Snippets Groups Projects
Commit 3b055baf authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Merge branch 'sh-normalize-urls' into 'master'

Escape username and password in UrlSanitizer#full_url

See merge request gitlab-org/gitlab-ce!20684
parents 928c81e2 50ff3626
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
---
title: Escape username and password in UrlSanitizer#full_url
merge_request: 20684
author:
type: fixed
Loading
Loading
@@ -71,12 +71,10 @@ module Gitlab
def generate_full_url
return @url unless valid_credentials?
 
@full_url = @url.dup
@full_url.password = credentials[:password] if credentials[:password].present?
@full_url.user = credentials[:user] if credentials[:user].present?
@full_url
@url.dup.tap do |generated|
generated.password = encode_percent(credentials[:password]) if credentials[:password].present?
generated.user = encode_percent(credentials[:user]) if credentials[:user].present?
end
end
 
def safe_url
Loading
Loading
@@ -89,5 +87,10 @@ module Gitlab
def valid_credentials?
credentials && credentials.is_a?(Hash) && credentials.any?
end
def encode_percent(string)
# CGI.escape converts spaces to +, but this doesn't work for git clone
CGI.escape(string).gsub('+', '%20')
end
end
end
Loading
Loading
@@ -145,6 +145,10 @@ describe Gitlab::UrlSanitizer do
'http://foo:@example.com' | 'http://foo@example.com'
'http://:bar@example.com' | :same
'http://foo:bar@example.com' | :same
'http://foo:g p@example.com' | 'http://foo:g%20p@example.com'
'http://foo:s/h@example.com' | 'http://foo:s%2Fh@example.com'
'http://t u:a#b@example.com' | 'http://t%20u:a%23b@example.com'
'http://t+u:a#b@example.com' | 'http://t%2Bu:a%23b@example.com'
end
 
with_them do
Loading
Loading
@@ -160,7 +164,7 @@ describe Gitlab::UrlSanitizer do
url_sanitizer = described_class.new("https://foo:b?r@github.com/me/project.git")
 
expect(url_sanitizer.sanitized_url).to eq("https://github.com/me/project.git")
expect(url_sanitizer.full_url).to eq("https://foo:b?r@github.com/me/project.git")
expect(url_sanitizer.full_url).to eq("https://foo:b%3Fr@github.com/me/project.git")
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment