Skip to content

Commit 74ea7cf

Browse files
authored
Merge pull request from GHSA-j8r2-6x86-q33q
1 parent 3022253 commit 74ea7cf

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

requests/sessions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ def rebuild_proxies(self, prepared_request, proxies):
324324
except KeyError:
325325
username, password = None, None
326326

327-
if username and password:
327+
# urllib3 handles proxy authorization for us in the standard adapter.
328+
# Avoid appending this to TLS tunneled requests where it may be leaked.
329+
if not scheme.startswith('https') and username and password:
328330
headers["Proxy-Authorization"] = _basic_auth_str(username, password)
329331

330332
return new_proxies

tests/test_requests.py

+20
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,26 @@ def test_proxy_authorization_preserved_on_request(self, httpbin):
647647

648648
assert sent_headers.get("Proxy-Authorization") == proxy_auth_value
649649

650+
651+
@pytest.mark.parametrize(
652+
"url,has_proxy_auth",
653+
(
654+
('http://example.com', True),
655+
('https://example.com', False),
656+
),
657+
)
658+
def test_proxy_authorization_not_appended_to_https_request(self, url, has_proxy_auth):
659+
session = requests.Session()
660+
proxies = {
661+
'http': 'http://test:pass@localhost:8080',
662+
'https': 'http://test:pass@localhost:8090',
663+
}
664+
req = requests.Request('GET', url)
665+
prep = req.prepare()
666+
session.rebuild_proxies(prep, proxies)
667+
668+
assert ('Proxy-Authorization' in prep.headers) is has_proxy_auth
669+
650670
def test_basicauth_with_netrc(self, httpbin):
651671
auth = ("user", "pass")
652672
wrong_auth = ("wronguser", "wrongpass")

0 commit comments

Comments
 (0)