The vulnerability is a classic case of prototype pollution in JavaScript. The axios library did not properly check for own properties when accessing configuration options. This allowed an attacker who could pollute Object.prototype in the same process to inject malicious configuration into every axios request.
The core of the vulnerability lies in several key functions:
-
mergeConfig: This function was responsible for merging default and user-provided configurations. It created a standard object {} which inherits from Object.prototype. This was the entry point for the polluted properties to enter the configuration.
-
resolveConfig: This function resolved the final URL for the request. It read baseURL from the configuration without an own property check, allowing an attacker to hijack requests with relative URLs.
-
httpAdapter: This is the main function for making HTTP requests in Node.js. It read several sensitive configuration options like auth, socketPath, beforeRedirect, and insecureHTTPParser directly from the configuration object. This allowed for a range of attacks, including credential injection, Server-Side Request Forgery (SSRF) via socketPath, remote code execution via beforeRedirect, and weakening of the HTTP parser.
-
assertOptions: This validation function was also vulnerable, as it accessed schema properties without checking for own properties, potentially leading to a denial of service.
The patch addresses these issues by:
- Modifying
mergeConfig to create a null-prototype object using Object.create(null). This is the most critical fix as it prevents the merged configuration from inheriting any properties from Object.prototype.
- Adding
hasOwnProperty checks (via an own() helper) in httpAdapter and resolveConfig before accessing sensitive configuration properties. This provides defense-in-depth.
- Using
Object.prototype.hasOwnProperty.call() in assertOptions to safely access schema properties.
By identifying these functions, a security engineer can understand the runtime behavior of the exploit and create targeted monitoring and detection rules.