Details
Observed result on the current npm package:
{
"response": "ATTACKER",
"legitHits": [],
"attackerHits": [
{
"url": "/secret",
"auth": "Bearer SECRET"
}
]
}
The request never reached the intended target. The attacker-controlled server received the Authorization header and supplied the response body returned by axios.
Versions tested
I reproduced this against:
- axios 1.16.1 from npm
- axios 1.17.0 from npm
- current
v1.xsource at commita8e4f13aeecc45a3b8fab3ecfd9ddb5d70fb772b
Fix validation
Adding an own safe value for createConnection to the adapter options object prevents inherited pollution from being observed after Node's option copy:
const options = Object.assign(Object.create(null), {
path,
method: method,
headers: toByteStringHeaderObject(headers),
agents: { http: config.httpAgent, https: config.httpsAgent },
auth,
protocol,
family,
beforeRedirect: dispatchBeforeRedirect,
beforeRedirects: Object.create(null),
http2Options,
createConnection: undefined,
});
With that guard in place, the same proof no longer calls the polluted function. The legitimate server receives the request, the attacker server receives nothing, and axios returns the legitimate response.
Remediation
Set own safe defaults for sensitive Node HTTP request options before calling transport.request, at minimum:
createConnection: undefined
I recommend reviewing other sensitive Node HTTP options that may be read after Node copies the request options into a normal object, especially connection/TLS-affecting fields such as lookup, timeout, localAddress, servername, signal, and related options.
</details>
---