fix: stop forwarding credentials to cross-origin redirect targets - #3174
Open
ethicnology wants to merge 1 commit into
Open
fix: stop forwarding credentials to cross-origin redirect targets#3174ethicnology wants to merge 1 commit into
ethicnology wants to merge 1 commit into
Conversation
ethicnology
force-pushed
the
harden-redirect-handling
branch
from
August 7, 2026 19:53
e28adb0 to
013d4f9
Compare
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.
HttpService.sourceRequestStreamResponsefollows redirects manually. Onevery hop it re-applies the original request headers — including
Authorization(e.g. the GitHub PAT sent asToken …) and any customheaders configured for HTML sources — regardless of the redirect target's
origin. Session cookies collected along the way are forwarded the same way.
A source answering
302to a third-party host therefore receives theuser's credentials. The same loop also follows
https → httpdowngrades,silently dropping to cleartext.
What this PR changes
In the redirect loop only:
Authorization,Proxy-AuthorizationandCookieheaders are stripped, and accumulatedsession cookies are not forwarded.
https → httpredirects are refused with an error instead of beingfollowed.
legitimate flows (e.g. same-host API redirects) keep working.
What it deliberately does NOT change
downloadFile), which delegates redirectfollowing to
dart:ioand does not re-apply custom headers — verifiedsafe.
besides one new error string (
en.jsononly, other locales to follow viathe usual translation process).
Tests
Regression tests are ready (cross-origin strip, same-origin keep, downgrade
refusal, plus a control for the download path) and will follow in a
dedicated test PR once this lands — the project has no
flutter_testharness yet, and adding it here would mix infrastructure with the fix.