//nefariousplan

CVE-2026-47265: aiohttp's Cross-Origin Redirect Cleanup Enumerated Four Credential Carriers. The Loop Carried Five.

vendor

pattern

cve

proof of concept

Inside aiohttp/client.py, the ClientSession._request redirect loop ends each iteration with a block that runs on cross-origin redirects. Pre-patch, the block does four things. It sets auth = None. It pops Authorization from the request headers. It pops Cookie from the request headers. It pops Proxy-Authorization from the request headers. CVE-2026-47265 is the one line PR #12550 added to that block on May 19, 2026: cookies = None.

The block was a hand-written list of credential carriers the redirect loop knew to drop before the next iteration. The list had four entries. The loop carried five.

The block was a list, not a policy

ClientSession._request is a while True: loop with redirect-handling logic at its tail. Every iteration sends one HTTP request; if the response is a redirect, the loop parses the redirect URL and continues with the new URL in hand. Loop-scoped variables persist across iterations unless the loop explicitly clears them.

Pre-patch, the cross-origin block at the end of the iteration looked like this:

if url.origin() != redirect_origin:
    auth = None
    headers.pop(hdrs.AUTHORIZATION, None)
    headers.pop(hdrs.COOKIE, None)
    headers.pop(hdrs.PROXY_AUTHORIZATION, None)

url = parsed_redirect_url
params = {}
resp.release()
continue

The block is a list. It enumerates the credential-bearing inputs to the request, by hand, and clears each one. auth is the BasicAuth object the loop carries across iterations. Authorization, Cookie, and Proxy-Authorization are the three credential-bearing HTTP headers the caller might have passed via the headers= keyword argument. There is no for carrier in CARRIERS: loop here. There is no policy that asks the loop to forget every input whose authority was scoped to the previous host. The block names four things and clears them.

The patch for CVE-2026-47265 adds a fifth line:

                         if url.origin() != redirect_origin:
                             auth = None
+                            cookies = None
                             headers.pop(hdrs.AUTHORIZATION, None)
                             headers.pop(hdrs.COOKIE, None)
                             headers.pop(hdrs.PROXY_AUTHORIZATION, None)

cookies is the loop-scoped variable that holds the dict the caller passed as the cookies= keyword argument on the request. Before the patch, that variable persisted across redirect iterations and was used to construct the outbound Cookie header on every one of them. The block knew to drop the header. It did not know to drop the source the header was reconstructed from.

The fifth carrier was the per-request cookies parameter

Earlier in the same loop body, the request-construction block builds the outbound cookie set:

all_cookies = self._cookie_jar.filter_cookies(url)

if cookies is not None:
    tmp_cookie_jar = CookieJar(
        unsafe=self._cookie_jar.unsafe,
        quote_cookie=self._cookie_jar.quote_cookie,
    )
    tmp_cookie_jar.update_cookies(cookies)
    req_cookies = tmp_cookie_jar.filter_cookies(url)
    if req_cookies:
        all_cookies.load(req_cookies)

self._cookie_jar is the session-level CookieJar. Its filter_cookies(url) applies RFC 6265 domain matching: cookies whose Domain attribute does not match url.host are not returned. When the loop iterates with a new host after a cross-origin redirect, self._cookie_jar.filter_cookies(new_url) correctly returns only the cookies whose domain matches the new host. The session jar is fine.

The cookies keyword argument is the problem. Per-request cookies are loaded into a fresh, ad-hoc tmp_cookie_jar and the filtered result is merged into all_cookies. The pre-patch code re-ran this block on every redirect iteration, because the loop body runs from the top each time. On the second iteration, the cookies parameter still pointed at the dict the caller passed for the original request. The temp jar got loaded again. The outbound Cookie header got built again. The redirected host received the developer's per-request session cookie.

A user-facing call that triggers the leak looks like this:

async with aiohttp.ClientSession() as session:
    resp = await session.get(
        "https://victim.example.com/account",
        cookies={"session": "REDACTED_SESSION_TOKEN"},
    )

If victim.example.com/account responds with Location: https://attacker.example.com/, pre-patch the redirected request carries Cookie: session=REDACTED_SESSION_TOKEN to attacker.example.com. The developer set the cookie on a request to one host. The redirect handler reused it on a request to another.

The temp jar was built without a response URL, and a cookie without a host is shared

The mechanism by which the temp jar treats per-request cookies as send-to-everywhere is worth tracing, because it is what makes the convenient API the unsafe one.

CookieJar.update_cookies has this branch:

def update_cookies(self, cookies: LooseCookies, response_url: URL = URL()) -> None:
    hostname = response_url.raw_host
    ...
    if not domain and hostname is not None:
        # Set the cookie's domain to the response hostname
        # and set its host-only-flag
        self._host_only_cookies.add((hostname, name))
        domain = cookie["domain"] = hostname

The session jar receives cookies via update_cookies(set_cookie_morsels, response_url=response.url). The response URL is always present, so cookies that arrive without an explicit Domain attribute get their domain set to the responding host. They become host-only. A later filter_cookies(other_host) will not return them.

tmp_cookie_jar.update_cookies(cookies) is called with no response_url. The default is URL(), whose raw_host is None. The host-fallback branch is skipped. The cookie's domain stays empty.

Then filter_cookies runs. Cookies with empty domain land in the ("", "") bucket. filter_cookies returns the contents of that bucket unconditionally:

# Send shared cookie
key = ("", "")
for c in self._cookies[key].values():
    ...
    filtered[c.key] = mrsl_val

The "shared cookie" path exists for cookies the application explicitly wants on every host. The per-request cookies= dict is not that. It is the set of cookies the caller wanted on this one call. The temp jar treats them as shared cookies because the only signal it has that a cookie should be scoped to a specific host is the response_url it was never given.

The result is that the per-request cookies become host-agnostic for the lifetime of the redirect chain. Each iteration's tmp_cookie_jar.filter_cookies(url) returns every cookie in the dict, no matter what host url points at. The cleanup block at the end of the iteration is the only thing that could have prevented this. Pre-patch, the cleanup block did not.

The patch did not change any of this. update_cookies still accepts a default empty response_url. The temp jar still stores per-request cookies in the ("", "") bucket. The "send shared cookie" branch still emits everything in that bucket on every request. The fix is to drop the cookies variable before the next iteration starts, so the temp jar never gets constructed against a new host. Any future call site that passes a user-controlled dict through CookieJar(...).update_cookies(...) without a response_url and then asks for cookies on an attacker-controlled URL inherits the same shared-cookie path. The cookie jar's behavior is unchanged; the redirect loop has stopped reaching it on cross-origin transitions.

The mitigation routes you to the carrier the block already covered

The GHSA advisory's "if unable to upgrade" guidance reads, verbatim:

If unable to upgrade, using a Cookie header in the headers parameter is not vulnerable.

The advisory does not explain why. The reason is in the cleanup block. headers.pop(hdrs.COOKIE, None) has been there since well before CVE-2026-47265. A developer who passed their cookie as headers={"Cookie": "session=abc"} was triggering that existing line on every cross-origin redirect. The header was already in the list.

The aiohttp client API offers two ways to send a cookie on a single request:

  • session.get(url, cookies={"session": "abc"}), the structured parameter that auto-encodes the value and reads to code review as the safe option.
  • session.get(url, headers={"Cookie": "session=abc"}), the manual header the developer assembled by hand.

The structured parameter is the one that leaked. The manual header was already covered.

The mitigation tells developers to stop using the structured carrier and go back to assembling the Cookie header by hand. The reason the manual header is safe is that the block listed it. The reason the structured parameter was not safe is that the block did not. The mitigation is the proof that the cleanup is by enumeration, not by policy: if a name appears in the block, the carrier is safe across redirects; if it does not, it is not.

Three carriers, three patches, the same block

The same cleanup block has been patched three times in the ten weeks ending June 2026. Each patch added a previously-unenumerated carrier, or rewrote the scope of a variable the block could not reach.

Date PR Author What the block missed
2026-03-27 #12275 Rodrigo Nogueira An is_same_host_https_redirect carve-out skipped the cleanup entirely on same-host HTTP-to-HTTPS upgrades. Authorization, Cookie, and Proxy-Authorization headers persisted across that class of cross-origin redirect because the block was specifically declined.
2026-05-19 #12550 (CVE-2026-47265) Sam Bull The per-request cookies keyword argument persisted across cross-origin redirects because the block did not name it.
2026-06-06 #12829 J. Nick Koston The environment-resolved proxy auth header (from HTTPS_PROXY with credentials in the URL) was set once before the loop and persisted across iterations. The fix moves resolution inside the loop and nulls the carried headers at the top of each iteration.

The three patches are not the same fix. They are three different ways of saying the same thing: a credential-bearing input to the loop body was persisting across redirect iterations, and the cleanup block did not name it. Each fix was authored by a different contributor. Each fix was a small diff to aiohttp/client.py. Each fix added a missing entry to a list that the redirect handler treats as authoritative.

This is Wide Default, Narrow Doc. The redirect loop's local-variable scope is the wide default: every keyword argument the caller passes to _request persists across iterations because Python does not unbind them. The cleanup block is the narrow doc: a hand-curated enumeration of which carriers are credential-bearing. The same shape, Traefik's error-page middleware copying every inbound header by default while the documentation page only ever discussed Host, is the canonical case. aiohttp's redirect loop is the same shape with a different rendering of the wide default: Python's lexical scoping instead of Go's utils.CopyHeaders. The block is still a list. The next credential-bearing keyword argument added to _request, or the next runtime side channel that injects a header into the outbound request, will not appear in the block until someone files the next CVE.

PoC: aio-libs/aiohttp, patch f54c408 (PR #12550).

The cleanup block enumerated four credential carriers. The redirect loop carried five. The patch added the fifth name. The block is still the only thing keeping the sixth from leaking.