GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(http): preserve basic auth on same-origin redirects (#6929) by devareddy05 · Pull Request #10929 · axios/axios

Conversation

@devareddy05

@devareddy05 devareddy05 commented May 21, 2026 •
edited by cubic-dev-ai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

config.auth (HTTP Basic credentials) was being lost on every redirect after follow-redirects 1.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 auth on 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 in THREATMODEL.md is preserved.

Implementation mirrors the existing beforeRedirects.proxy pattern (a hook registered alongside beforeRedirects.config and invoked from dispatchBeforeRedirect).

Linked issue

Closes #6929

Changes

  • lib/adapters/http.js: add beforeRedirects.auth hook that re-applies options.auth when the redirect URL's origin matches the original request origin; wire it into dispatchBeforeRedirect. Malformed redirect URLs fall through with auth left stripped (fail-safe).
  • tests/unit/adapters/http.test.js: three new regression tests
    • same-origin 303 POST → GET preserves Basic auth (the exact Error 401 with the 'follow-redirects' library since version 1.15.8 #6929 scenario)
    • cross-origin 302 strips Basic auth (regression guard for T-R2)
    • multi-hop same-origin redirect chain preserves Basic auth
  • PRE_RELEASE_CHANGELOG.md: bug-fix entry under Unreleased.

Security notes

  • Same-origin = exact match on URL(redirectOptions.href).origin vs the parsed request URL's origin (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.
  • HTTPS → HTTP downgrade to the same hostname/port is not same-origin (different protocol), so credentials are still dropped on downgrade.
  • No new public API surface; the hook is internal-only (analogous to beforeRedirects.proxy).

Checklist

  • Tests added or updated (or N/A with reason)
  • Docs / types updated if public API changed (index.d.ts and index.d.cts) — N/A, no public API change
  • No breaking changes (or called out explicitly above)

AI-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

    • Added beforeRedirects.auth to re-apply options.auth when the redirect URL’s origin matches the original; invoked from dispatchBeforeRedirect.
    • Keeps security behavior: no restore on origin change or HTTPS→HTTP downgrade.
    • Added changelog entry under Bug Fixes.
    • Docs: update /docs/ to clarify Basic auth is restored only on same-origin redirects and not on HTTPS→HTTP.
    • SemVer: patch (bug fix, no public API change).
  • Testing

    • Added unit tests:
      • same-origin 303 POST→GET preserves auth
      • cross-origin 302 strips auth
      • multi-hop same-origin chain preserves auth

Written for commit 62ca77a. Summary will update on new commits. Review in cubic

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devareddy05
devareddy05 requested a review from jasonsaayman as a code owner May 21, 2026 19:26
@devareddy05 devareddy05 mentioned this pull request May 21, 2026
Error 401 with the 'follow-redirects' library since version 1.15.8 #6929
Closed
cubic-dev-ai[bot]
cubic-dev-ai Bot reviewed May 21, 2026
View reviewed changes

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@devareddy05
devareddy05 force-pushed the fix/6929-preserve-basic-auth-same-origin-redirect branch from 7981262 to 12b11ea Compare May 23, 2026 19:14
@jasonsaayman jasonsaayman assigned devareddy05 May 24, 2026
@jasonsaayman jasonsaayman added priority::medium labels May 24, 2026
@devareddy05
devareddy05 force-pushed the fix/6929-preserve-basic-auth-same-origin-redirect branch from 12b11ea to 9cdb48d Compare May 24, 2026 14:32
@devareddy05
fix(http): preserve basic auth on same-origin redirects (axios#6929)
3f1b3dd
@devareddy05
devareddy05 force-pushed the fix/6929-preserve-basic-auth-same-origin-redirect branch from 9cdb48d to 3f1b3dd Compare May 25, 2026 08:05
@jasonsaayman
docs(http): address redirect auth review nits
bf2b65b
jasonsaayman
jasonsaayman approved these changes May 26, 2026
View reviewed changes
jasonsaayman added 2 commits May 26, 2026 20:43
@jasonsaayman
Merge branch 'v1.x' into fix/6929-preserve-basic-auth-same-origin-red…
5e2f001
…irect
@jasonsaayman
Merge branch 'v1.x' into fix/6929-preserve-basic-auth-same-origin-red…
62ca77a
…irect
@jasonsaayman
jasonsaayman merged commit 58d8a12 into axios:v1.x May 26, 2026
26 checks passed

Uh oh!

There was an error while loading. Please reload this page.

jasonsaayman added a commit that referenced this pull request May 28, 2026
@devareddy05 @jasonsaayman
fix(http): preserve basic auth on same-origin redirects (#6929) (#10929)
a598239
* fix(http): preserve basic auth on same-origin redirects (#6929)

* docs(http): address redirect auth review nits

---------

Co-authored-by: Jason Saayman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cubic-dev-ai cubic-dev-ai[bot] cubic-dev-ai[bot] left review comments
@jasonsaayman jasonsaayman jasonsaayman approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@devareddy05 devareddy05

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Error 401 with the 'follow-redirects' library since version 1.15.8

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@devareddy05 @jasonsaayman
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.