Skip to content

Drop connection-supplied HTTP headers on cross-host redirects - #72165

Open
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:fix-http-conn-headers-cross-host-redirect
Open

Drop connection-supplied HTTP headers on cross-host redirects#72165
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:fix-http-conn-headers-cross-host-redirect

Conversation

@potiuk

@potiuk potiuk commented Aug 27, 2026

Copy link
Copy Markdown
Member

Why

HttpHook.get_conn applies every unrecognised key from a connection's extra field as a persistent session header:

session.headers.update(conn_extra_options)   # _configure_session_from_extra

and the hook's own docstring documents that field as the place to put them — "headers can also be specified in the Extra field in json format".

requests removes only the Authorization header when a redirect crosses to a different host (Session.rebuild_authshould_strip_auth). A credential carried under any other header name — X-API-Key, X-Auth-Token and similar, which is exactly what the documented extra-field pattern produces — stays on the session and is replayed verbatim to whatever host the redirect points at. Redirects are followed by default (session.max_redirects = DEFAULT_REDIRECT_LIMIT).

What

  • Add _ConnectionHeaderSession, a requests.Session subclass that records which header names came from the connection and drops only those when should_strip_auth() reports the redirect is cross-origin.
  • Use it in get_conn, and populate connection_header_keys where the extra-field headers are applied.
  • Tests covering cross-host stripping, same-host preservation, caller-supplied headers being left alone, and the keys being recorded through get_conn.

Delegating the decision to requests' own should_strip_auth() means an httpshttp downgrade on the same host is covered too, without duplicating that logic.

Compatibility

  • Headers passed explicitly by the caller (get_conn(headers=...), default_headers) are not affected — the caller controls the request either way.
  • Same-host redirects are unchanged.
  • Only connection-extra-derived headers are dropped, and only on a cross-origin hop.

Testing

Verified locally against real requests, all five cases passing: cross-host connection header dropped, same-host preserved, caller-supplied header preserved, Authorization still stripped by requests itself, and same-host httpshttp downgrade stripped.

The provider test suite could not be executed in my environment — a local editable-install issue unrelated to this change prevented airflow from importing. ruff check and ruff format --check are clean, and py_compile passes on both files, but CI needs to run providers/http tests.

🤖 Generated with Claude Code

@SameerMesiah97 SameerMesiah97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment. I believe that the existing tests i.e test_get, test_get_response_check, and test_sensor are now failing as they patch Session directly when this PR is now routing the connection through _ConnectionHeaderSession. I would adjust the patching for those tests accordingly to see if it fixes the failing tests.

Comment thread providers/http/tests/unit/http/hooks/test_http.py Outdated
@potiuk
potiuk force-pushed the fix-http-conn-headers-cross-host-redirect branch from 56e80c8 to f2ec50a Compare August 27, 2026 20:09
HttpHook applies every unrecognised key from a connection's extra field as a
persistent session header (get_conn -> _configure_session_from_extra), and the
hook documents that field as the place to put headers. requests removes only
the Authorization header when a redirect crosses to a different host
(Session.rebuild_auth), so a credential carried under any other header name --
X-API-Key and similar, which is what the documented pattern produces -- is
replayed verbatim to the redirect target.

Track which header names came from the connection and drop just those when
requests' own should_strip_auth() says the hop is cross-origin. Headers passed
explicitly by the caller are left alone, since the caller controls the request
either way, and same-host redirects are unaffected. Delegating the decision to
should_strip_auth also covers an https -> http downgrade on the same host.
@potiuk
potiuk force-pushed the fix-http-conn-headers-cross-host-redirect branch from f2ec50a to 51492ae Compare August 28, 2026 14:38
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.

2 participants