From 528611956c8ea77e8dddc312b64baa3549697bdf Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Fri, 27 Feb 2026 01:31:07 +0000 Subject: [PATCH] Drop additional headers on redirect (#12146) (#12150) CVE: CVE-2026-34518 Upstream-Status: Backport [https://github.com/aio-libs/aiohttp/commit/5351c980dcec7ad385730efdf4e1f4338b24fdb6] (cherry picked from commit 6e8f393330f9bd6d7b24a146124ebc42eaa727b9) (cherry picked from commit 5351c980dcec7ad385730efdf4e1f4338b24fdb6) Signed-off-by: Darsh Kelaiya --- aiohttp/client.py | 2 ++ tests/test_client_functional.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/aiohttp/client.py b/aiohttp/client.py index e30b880e9..0b87d7eec 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -684,6 +684,8 @@ class ClientSession: if url.origin() != parsed_url.origin(): auth = None headers.pop(hdrs.AUTHORIZATION, None) + headers.pop(hdrs.COOKIE, None) + headers.pop(hdrs.PROXY_AUTHORIZATION, None) url = parsed_url params = {} diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index c8d4e0aab..3ca1716ba 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -2604,6 +2604,8 @@ async def test_drop_auth_on_redirect_to_other_host( async def srv_to(request): assert request.host == url_to.host assert "Authorization" not in request.headers, "Header wasn't dropped" + assert "Proxy-Authorization" not in request.headers + assert "Cookie" not in request.headers return web.Response() server_from = await create_server_for_url_and_handler(url_from, srv_from) @@ -2646,11 +2648,16 @@ async def test_drop_auth_on_redirect_to_other_host( resp = await client.get( url_from, auth=aiohttp.BasicAuth("user", "pass"), + headers={"Proxy-Authorization": "Basic dXNlcjpwYXNz", "Cookie": "a=b"}, ) assert resp.status == 200 resp = await client.get( url_from, - headers={"Authorization": "Basic dXNlcjpwYXNz"}, + headers={ + "Authorization": "Basic dXNlcjpwYXNz", + "Proxy-Authorization": "Basic dXNlcjpwYXNz", + "Cookie": "a=b", + }, ) assert resp.status == 200 -- 2.35.6