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

fix(http): preserve basic auth on same-origin redirects (#6929) #10929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jasonsaayman merged 4 commits into axios:v1.x from devareddy05:fix/6929-preserve-basic-auth-same-origin-redirect
May 26, 2026

Uh oh!

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

Merged

fix(http): preserve basic auth on same-origin redirects (#6929) #10929

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
3f1b3dd
fix(http): preserve basic auth on same-origin redirects (#6929)
devareddy05 May 21, 2026
bf2b65b
docs(http): address redirect auth review nits
jasonsaayman May 26, 2026
5e2f001
Merge branch 'v1.x' into fix/6929-preserve-basic-auth-same-origin-red…
jasonsaayman May 26, 2026
62ca77a
Merge branch 'v1.x' into fix/6929-preserve-basic-auth-same-origin-red…
jasonsaayman May 26, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 PRE_RELEASE_CHANGELOG.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
## Bug Fixes

- **AxiosHeaders:** Silently skip empty response header names emitted by some React Native Android responses instead of throwing. (**#6959**, **#10875**)
- **HTTP Adapter - Auth on Redirect:** HTTP Basic credentials supplied via `config.auth` are now restored on same-origin redirects, fixing a regression caused by `follow-redirects` >= 1.15.8 that broke `POST` requests answered with a 303 Location. Cross-origin redirects continue to drop credentials, preserving the existing T-R2 mitigation in `THREATMODEL.md`. (**#6929**)
- **HTTP Adapter - Socket Path:** Ignore inherited `socketPath` and `allowedSocketPaths` config values when building Node.js requests, preventing prototype-pollution SSRF via Unix sockets. (**#10901**)
- **React Native FormData:** Clear the default `Content-Type` header for React Native `FormData` requests so Android can build multipart bodies with the correct boundary. (**#10898**)
- **Request Data:** Preserve enumerable symbol keys when merging plain request data before `transformRequest`. (**#6392**)
Expand Down
24 changes: 22 additions & 2 deletions 24 lib/adapters/http.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ const flushOnFinish = (stream, [throttled, flush]) => {
const http2Sessions = new Http2Sessions();

/**
* If the proxy or config beforeRedirects functions are defined, call them with the options
* object.
* If the proxy, auth, or config beforeRedirects functions are defined, call them
* with the options object.
*
* @param {Object<string, any>} options - The options object that was passed to the request.
*
Expand All @@ -157,6 +157,9 @@ function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
if (options.beforeRedirects.proxy) {
options.beforeRedirects.proxy(options);
}
if (options.beforeRedirects.auth) {
options.beforeRedirects.auth(options);
}
if (options.beforeRedirects.config) {
options.beforeRedirects.config(options, responseDetails, requestDetails);
}
Expand Down Expand Up @@ -860,6 +863,23 @@ export default isHttpAdapterSupported &&
if (configBeforeRedirect) {
options.beforeRedirects.config = configBeforeRedirect;
}
if (auth) {
// Restore HTTP Basic credentials on same-origin redirects only.
// follow-redirects >= 1.15.8 strips Authorization on every redirect (see #6929);
// cross-origin stripping is the documented mitigation for T-R2 in THREATMODEL.md
// and is preserved by deliberately not restoring on origin change.
const requestOrigin = parsed.origin;
const authToRestore = auth;
options.beforeRedirects.auth = function beforeRedirectAuth(redirectOptions) {
try {
if (new URL(redirectOptions.href).origin === requestOrigin) {
redirectOptions.auth = authToRestore;
}
} catch (e) {
// ignore malformed URL: leaving auth stripped is fail-safe
}
};
}
transport = isHttpsRequest ? httpsFollow : httpFollow;
}
}
Expand Down
92 changes: 92 additions & 0 deletions 92 tests/unit/adapters/http.test.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,98 @@ describe('supports http with nodejs', () => {
}
});

it('should preserve basic auth across same-origin 303 POST -> GET redirect', async () => {
const server = await startHTTPServer(
(req, res) => {
if (req.url === '/login') {
res.setHeader('Location', '/profile');
res.statusCode = 303;
res.end();
return;
}
res.end(req.headers.authorization || '');
},
{ port: SERVER_PORT }
);

try {
const auth = { username: 'foo', password: 'bar' };
const response = await axios.post(
`http://localhost:${server.address().port}/login`,
{ hello: 'world' },
{ auth, maxRedirects: 1 }
);
const base64 = Buffer.from('foo:bar', 'utf8').toString('base64');
assert.strictEqual(response.data, `Basic ${base64}`);
assert.strictEqual(response.request.path, '/profile');
} finally {
await stopHTTPServer(server);
}
});

it('should strip basic auth on cross-origin redirect', async () => {
const targetServer = await startHTTPServer(
(req, res) => {
res.end(req.headers.authorization || 'no-auth');
},
{ port: ALTERNATE_SERVER_PORT }
);
const redirectServer = await startHTTPServer(
(req, res) => {
res.setHeader('Location', `http://127.0.0.1:${targetServer.address().port}/`);
res.statusCode = 302;
res.end();
},
{ port: SERVER_PORT }
);

try {
const auth = { username: 'foo', password: 'bar' };
const response = await axios.get(`http://localhost:${redirectServer.address().port}/start`, {
auth,
maxRedirects: 1,
});
assert.strictEqual(response.data, 'no-auth');
} finally {
await stopHTTPServer(redirectServer);
await stopHTTPServer(targetServer);
}
});

it('should preserve basic auth across multi-hop same-origin redirects', async () => {
const server = await startHTTPServer(
(req, res) => {
if (req.url === '/a') {
res.setHeader('Location', '/b');
res.statusCode = 302;
res.end();
return;
}
if (req.url === '/b') {
res.setHeader('Location', '/c');
res.statusCode = 302;
res.end();
return;
}
res.end(req.headers.authorization || '');
},
{ port: SERVER_PORT }
);

try {
const auth = { username: 'foo', password: 'bar' };
const response = await axios.get(`http://localhost:${server.address().port}/a`, {
auth,
maxRedirects: 5,
});
const base64 = Buffer.from('foo:bar', 'utf8').toString('base64');
assert.strictEqual(response.data, `Basic ${base64}`);
assert.strictEqual(response.request.path, '/c');
} finally {
await stopHTTPServer(server);
}
});

it('should provides a default User-Agent header', async () => {
const server = await startHTTPServer(
(req, res) => {
Expand Down
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.