Skip to content

Commit

Permalink
Url: fix sanitize for new github tokens (#10048)
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubinix committed Aug 11, 2021
1 parent c7d11f3 commit c65bd83
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Composer/Util/Url.php
Expand Up @@ -110,8 +110,8 @@ public static function sanitize($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) {
// if the username looks like a long (12char+) hex string, or a modern github token (e.g. gp1_xxx) we obfuscate that
if (preg_match('{^([a-f0-9]{12,}|g[a-z]\d_[a-zA-Z0-9_]+)$}', $m['user'])) {
// 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,}|gh[a-z]_[a-zA-Z0-9_]+)$}', $m['user'])) {
return $m['prefix'].'***:***@';
}

Expand Down
1 change: 1 addition & 0 deletions tests/Composer/Test/Util/UrlTest.php
Expand Up @@ -78,6 +78,7 @@ public static function sanitizeProvider()
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?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
array('foo:***@example.org/', 'foo:bar@example.org/'),
array('foo@example.org/', 'foo@example.org/'),
Expand Down

0 comments on commit c65bd83

Please sign in to comment.