Url: fix sanitize for new github tokens (#10048)
parent
c7d11f361c
commit
c65bd832d6
|
@ -110,8 +110,8 @@ class Url
|
||||||
$url = preg_replace('{([&?]access_token=)[^&]+}', '$1***', $url);
|
$url = preg_replace('{([&?]access_token=)[^&]+}', '$1***', $url);
|
||||||
|
|
||||||
$url = preg_replace_callback('{^(?P<prefix>[a-z0-9]+://)?(?P<user>[^:/\s@]+):(?P<password>[^@\s/]+)@}i', function ($m) {
|
$url = preg_replace_callback('{^(?P<prefix>[a-z0-9]+://)?(?P<user>[^:/\s@]+):(?P<password>[^@\s/]+)@}i', function ($m) {
|
||||||
// if the username looks like a long (12char+) hex string, or a modern github token (e.g. gp1_xxx) we obfuscate that
|
// if the username looks like a long (12char+) hex string, or a modern github token (e.g. ghp_xxx) we obfuscate that
|
||||||
if (preg_match('{^([a-f0-9]{12,}|g[a-z]\d_[a-zA-Z0-9_]+)$}', $m['user'])) {
|
if (preg_match('{^([a-f0-9]{12,}|gh[a-z]_[a-zA-Z0-9_]+)$}', $m['user'])) {
|
||||||
return $m['prefix'].'***:***@';
|
return $m['prefix'].'***:***@';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ class UrlTest extends TestCase
|
||||||
array('https://foo:***@example.org:123/', 'https://foo:bar@example.org:123/'),
|
array('https://foo:***@example.org:123/', 'https://foo:bar@example.org:123/'),
|
||||||
array('https://example.org/foo/bar?access_token=***', 'https://example.org/foo/bar?access_token=abcdef'),
|
array('https://example.org/foo/bar?access_token=***', 'https://example.org/foo/bar?access_token=abcdef'),
|
||||||
array('https://example.org/foo/bar?foo=bar&access_token=***', 'https://example.org/foo/bar?foo=bar&access_token=abcdef'),
|
array('https://example.org/foo/bar?foo=bar&access_token=***', 'https://example.org/foo/bar?foo=bar&access_token=abcdef'),
|
||||||
|
array('https://***:***@github.com/acme/repo', 'https://ghp_1234567890abcdefghijklmnopqrstuvwxyzAB:x-oauth-basic@github.com/acme/repo'),
|
||||||
// without scheme
|
// without scheme
|
||||||
array('foo:***@example.org/', 'foo:bar@example.org/'),
|
array('foo:***@example.org/', 'foo:bar@example.org/'),
|
||||||
array('foo@example.org/', 'foo@example.org/'),
|
array('foo@example.org/', 'foo@example.org/'),
|
||||||
|
|
Loading…
Reference in New Issue