fix(connect): strip Authorization on cross-origin redirects in custom Session#464
Open
fix(connect): strip Authorization on cross-origin redirects in custom Session#464
Conversation
The custom Session.post manually followed redirects and re-dispatched via self.request without stripping credentials, bypassing requests' SessionRedirectMixin.rebuild_auth. A malicious or compromised Connect server could return a Location header pointing to an attacker-controlled host (including protocol-relative //attacker/... resolved via urljoin) and receive the Connect API key or bootstrap JWT. Compare origins (scheme, hostname, port) between the current response URL and the resolved redirect target; on mismatch, drop any Authorization header from the outgoing headers kwarg, suppress the session-level Authorization header, and set auth=None for the next hop. Also reject redirect schemes other than http/https. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
tdstein
added a commit
that referenced
this pull request
Apr 9, 2026
Replace the hand-rolled redirect loop in Session.post with a minimal rebuild_method override. Inheriting from requests.SessionRedirectMixin restores rebuild_auth (strips Authorization on cross-origin hops), cookie propagation, response.history, TooManyRedirects, proxy rebuild, and streaming semantics — all of which the previous implementation silently dropped. Supersedes the defensive patch in #464.
3 tasks
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
The custom
Session.postinsrc/posit/connect/sessions.pymanually follows redirects withallow_redirects=False, bypassingrequests.SessionRedirectMixin.rebuild_auth. On a cross-origin redirect, the session'sAuthorizationheader (Connect API key or bootstrap JWT) was forwarded to the attacker-controlled host named inLocation— including protocol-relative//attacker/...resolved viaurljoin.Authorizationfrom the outgoing headers kwarg and passesauth=Nonefor that request.http/https.preserve_postbehavior unchanged.Test plan
tests/posit/connect/test_sessions.py(12 passing):