Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions botocore/httpsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,17 @@ def mask_proxy_url(proxy_url):

:return: Masked proxy url, i.e. https://***:***@proxy.com
"""
mask = '*' * 3
parsed_url = urlparse(proxy_url)
if parsed_url.username:
proxy_url = proxy_url.replace(parsed_url.username, mask, 1)
if parsed_url.password:
proxy_url = proxy_url.replace(parsed_url.password, mask, 1)
return proxy_url
if not parsed_url.username:
return proxy_url
mask = '*' * 3
# Rebuild the netloc from the parsed userinfo/host so only the credential
# fields are masked. A substring replace can spend the mask on an earlier
# occurrence of the credential value (e.g. in the scheme or host) and leave
# the real secret in place.
_, _, host = parsed_url.netloc.rpartition('@')
userinfo = f'{mask}:{mask}' if parsed_url.password else mask
return parsed_url._replace(netloc=f'{userinfo}@{host}').geturl()


def _is_ipaddress(host):
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_http_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def test_get_cert_path_certifi_or_default(self):
('http://user:pass@192.168.1.1', 'http://***:***@192.168.1.1'),
('http://user:pass@[::1]', 'http://***:***@[::1]'),
('http://user:pass@[::1]:80', 'http://***:***@[::1]:80'),
# credential value also appears earlier in the url
(
'https://user:https@proxy.example.com',
'https://***:***@proxy.example.com',
),
('http://ttp:secret@host.com', 'http://***:***@host.com'),
('http://myproxy.amazonaws.com', 'http://myproxy.amazonaws.com'),
),
)
def test_mask_proxy_url(proxy_url, expected_mask_url):
Expand Down