Summary
Axios' Node.js HTTP adapter contains a prototype pollution gadget that can cause attacker-controlled HTTP headers to be injected into outgoing requests when the global Object prototype has been polluted.
By abusing duck-typed detection of FormData-like objects, an attacker who can influence Object.prototype can supply a malicious getHeaders() implementation, leading Axios to merge arbitrary headers into subsequent HTTP requests under specific conditions.
Affected context
This issue affects applications that:
- Use Axios in environments where the Node.js HTTP adapter (
lib/adapters/http.js) is active - Rely on shared JavaScript object prototypes (e.g., in typical Node.js runtimes or bundled server-side code)
- Include Axios alongside other libraries that may introduce a prototype pollution primitive, even if Axios itself is not directly polluting prototypes
The vulnerability manifests when Axios processes a plain object as request data and its type detection logic interacts with a polluted Object.prototype.
Exploit preconditions
- Attack surface: Any code path that sends HTTP requests using Axios in a Node.js context (HTTP adapter).
- Required access: Ability to introduce or trigger a prototype pollution primitive that:
- Modifies
Object.prototype(or a shared ancestor) with properties likegetHeaders,append,pipe,on,once, andSymbol.toStringTag - Provides an attacker-controlled implementation of
getHeaders(). - Trigger point: An outgoing Axios request where:
- The
datapayload is a plain object, but due to polluted prototype methods, it is misclassified as a FormData-like object - Axios invokes
data.getHeaders()and merges the returned object into the request headers. - Why exploitation is possible: The HTTP adapter relies on duck-typing and inherited methods to determine whether the payload behaves like a FormData instance. When
Object.prototypeis polluted with specific methods, the adapter treats arbitrary objects as FormData, calling an attacker-suppliedgetHeaders()that returns arbitrary headers, which Axios then injects into the request.
Why this happens
The underlying bug stems from a combination of unsafe duck-typing and trust in inherited object properties in a prototype-based language.
Instead of checking for a specific, trusted type or using robust feature detection on the actual instance, the Axios HTTP adapter inspects the presence of methods such as getHeaders, append, pipe, on, once, and Symbol.toStringTag. Because JavaScript objects inherit from Object.prototype, any pollution of that prototype can cause arbitrary plain objects to present these methods.
This results in a prototype pollution gadget: once any dependency or application code introduces attacker-controlled methods on Object.prototype, Axios' type check incorrectly identifies plain objects as FormData-like. It then calls getHeaders() and merges its return value into the outgoing request headers, mapping to:
- CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers, as arbitrary header values can be introduced into requests, potentially enabling header injection if those values are not otherwise sanitized downstream.
- CWE-1321: Prototype Pollution, as the gadget becomes exploitable when global object prototypes are modified, enabling unintended behavior in downstream code.
Potential impact
- Injection of arbitrary custom HTTP headers into outgoing requests from the affected application
- Manipulation of authentication or authorization headers (e.g., cookies, tokens, or API keys) if the attacker can control their names and values
- Bypassing of security controls such as CSRF protections, origin-based checks, or internal routing rules that depend on trusted headers
- Facilitating SSRF-style scenarios by influencing headers that control downstream behavior (e.g., host routing, internal feature flags)
- Interference with logging, monitoring, or auditing systems that rely on consistent header formats
General mitigation guidance
Mitigation typically focuses on breaking the gadget pattern and reducing trust in inherited object properties:
- Prefer strict type checks over duck-typing when differentiating between payload types such as FormData and plain objects, ensuring the adapter cannot be tricked by prototype modifications.
- Avoid reading critical behavior from
Object.prototypeor other shared prototypes; instead, useObject.hasOwn()or similar techniques that only consider own properties. - Introduce defensive coding patterns that treat prototype pollution as an assumed risk in large dependency trees, especially when working in JavaScript/TypeScript environments.
- Constrain where and how headers are derived from application inputs by centralizing header construction logic and avoiding implicit header merging from untrusted functions.
- Employ defense-in-depth by limiting the power of individual headers where possible (e.g., having backend services re-validate sensitive headers instead of trusting client-provided ones).
How teams detect issues like this
Detection strategies can focus on both the gadget and the broader prototype pollution risk:
- Static analysis: Configure rules to flag:
- Duck-typed checks that rely on methods inherited from prototypes instead of explicit type checks
- Usage of shared prototypes (
Object.prototype) where behavior decisions (like header derivation) are made based on inherited methods. - Code review: Look for:
- Any logic in HTTP adapters or networking layers that merges headers returned from user-influenced functions
- Patterns where
getHeaders()or similar methods are invoked on loosely-typed objects. - Runtime defenses: Implement:
- Application-level guards that freeze or lock down
Object.prototypein controlled environments where feasible - Monitoring around outgoing HTTP requests to detect unexpected or anomalous headers being sent, especially those not constructed by known code paths.
- Tooling: Use automated security scanners and SAST tools configured to recognize prototype pollution sinks and gadgets, particularly in widely used HTTP clients and middleware.

