Properly handle colons in URL passwords

Before b46d5b13ec, we relied on
`Addressable::URI` to parse the username/password in a URL, but this failed
when credentials contained special characters. However, this introduced a regression
where the parsing would incorrectly truncate the password if the password had a colon.

Closes #49080
This commit is contained in:
Stan Hu 2018-07-10 13:00:21 -07:00
parent 255db3d597
commit 718a23fd36
3 changed files with 7 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
title: Properly handle colons in URL passwords
merge_request:
author:
type: fixed

View File

@ -58,7 +58,7 @@ module Gitlab
if raw_credentials.present?
url.sub!("#{raw_credentials}@", '')
user, password = raw_credentials.split(':')
user, _, password = raw_credentials.partition(':')
@credentials ||= { user: user.presence, password: password.presence }
end

View File

@ -92,6 +92,7 @@ describe Gitlab::UrlSanitizer do
context 'credentials in URL' do
where(:url, :credentials) do
'http://foo:bar@example.com' | { user: 'foo', password: 'bar' }
'http://foo:bar:baz@example.com' | { user: 'foo', password: 'bar:baz' }
'http://:bar@example.com' | { user: nil, password: 'bar' }
'http://foo:@example.com' | { user: 'foo', password: nil }
'http://foo@example.com' | { user: 'foo', password: nil }