fix(http): preserve basic auth on same-origin redirects (#6929)#10929
Merged
jasonsaayman merged 4 commits intoMay 26, 2026
Merged
Conversation
7981262 to
12b11ea
Compare
12b11ea to
9cdb48d
Compare
9cdb48d to
3f1b3dd
Compare
jasonsaayman
approved these changes
May 26, 2026
jasonsaayman
added a commit
that referenced
this pull request
May 28, 2026
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
config.auth(HTTP Basic credentials) was being lost on every redirect afterfollow-redirects1.15.8 — including same-origin POST → 303 → GET, which is the most common Basic-auth redirect pattern and what users in #6929 hit (401 Unauthorized).This restores
authon the redirected request only when the redirect target shares the original request's origin. Cross-origin redirects continue to drop credentials, so the T-R2 cross-host credential-leak mitigation documented inTHREATMODEL.mdis preserved.Implementation mirrors the existing
beforeRedirects.proxypattern (a hook registered alongsidebeforeRedirects.configand invoked fromdispatchBeforeRedirect).Linked issue
Closes #6929
Changes
lib/adapters/http.js: addbeforeRedirects.authhook that re-appliesoptions.authwhen the redirect URL's origin matches the original request origin; wire it intodispatchBeforeRedirect. Malformed redirect URLs fall through with auth left stripped (fail-safe).tests/unit/adapters/http.test.js: three new regression testsPRE_RELEASE_CHANGELOG.md: bug-fix entry under Unreleased.Security notes
URL(redirectOptions.href).originvs the parsed request URL'sorigin(protocol + hostname + port). This is the same notion of origin PR fix: custom auth headers not stripped on cross-origin redirects #10892 uses for cross-origin sensitive-header stripping.beforeRedirects.proxy).Checklist
index.d.tsandindex.d.cts) — N/A, no public API changeAI-assisted (Claude Opus 4.7); commit subject is one line per author preference, disclosed here. Happy to amend in an
Assisted-by:trailer if reviewers prefer.Summary by cubic
Restores HTTP Basic auth on same-origin redirects in the Node HTTP adapter to prevent 401s introduced by
follow-redirects>= 1.15.8. Cross-origin redirects and malformed targets still strip credentials.Description
beforeRedirects.authto re-applyoptions.authwhen the redirect URL’s origin matches the original; invoked fromdispatchBeforeRedirect./docs/to clarify Basic auth is restored only on same-origin redirects and not on HTTPS→HTTP.Testing
Written for commit 62ca77a. Summary will update on new commits. Review in cubic