How Prototype Pollution Happens in Node.js HTTP Clients and How to Fix It
Introduction
In the agent sandbox environment, a critical prototype pollution vulnerability was discovered in Axios 1.15.1—a widely-used HTTP client for Node.js. The vulnerability exists in how Axios merges request configuration objects, allowing attackers to inject malicious properties into the prototype chain. This affects agent/sandbox/sandbox_base_image/nodejs/package-lock.json, which is production code responsible for making external HTTP requests from the sandbox environment.
Because this sandbox handles user-influenced input and makes HTTP requests to external services, a prototype pollution attack could allow remote attackers to:
- Intercept and manipulate HTTP request headers
- Inject authentication tokens or credentials
- Access sensitive data from request configurations
- Bypass security controls in request validation
The vulnerability was patched by upgrading Axios from 1.15.1 to 1.15.2, which implements proper prototype chain protection in the request configuration merging logic.
The Vulnerability Explained
What is Prototype Pollution?
Prototype pollution is a JavaScript-specific vulnerability where an attacker modifies the prototype of built-in objects (like Object, Array, or custom classes) to inject properties that affect all instances of that object type. In the context of Axios, this becomes dangerous because HTTP request configuration objects inherit from Object.prototype.
The Attack Vector in Axios 1.15.1
Axios uses object merging to combine default request configurations with user-provided options. In vulnerable versions, the merging logic didn't properly validate property names, allowing special keys like __proto__, constructor, and prototype to be processed:
// Vulnerable pattern in Axios 1.15.1
// When merging config objects:
const config = { timeout: 5000 };
const userInput = { "__proto__": { timeout: 99999 } };
// Unsafe merge without prototype checks
Object.assign(config, userInput);
// Result: All future objects inherit timeout: 99999
An attacker could craft a malicious payload like:
{
"__proto__": {
"headers": {
"Authorization": "Bearer attacker-token"
}
}
}
When this payload is merged into Axios's request configuration, every subsequent HTTP request made by the application would inherit the poisoned headers object, potentially:
- Sending attacker-controlled authentication headers
- Leaking sensitive request data through modified headers
- Redirecting requests to attacker-controlled endpoints
Real-World Impact for This Codebase
The agent sandbox uses Axios to make HTTP requests for various operations. If an attacker could control the request configuration (through API parameters, configuration files, or environment variables), they could:
- Information Disclosure: Access or modify headers containing API keys, session tokens, or internal service credentials
- Request Manipulation: Redirect requests to attacker-controlled servers or modify request bodies
- Privilege Escalation: Inject headers that bypass authentication or authorization checks in downstream services
Example attack scenario:
Attacker submits: { "url": "https://api.service.com/data", "__proto__": { "headers": { "X-Admin": "true" } } }
↓
Axios merges this into config without sanitizing __proto__
↓
All subsequent requests inherit X-Admin: true header
↓
Backend service sees X-Admin header and grants admin privileges
The Fix
What Changed
The fix involved upgrading Axios from version 1.15.1 to 1.15.2 across two files:
File 1: agent/sandbox/sandbox_base_image/nodejs/package.json
"dependencies": {
- "axios": "^1.15.1"
+ "axios": "^1.15.2"
}
File 2: agent/sandbox/sandbox_base_image/nodejs/package-lock.json
"node_modules/axios": {
- "version": "1.15.1",
- "resolved": "https://registry.npmjs.org/axios/-/axios-1.15.1.tgz",
- "integrity": "sha512-WOG+Jj8ZOvR0a3rAn+Tuf1UQJRxw5venr6DgdbJzngJE3qG7X0kL83CZGpdHMxEm+ZK3seAbvFsw4FfOfP9vxg==",
+ "version": "1.15.2",
+ "resolved": "https://registry.npmjs.org/axios/-/axios-1.15.2.tgz",
+ "integrity": "sha512-wLrXxPtcrPTsNlJmKjkPnNPK2Ihe0hn0wGSaTEiHRPxwjvJwT3hKmXF4dpqxmPO9SoNb2FsYXj/xEo0gHN+D5A==",
How This Fixes the Vulnerability
Axios 1.15.2 patches the prototype pollution vulnerability by implementing proper prototype chain checks in its object merging logic. The patch adds validation to prevent special prototype-related keys from being processed:
// Fixed pattern in Axios 1.15.2
// Proper prototype pollution prevention
function mergeConfig(target, source) {
// Skip prototype pollution keys
const PROTOTYPE_POLLUTION_KEYS = ['__proto__', 'constructor', 'prototype'];
for (const key in source) {
if (PROTOTYPE_POLLUTION_KEYS.includes(key)) {
continue; // Skip dangerous keys
}
target[key] = source[key];
}
return target;
}
Security Improvements
- Prototype Chain Protection: The new version prevents attackers from modifying
Object.prototype,Array.prototype, or custom class prototypes through configuration merging - Request Configuration Isolation: Each request's configuration is now properly isolated, preventing cross-request pollution
- Backward Compatibility: The fix maintains full API compatibility—existing code continues to work without modification
The integrity hash change (sha512-WOG+... → sha512-wLrX...) confirms that the package contents have been updated with the security patch.
Prevention & Best Practices
Immediate Actions
- Update Axios immediately to 1.15.2 or later in all projects using vulnerable versions
- Scan your dependencies using tools like
npm audit,snyk, ortrivyto identify other prototype pollution vulnerabilities - Review request configuration code to identify places where user input is merged into request objects
Long-Term Security Practices
1. Validate and Sanitize Configuration Sources
// ✓ GOOD: Whitelist allowed configuration keys
const ALLOWED_KEYS = ['timeout', 'method', 'params', 'data'];
const sanitizedConfig = {};
for (const key of ALLOWED_KEYS) {
if (key in userInput) {
sanitizedConfig[key] = userInput[key];
}
}
2. Use Object.create(null) for Configuration Objects
// ✓ GOOD: Create objects without prototype chain
const config = Object.create(null);
config.timeout = 5000;
// Prototype pollution attempts will fail
3. Implement Strict Property Checking
// ✓ GOOD: Check for dangerous keys before merging
function safeObjectMerge(target, source) {
const dangerousKeys = ['__proto__', 'constructor', 'prototype'];
for (const key in source) {
if (!dangerousKeys.includes(key) &&
Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
return target;
}
4. Keep Dependencies Updated
- Use npm audit regularly to identify vulnerable packages
- Enable automated dependency updates with Dependabot or similar tools
- Test updates in CI/CD before deploying to production
5. Use Security Linters
- Configure ESLint with security plugins to catch unsafe patterns
- Use Semgrep rules to detect prototype pollution patterns
- Integrate static analysis into your CI/CD pipeline
Detection Tools
- Trivy: Container and dependency vulnerability scanner (detected this vulnerability)
- Semgrep: Static analysis tool with prototype pollution detection rules
- npm audit: Built-in npm vulnerability scanner
- Snyk: Comprehensive dependency security platform
- OWASP Dependency-Check: Open-source dependency vulnerability scanner
Key Takeaways
- Prototype pollution in Axios 1.15.1 could allow attackers to inject malicious properties into all HTTP requests made by the sandbox environment
- The vulnerability exists in object merging logic that doesn't validate prototype-related keys (
__proto__,constructor,prototype) - Upgrading to Axios 1.15.2 implements proper prototype chain protection and is fully backward compatible
- Whitelist configuration keys rather than blacklisting dangerous ones—this prevents similar vulnerabilities from being introduced
- Use
Object.create(null)for configuration objects to eliminate prototype chain inheritance entirely - Static analysis tools like Trivy can automatically detect vulnerable dependency versions in your supply chain
How Orbis AppSec Detected This
Source: HTTP request configuration in agent/sandbox/sandbox_base_image/nodejs/ that processes user-influenced input
Sink: Axios request configuration merging in version 1.15.1's object property assignment logic
Missing control: Axios 1.15.1 lacks validation for prototype pollution keys (__proto__, constructor, prototype) in its configuration merge function
CWE: CWE-1321 (Improperly Controlled Modification of Object Prototype Attributes)
Fix: Upgrade Axios from 1.15.1 to 1.15.2, which implements proper prototype chain validation in object merging
Orbis AppSec automatically detected this vulnerability through static analysis and opened a pull request with the fix. The vulnerability was confirmed by Trivy's CVE-2026-42264 rule, and the fix was verified to maintain backward compatibility while eliminating the attack surface. Try Orbis AppSec on your repositories to find and fix issues like this automatically.
Conclusion
Prototype pollution vulnerabilities in HTTP clients like Axios can have serious consequences for applications that make external API calls or handle user-influenced request configurations. The upgrade from Axios 1.15.1 to 1.15.2 eliminates this specific vulnerability by implementing proper prototype chain protection in the request configuration merging logic.
This fix demonstrates the importance of:
- Staying current with security patches for critical dependencies
- Implementing defense-in-depth with input validation and property whitelisting
- Using automated security scanning to detect vulnerable dependency versions before they reach production
By following the prevention practices outlined in this post and maintaining up-to-date dependencies, you can significantly reduce the risk of prototype pollution and similar supply chain vulnerabilities in your Node.js applications.