CVE-2023-28081
CVE-2023-28081
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
A bytecode optimization bug in Hermes prior to commit e6ed9c1a4b02dc219de1648f44cd808a56171b81 could be used to cause an use-after-free and obtain arbitrary code execution via a carefully crafted payload. Note that this is only exploitable in cases where Hermes is used to execute untrusted JavaScript. Hence, most React Native applications are not affected.
Comprehensive Technical Analysis of CVE-2023-28081
CVE ID: CVE-2023-28081 CVSS Score: 9.8 (Critical) Vulnerability Type: Use-After-Free (UAF) leading to Arbitrary Code Execution (ACE) Affected Component: Hermes JavaScript Engine (Bytecode Optimization) Disclosure Date: May 18, 2023
1. Vulnerability Assessment and Severity Evaluation
Technical Overview
CVE-2023-28081 is a use-after-free (UAF) vulnerability in Hermes, a JavaScript engine optimized for React Native applications. The flaw resides in Hermes’ bytecode optimization logic, where improper handling of object lifetimes during optimization passes allows an attacker to reclaim freed memory and execute arbitrary code in the context of the affected application.
Severity Justification (CVSS 9.8 - Critical)
The CVSS v3.1 scoring breakdown is as follows:
| Metric | Value | Justification |
|---|---|---|
| Attack Vector | Network | Exploitable remotely via crafted JavaScript payloads. |
| Attack Complexity | Low | No special conditions required; exploitation is straightforward with a crafted payload. |
| Privileges Required | None | No authentication or elevated privileges needed. |
| User Interaction | None | Exploitation can occur without user interaction (e.g., via malicious ads, API responses, or injected scripts). |
| Scope | Unchanged | Impact is confined to the Hermes engine’s process. |
| Confidentiality | High | Arbitrary code execution allows full data exfiltration. |
| Integrity | High | Attacker can modify application behavior or inject malicious logic. |
| Availability | High | Crash or denial-of-service (DoS) possible; ACE enables further disruption. |
Key Takeaways:
- Critical severity due to remote exploitation potential and arbitrary code execution.
- Low attack complexity makes it attractive for threat actors.
- No user interaction required, increasing the risk of drive-by attacks.
2. Potential Attack Vectors and Exploitation Methods
Exploitation Prerequisites
- Hermes engine must execute untrusted JavaScript (e.g., from a web API, user input, or third-party scripts).
- React Native applications using Hermes are only vulnerable if they execute untrusted JavaScript (e.g., dynamic
eval(),Function(), or remote script loading).
Attack Vectors
-
Malicious JavaScript Payloads
- Attackers craft a specially designed JavaScript snippet that triggers the UAF during bytecode optimization.
- Delivery methods:
- Compromised APIs (e.g., malicious JSON/JS responses).
- Third-party libraries (supply chain attacks).
- XSS vulnerabilities in hybrid apps.
- Malvertising (malicious ads injecting JS).
-
Supply Chain Attacks
- Attackers compromise a React Native dependency to inject malicious JS.
- Example: A popular npm package includes a payload that exploits CVE-2023-28081.
-
Phishing & Social Engineering
- Victims are tricked into visiting a malicious website or opening a crafted document that loads the exploit.
Exploitation Mechanics
-
Triggering the UAF
- The attacker’s JavaScript forces Hermes to optimize a function in a way that prematurely frees an object while still holding a reference to it.
- Example (pseudo-code):
// Crafted payload to trigger UAF during optimization function exploit() { let obj = { a: 1 }; // Force optimization pass that incorrectly frees 'obj' for (let i = 0; i < 1000; i++) { obj = { b: i }; // Reassignment triggers optimization } // Use-after-free occurs here return obj.a; // Accessing freed memory } exploit();
-
Memory Corruption & Arbitrary Code Execution
- The UAF allows the attacker to overwrite freed memory with controlled data.
- By spraying the heap with malicious objects, the attacker can redirect execution flow to attacker-controlled shellcode.
- Techniques:
- JIT Spraying (abusing Just-In-Time compilation to place shellcode).
- Return-Oriented Programming (ROP) to bypass DEP/ASLR.
-
Post-Exploitation
- Sandbox Escape (if applicable): If Hermes runs in a sandbox (e.g., React Native’s JavaScriptCore bridge), further exploitation may be needed to escape.
- Persistence: Attacker may install malware, exfiltrate data, or pivot to other systems.
3. Affected Systems and Software Versions
Vulnerable Hermes Versions
- All versions of Hermes prior to commit
e6ed9c1a4b02dc219de1648f44cd808a56171b81(May 2023). - React Native applications using Hermes only if they execute untrusted JavaScript.
Not Affected
- React Native apps that do not use Hermes (e.g., those using JavaScriptCore or V8).
- Apps that do not execute dynamic/untrusted JavaScript (e.g., static content).
Detection Methods
- Static Analysis:
- Check
package.jsonfor Hermes engine usage ("hermes": true). - Search for
eval(),Function(), or dynamic script loading.
- Check
- Dynamic Analysis:
- Monitor Hermes process for crashes when executing untrusted JS.
- Use fuzzing tools (e.g., AFL, LibFuzzer) to test for UAF conditions.
4. Recommended Mitigation Strategies
Immediate Actions
-
Apply the Patch
- Upgrade Hermes to the latest version (commit
e6ed9c1a4b02dc219de1648f44cd808a56171b81or later). - For React Native, update to a patched version (check React Native releases).
- Upgrade Hermes to the latest version (commit
-
Disable Hermes (Temporary Workaround)
- If patching is not immediately possible, disable Hermes in
android/app/build.gradle:project.ext.react = [ enableHermes: false ] - Note: This may impact performance and is not a long-term solution.
- If patching is not immediately possible, disable Hermes in
-
Input Sanitization & Sandboxing
- Avoid executing untrusted JavaScript (e.g.,
eval(),Function(),new Function()). - Use Content Security Policy (CSP) to restrict script sources.
- Isolate Hermes execution in a sandboxed environment (e.g., WebView with strict permissions).
- Avoid executing untrusted JavaScript (e.g.,
Long-Term Defenses
-
Code Auditing & Static Analysis
- Use SAST tools (e.g., Semgrep, SonarQube) to detect unsafe JS execution.
- Audit third-party dependencies for malicious or vulnerable code.
-
Runtime Protection
- Enable Control Flow Integrity (CFI) and Address Space Layout Randomization (ASLR).
- Use memory-safe languages (e.g., Rust, WebAssembly) for critical components.
-
Monitoring & Incident Response
- Log and alert on suspicious JavaScript execution (e.g., unexpected
evalcalls). - Deploy EDR/XDR solutions to detect post-exploitation activity.
- Log and alert on suspicious JavaScript execution (e.g., unexpected
5. Impact on the Cybersecurity Landscape
Broader Implications
-
Increased Targeting of Mobile & Hybrid Apps
- Hermes is widely used in React Native apps, making this a high-value target for attackers.
- Similar vulnerabilities in JavaScript engines (V8, JavaScriptCore) have been exploited in the wild (e.g., CVE-2021-30563 in Chrome).
-
Supply Chain Risks
- Attackers may compromise npm packages to distribute exploits.
- Third-party SDKs (e.g., analytics, ads) could be vectors for malicious JS.
-
Evolution of Exploit Techniques
- JIT Spraying & ROP chains in JavaScript engines are becoming more sophisticated.
- Sandbox escapes from Hermes could lead to full device compromise in some cases.
-
Regulatory & Compliance Impact
- GDPR, CCPA, and other regulations may require rapid patching to avoid fines.
- App Store policies (Apple App Store, Google Play) may enforce Hermes updates.
Historical Context
- Similar Vulnerabilities:
- CVE-2021-30563 (V8 Type Confusion in Chrome).
- CVE-2020-6506 (V8 UAF in WebAssembly).
- CVE-2018-17463 (V8 Heap Overflow in TurboFan).
- Exploitation in the Wild:
- Pegasus spyware has exploited JS engine flaws for iOS/Android attacks.
- Cryptojacking malware (e.g., Coinhive) has abused JS engines for mining.
6. Technical Details for Security Professionals
Root Cause Analysis
- Bytecode Optimization Flaw:
- Hermes performs optimizations (e.g., inlining, constant folding) on JavaScript bytecode.
- A race condition or incorrect object lifetime management during optimization causes a dangling pointer to freed memory.
- Use-After-Free (UAF) Primitive:
- The attacker forces an object to be freed while Hermes still holds a reference.
- Subsequent access to the freed object corrupts memory, enabling arbitrary read/write.
Exploit Development Insights
-
Heap Grooming
- Attackers spray the heap with controlled objects to predict memory layout.
- Example:
// Heap spraying to control freed memory let spray = []; for (let i = 0; i < 1000; i++) { spray.push(new ArrayBuffer(0x1000)); }
-
JIT Spraying for Shellcode
- Just-In-Time (JIT) compilation can be abused to place shellcode in executable memory.
- Example:
// JIT-sprayed shellcode function jitMe() { return 0x41414141; // Placeholder for shellcode } for (let i = 0; i < 10000; i++) jitMe();
-
Bypassing Mitigations
- ASLR Bypass: Leak memory addresses via JavaScript type confusion.
- DEP Bypass: Use Return-Oriented Programming (ROP) to execute shellcode.
Proof-of-Concept (PoC) Considerations
- A minimal PoC would:
- Trigger the UAF via crafted JS.
- Spray the heap to control freed memory.
- Redirect execution to attacker-controlled data.
- Full exploit would require:
- Memory leaks to bypass ASLR.
- ROP chain construction to bypass DEP.
Detection & Forensics
- Crash Analysis:
- Look for Hermes process crashes with UAF signatures (e.g.,
EXC_BAD_ACCESSon iOS,SIGSEGVon Android).
- Look for Hermes process crashes with UAF signatures (e.g.,
- Memory Forensics:
- Use Volatility or Frida to inspect Hermes heap for dangling pointers.
- Network Monitoring:
- Detect malicious JS payloads via WAF rules or deep packet inspection.
Conclusion & Recommendations
Key Takeaways
- CVE-2023-28081 is a critical UAF in Hermes that enables remote code execution in React Native apps executing untrusted JS.
- Exploitation is feasible with low complexity, making it a high-risk vulnerability.
- Patch immediately and audit applications for unsafe JavaScript execution.
Action Plan for Organizations
- Patch Hermes to the latest version.
- Disable Hermes if patching is not possible (temporary measure).
- Audit React Native apps for untrusted JS execution.
- Monitor for exploitation attempts (crashes, suspicious JS payloads).
- Educate developers on secure coding practices for JavaScript engines.
Future Research Directions
- Automated exploit generation for Hermes vulnerabilities.
- Sandboxing improvements to limit Hermes’ attack surface.
- Fuzzing Hermes to discover additional vulnerabilities.
References: