Skip to content

Drop connection headers on cross-host redirect in HttpAsyncHook (#70164) - #70641

Open
waterWang wants to merge 3 commits into
apache:mainfrom
waterWang:fix/async-hook-drop-connection-headers-on-cross-host-redirect
Open

Drop connection headers on cross-host redirect in HttpAsyncHook (#70164)#70641
waterWang wants to merge 3 commits into
apache:mainfrom
waterWang:fix/async-hook-drop-connection-headers-on-cross-host-redirect

Conversation

@waterWang

Copy link
Copy Markdown

Summary

HttpAsyncHook forwards Connection extra headers (e.g. X-API-Key, Private-Token) across cross-host redirects because aiohttp only strips the Authorization header. This is a security issue — a secret held under any other header name is replayed verbatim to the redirect target.

PR #70000 fixed the synchronous HttpHook by subclassing requests.Session and extending rebuild_auth. This PR fixes the async side.

Approach

aiohttp has no per-redirect callback equivalent to requests.Session.rebuild_auth(), so the fix disables automatic redirect following (allow_redirects=False) and walks the redirect chain manually. When the redirect target changes host, connection-supplied headers are dropped from subsequent requests. Same-host redirects are unaffected.

Changes

  1. providers/http/src/airflow/providers/http/hooks/http.pyAsyncHttpSession.run() now handles redirects manually:

    • Tracks which headers originated from the connection
    • Disables aiohttp's auto-redirect
    • On cross-host redirect: drops connection headers, keeps caller-supplied headers
    • On same-host redirect: retains all headers
    • Max 5 redirects followed (matching requests default)
  2. devel-common/src/tests_common/test_utils/aiohttp.py — Added headers and release() to MockAiohttpClientResponse to support redirect tests.

  3. providers/http/tests/unit/http/hooks/test_http.py — Added test_async_connection_header_is_only_forwarded_on_a_same_host_redirect parametrized for cross-host and same-host redirects.

Verification

  • Cross-host redirect: X-API-Key present on first request, absent on second
  • Same-host redirect: X-API-Key present on both requests
  • Existing tests pass unchanged

Related

@shahar1 shahar1 changed the title fix: drop connection headers on cross-host redirect in HttpAsyncHook (#70164) Drop connection headers on cross-host redirect in HttpAsyncHook (#70164) Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpAsyncHook replays connection extra headers across a cross-host redirect

1 participant