CVE-2023-2972
CVE-2023-2972
Weakness (CWE)
CVSS Vector
v3.1- Attack Vector
- Network
- Attack Complexity
- Low
- Privileges Required
- None
- User Interaction
- None
- Scope
- Unchanged
- Confidentiality
- High
- Integrity
- High
- Availability
- High
Description
Prototype Pollution in GitHub repository antfu/utils prior to 0.7.3.
Comprehensive Technical Analysis of CVE-2023-2972: Prototype Pollution in antfu/utils
1. Vulnerability Assessment and Severity Evaluation
CVE ID: CVE-2023-2972
CVSS Score: 9.8 (Critical) – [AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H]
Vulnerability Type: Prototype Pollution (CWE-1321)
Affected Software: antfu/utils (JavaScript utility library)
Affected Versions: All versions prior to 0.7.3
Patch Status: Fixed in v0.7.3 (commit 7f8b16c6181c988bdb96613fbb2533b345f68682)
Severity Justification
The CVSS 9.8 (Critical) rating is justified due to:
- Network-based exploitation (AV:N) – Attackers can trigger the vulnerability remotely without authentication.
- Low attack complexity (AC:L) – Exploitation requires minimal effort, typically via maliciously crafted JSON input.
- No user interaction required (UI:N) – The vulnerability can be exploited without victim interaction.
- High impact on confidentiality, integrity, and availability (C:H/I:H/A:H) – Successful exploitation can lead to arbitrary code execution (ACE), denial of service (DoS), or data exfiltration.
Prototype pollution is a high-severity vulnerability in JavaScript environments due to its potential to bypass security controls, modify application behavior, and enable remote code execution (RCE) in certain contexts.
2. Potential Attack Vectors and Exploitation Methods
Root Cause: Prototype Pollution
Prototype pollution occurs when an attacker manipulates JavaScript object prototypes (e.g., Object.prototype) by injecting properties via user-controlled input. This can lead to:
- Property injection – Overriding default object properties.
- Function hijacking – Modifying built-in methods (e.g.,
toString,valueOf). - Security bypass – Disabling security checks (e.g.,
hasOwnPropertychecks).
Exploitation Scenarios
Scenario 1: Direct Prototype Pollution via Merge/Clone Functions
The antfu/utils library likely contains utility functions for deep object merging/cloning (e.g., merge(), deepClone()). If these functions do not properly sanitize input, an attacker can craft malicious JSON/JS objects to pollute the prototype.
Example Exploit Payload:
const maliciousPayload = {
"__proto__": {
"isAdmin": true,
"toString": () => { /* Malicious code */ }
}
};
// If `merge(target, maliciousPayload)` is called, it pollutes `Object.prototype`
Impact:
- Authentication bypass – If an application checks
user.isAdmin, pollution can forceisAdmin: truefor all objects. - Remote Code Execution (RCE) – If
toStringor other methods are overridden, attacker-controlled code may execute.
Scenario 2: Server-Side Exploitation (Node.js)
If antfu/utils is used in a Node.js backend, prototype pollution can lead to:
- Arbitrary code execution via
child_process.exec()oreval(). - Denial of Service (DoS) by corrupting core JavaScript functions.
- Data exfiltration by modifying
JSON.stringifyorfetchbehavior.
Scenario 3: Client-Side Exploitation (Browser)
In a frontend application, exploitation may lead to:
- Cross-Site Scripting (XSS) if pollution affects DOM manipulation.
- Session hijacking if
localStorageorsessionStoragemethods are tampered with. - UI manipulation by overriding rendering logic.
Exploitation Requirements
- User-controlled input must be processed by a vulnerable function (e.g.,
merge(),deepClone()). - No authentication required – Exploitation can occur via API requests, form submissions, or maliciously crafted JSON.
- JavaScript environment – Both Node.js and browser-based applications are at risk.
3. Affected Systems and Software Versions
Affected Software
- Library:
antfu/utils(a JavaScript utility library) - Vulnerable Versions: < 0.7.3
- Patched Version: 0.7.3+ (commit
7f8b16c6181c988bdb96613fbb2533b345f68682)
Dependency Chain Risk
Since antfu/utils is a utility library, it may be transitively included in other projects. Security teams should:
- Audit
package.jsonfor direct or indirect dependencies. - Use
npm auditoryarn auditto detect vulnerable versions. - Check
node_modulesfor nested dependencies.
Potential Attack Surface
| Environment | Exploitation Risk | Impact |
|---|---|---|
| Node.js Backend | High | RCE, DoS, Data Exfiltration |
| Browser Frontend | Medium | XSS, Session Hijacking, UI Manipulation |
| Serverless (AWS Lambda, Cloud Functions) | High | RCE, Data Leakage |
| Electron Apps | High | Local Privilege Escalation |
4. Recommended Mitigation Strategies
Immediate Actions
- Upgrade to
antfu/utils@0.7.3or laternpm update antfu/utils@latest # or yarn upgrade antfu/utils@latest - Apply the Patch Manually
- Review the fix commit and ensure input sanitization is implemented in merge/clone functions.
Defensive Programming Best Practices
- Avoid Prototype Pollution in Merge/Clone Functions
- Use
Object.create(null)to create objects without prototypes. - Sanitize input by checking for
__proto__,constructor, orprototypekeys. - Example safe merge function:
function safeMerge(target, source) { const result = Object.create(null); for (const key in target) { if (Object.prototype.hasOwnProperty.call(target, key)) { result[key] = target[key]; } } for (const key in source) { if (Object.prototype.hasOwnProperty.call(source, key) && !["__proto__", "constructor", "prototype"].includes(key)) { result[key] = source[key]; } } return result; }
- Use
- Use
Object.freeze(Object.prototype)(Temporary Mitigation)- Prevents prototype pollution but may break legitimate functionality.
Object.freeze(Object.prototype); - Implement Input Validation
- Reject objects containing
__proto__,constructor, orprototypekeys. - Use schema validation (e.g.,
zod,joi) for API inputs.
- Reject objects containing
Monitoring and Detection
- Static Application Security Testing (SAST)
- Use tools like SonarQube, Semgrep, or ESLint to detect prototype pollution vulnerabilities.
- Example Semgrep rule:
rules: - id: prototype-pollution pattern: | function $FUNC($TARGET, $SOURCE) { ... $TARGET[$KEY] = $SOURCE[$KEY]; ... } message: "Potential prototype pollution in merge function"
- Dynamic Application Security Testing (DAST)
- Use OWASP ZAP or Burp Suite to fuzz API endpoints for prototype pollution.
- Runtime Protection
- Node.js: Use
--disable-proto(experimental) orses(Secure ECMAScript). - Browser: Use Content Security Policy (CSP) to mitigate XSS risks.
- Node.js: Use
5. Impact on the Cybersecurity Landscape
Broader Implications
-
Supply Chain Risks
antfu/utilsis a utility library, meaning it may be indirectly included in many projects.- Similar to
lodash(CVE-2019-10744) andjquery(CVE-2019-11358), prototype pollution in utility libraries can have widespread impact.
-
Increased Attack Surface for JavaScript Applications
- Node.js backends are particularly vulnerable to RCE via prototype pollution.
- Frontend frameworks (React, Vue, Angular) may be affected if they use vulnerable utilities.
-
Evolution of Exploitation Techniques
- Attackers are increasingly chaining prototype pollution with other vulnerabilities (e.g., XSS, SSRF) for full compromise.
- Automated exploit tools (e.g.,
pp-finder) are emerging to detect and exploit prototype pollution.
-
Regulatory and Compliance Risks
- GDPR, CCPA, HIPAA: Data breaches resulting from prototype pollution could lead to legal penalties.
- PCI DSS: If exploited in payment systems, this could result in non-compliance.
Historical Context
| CVE | Library | CVSS | Impact |
|---|---|---|---|
| CVE-2019-10744 | Lodash | 7.5 | Prototype Pollution → RCE |
| CVE-2019-11358 | jQuery | 6.1 | Prototype Pollution → XSS |
| CVE-2021-23337 | Handlebars | 9.8 | Prototype Pollution → RCE |
| CVE-2023-2972 | antfu/utils | 9.8 | Prototype Pollution → RCE |
This vulnerability follows a well-documented pattern of high-severity prototype pollution flaws in JavaScript libraries.
6. Technical Details for Security Professionals
Vulnerability Deep Dive
Root Cause Analysis
- The vulnerability exists in object merging/cloning functions that recursively copy properties without proper sanitization.
- Example vulnerable code (simplified):
function merge(target, source) { for (const key in source) { if (typeof source[key] === 'object' && source[key] !== null) { if (!target[key]) target[key] = {}; merge(target[key], source[key]); // Recursive merge without sanitization } else { target[key] = source[key]; // Direct assignment → Prototype pollution } } return target; } - Exploit Trigger:
merge({}, JSON.parse('{"__proto__": {"isAdmin": true}}')); // Now, all objects have `isAdmin: true`
Exploitation Proof of Concept (PoC)
- Polluting
Object.prototype:const payload = JSON.parse('{"__proto__": {"polluted": "yes"}}'); merge({}, payload); console.log({}.polluted); // Output: "yes" (prototype pollution successful) - Remote Code Execution (Node.js):
const payload = JSON.parse('{"__proto__": {"exec": "malicious_command"}}'); merge({}, payload); require('child_process').exec('echo "Exploited"'); // May execute attacker-controlled command - Denial of Service (DoS):
const payload = JSON.parse('{"__proto__": {"toString": () => { while(true); }}}'); merge({}, payload); ({}).toString(); // Infinite loop → DoS
Patch Analysis
The fix commit introduces:
- Input sanitization to block
__proto__,constructor, andprototypekeys. - Safe object creation using
Object.create(null)to avoid prototype inheritance. - Recursive property checks to prevent pollution in nested objects.
Detection and Forensics
- Log Analysis
- Look for unexpected object properties (e.g.,
isAdmin: trueon all objects). - Monitor for unusual API requests containing
__proto__orconstructor.
- Look for unexpected object properties (e.g.,
- Memory Forensics (Node.js)
- Use
heapdumporv8-inspectorto detect prototype pollution. - Check for unexpected properties in
Object.prototype.
- Use
- Network Traffic Analysis
- Inspect JSON payloads for suspicious keys (
__proto__,constructor).
- Inspect JSON payloads for suspicious keys (
Advanced Exploitation Techniques
- Chaining with Other Vulnerabilities
- Prototype Pollution + XSS → Override
innerHTMLorevalto execute arbitrary JS. - Prototype Pollution + SSRF → Modify
fetchorXMLHttpRequestto exfiltrate data.
- Prototype Pollution + XSS → Override
- Bypassing Sanitization
- Some libraries block
__proto__but notconstructor.prototype. - Alternative payloads:
{"constructor": {"prototype": {"polluted": true}}}
- Some libraries block
- Persistence via
localStorage/sessionStorage- Pollute
Storage.prototypeto persist malicious payloads across sessions.
- Pollute
Conclusion and Recommendations
Key Takeaways
- CVE-2023-2972 is a critical prototype pollution vulnerability in
antfu/utilswith CVSS 9.8. - Exploitation can lead to RCE, DoS, or data exfiltration in both Node.js and browser environments.
- Immediate patching is required (upgrade to
v0.7.3+). - Defensive measures (input sanitization, SAST/DAST, runtime protection) should be implemented.
Action Plan for Security Teams
| Priority | Action | Owner |
|---|---|---|
| Critical | Upgrade antfu/utils to 0.7.3+ | DevOps/Engineering |
| High | Audit all dependencies for prototype pollution risks | Security Team |
| High | Implement input sanitization in merge/clone functions | Developers |
| Medium | Deploy SAST/DAST tools to detect similar vulnerabilities | AppSec Team |
| Medium | Monitor for exploitation attempts in logs | SOC Team |
Long-Term Mitigation Strategies
- Adopt Secure Coding Practices
- Avoid recursive object merging without sanitization.
- Use
Object.create(null)for safe object creation.
- Enhance Dependency Management
- Automate vulnerability scanning (e.g., Dependabot, Snyk).
- Enforce minimal dependency usage to reduce attack surface.
- Improve Runtime Protections
- Node.js: Use
--disable-protoorses(Secure ECMAScript). - Browser: Enforce strict CSP to mitigate XSS risks.
- Node.js: Use
Final Thoughts
Prototype pollution remains a high-impact vulnerability class in JavaScript ecosystems. CVE-2023-2972 underscores the importance of:
- Secure coding practices in utility libraries.
- Proactive dependency management.
- Continuous monitoring for emerging threats.
Security teams should treat this vulnerability with urgency, given its critical severity and ease of exploitation. Organizations using antfu/utils should patch immediately and audit their codebases for similar flaws.