Drop connection headers on cross-host redirect in HttpAsyncHook (#70164) - #70641
Open
waterWang wants to merge 3 commits into
Open
Drop connection headers on cross-host redirect in HttpAsyncHook (#70164)#70641waterWang wants to merge 3 commits into
waterWang wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HttpAsyncHookforwards Connectionextraheaders (e.g.X-API-Key,Private-Token) across cross-host redirects becauseaiohttponly strips theAuthorizationheader. 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
HttpHookby subclassingrequests.Sessionand extendingrebuild_auth. This PR fixes the async side.Approach
aiohttphas no per-redirect callback equivalent torequests.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
providers/http/src/airflow/providers/http/hooks/http.py—AsyncHttpSession.run()now handles redirects manually:aiohttp's auto-redirectrequestsdefault)devel-common/src/tests_common/test_utils/aiohttp.py— Addedheadersandrelease()toMockAiohttpClientResponseto support redirect tests.providers/http/tests/unit/http/hooks/test_http.py— Addedtest_async_connection_header_is_only_forwarded_on_a_same_host_redirectparametrized for cross-host and same-host redirects.Verification
X-API-Keypresent on first request, absent on secondX-API-Keypresent on both requestsRelated