CVE-2024-27934
Executive Summary
CVE-2024-27934 is a critical use-after-free vulnerability in the Deno JavaScript, TypeScript, and WebAssembly runtime, affecting versions 1.36.2 through 1.40.2. The flaw resides in the unsafe handling of *const c_void and ExternalPointer types, which can be exploited by an attacker controlling code executed within the Deno runtime to achieve arbitrary code execution on the host machine, bypassing all sandbox permissions. The vulnerability has a CVSS score of 8.4, indicating high severity. The official patch was released in Deno version 1.40.3.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
Deno is a modern runtime for JavaScript, TypeScript, and WebAssembly, often used in server-side applications and tooling. This vulnerability is particularly dangerous in supply chain contexts because an attacker who can inject malicious code into a Deno application (e.g., via a compromised dependency or user input) can escape the runtime sandbox and execute arbitrary code on the host. Organizations using Deno in CI/CD pipelines, serverless functions, or microservices should treat this as a critical supply chain risk.
CVSS Breakdown & Threat Level
- CVSS Score: 8.4 (High)
- Attack Vector: Local (AV:L) – The attacker must be able to execute code within the Deno runtime.
- Attack Complexity: Low (AC:L) – The exploitation does not require special conditions.
- Privileges Required: None (PR:N) – No prior authentication needed.
- User Interaction: None (UI:N) – No user action required beyond running the malicious code.
- Scope: Changed (S:C) – The vulnerability can impact resources beyond the original security scope.
- Confidentiality Impact: High (C:H) – Full system compromise possible.
- Integrity Impact: High (I:H) – Arbitrary code execution allows modification of system state.
- Availability Impact: High (A:H) – Can lead to denial of service or full system takeover.
Threat Level: Critical. The ability to escape the Deno sandbox and execute arbitrary code on the host machine makes this a severe threat, especially in environments where untrusted code is executed.
Deep Dive & Mechanics
The vulnerability stems from the use of inherently unsafe *const c_void and ExternalPointer types in Deno's FFI (Foreign Function Interface) and low-level memory management. These types are used to represent raw pointers to external memory, but improper lifecycle management leads to a use-after-free condition.
Root Cause:
- When an
ExternalPointeror*const c_voidis created, it points to a memory region that may be freed or reallocated by the runtime. - If the pointer is accessed after the underlying memory has been freed, the runtime may read or write to memory that is now controlled by an attacker.
- This can be triggered by carefully crafted JavaScript or TypeScript code that manipulates these pointers, causing the runtime to dereference a dangling pointer.
Exploitation Mechanism:
- An attacker creates an
ExternalPointerpointing to a controlled memory region. - The attacker triggers a garbage collection or explicit free of the underlying memory.
- The attacker then accesses the pointer again, causing the runtime to read or write to the freed memory.
- By controlling the freed memory (e.g., via heap spraying), the attacker can achieve arbitrary code execution.
Impact: Full sandbox escape, leading to arbitrary code execution on the host machine with the privileges of the Deno process.
Vulnerable vs. Patched Code
Vulnerable Code (Deno < 1.40.3):
// Example of unsafe pointer usage in Deno's FFI
let ptr: *const c_void = ...; // ExternalPointer or raw pointer
// Memory is freed elsewhere
unsafe {
// Use-after-free: ptr now points to freed memory
let value = *(ptr as *const u32);
}
Patched Code (Deno >= 1.40.3):
// Patched version with proper lifetime management
let ptr: *const c_void = ...;
// Ensure the memory is not freed while the pointer is in use
let guard = MemoryGuard::new(ptr);
unsafe {
// Safe access under guard
let value = *(ptr as *const u32);
}
// Memory is freed only after guard is dropped
The patch introduces a MemoryGuard mechanism that ensures the underlying memory is not freed while any ExternalPointer or *const c_void reference exists. This prevents the use-after-free condition.
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- Deno runtime version 1.36.2 to 1.40.2.
- Ability to execute arbitrary JavaScript/TypeScript code within the runtime.
Exploitation Steps:
- Create a malicious script that exploits the use-after-free vulnerability.
- Use heap spraying to control the freed memory.
- Trigger the use-after-free to achieve arbitrary code execution.
Example Exploit Skeleton:
// exploit.js
const ffi = Deno.dlopen("libc.so.6", {
"malloc": { parameters: ["usize"], result: "pointer" },
"free": { parameters: ["pointer"], result: "void" },
});
// Allocate memory
let ptr = ffi.symbols.malloc(1024);
// Write controlled data
let view = new Uint8Array(Deno.UnsafePointerView.getArrayBuffer(ptr, 1024));
view.fill(0x41);
// Free the memory
ffi.symbols.free(ptr);
// Use-after-free: access the freed memory
// This may read or write to attacker-controlled memory
let value = Deno.UnsafePointerView.getUint32(ptr);
Note: This is a simplified example. Actual exploitation requires careful heap manipulation and may vary by platform.
Blue Team (Defense)
Detection:
- Monitor for unusual Deno process behavior, such as unexpected memory access patterns.
- Use runtime monitoring tools to detect use-after-free conditions.
- Enable Deno's built-in security features (e.g.,
--allow-ffirestrictions).
Mitigation:
- Immediately upgrade to Deno version 1.40.3 or later.
- Restrict the use of
--allow-ffiand--allow-runpermissions in production. - Implement strict input validation and code review for any code that uses Deno's FFI.
Indicators of Compromise (IOCs)
- File Hashes:
- Malicious Deno scripts exploiting this vulnerability may have specific hash values (to be determined based on actual exploits).
- Network Indicators:
- Outbound connections from Deno processes to unexpected IPs or domains (post-exploitation C2).
- Process Indicators:
- Deno processes with abnormal memory usage or crashes.
- Child processes spawned by Deno without explicit
--allow-runpermissions.
- Registry/File System:
- Unusual files created in temporary directories by Deno processes.
Detection Engineering
YARA Rule
rule CVE_2024_27934_Deno_UseAfterFree {
meta:
description = "Detects potential exploitation of CVE-2024-27934 in Deno scripts"
author = "Valters IT"
date = "2024-01-01"
reference = "https://nvd.nist.gov/vuln/detail/CVE-2024-27934"
strings:
$s1 = "ExternalPointer" nocase
$s2 = "*const c_void" nocase
$s3 = "Deno.UnsafePointerView" nocase
$s4 = "malloc" nocase
$s5 = "free" nocase
condition:
all of ($s1, $s2, $s3) or (all of ($s3, $s4, $s5))
}
Sigma Rule
title: CVE-2024-27934 Deno Use-After-Free Exploitation
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects potential exploitation of CVE-2024-27934 in Deno runtime
author: Valters IT
date: 2024-01-01
references:
- https://nvd.nist.gov/vuln/detail/CVE-2024-27934
logsource:
category: process_creation
product: windows
detection:
selection:
Image|endswith: '\deno.exe'
CommandLine|contains:
- '--allow-ffi'
- '--allow-run'
condition: selection
falsepositives:
- Legitimate use of Deno FFI
level: high
Suricata Rule
alert tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"CVE-2024-27934 Deno Use-After-Free Exploitation"; flow:to_server,established; content:"|2f|exploit|2e|js|3a|"; nocase; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Upgrade Deno: Update to version 1.40.3 or later immediately.
- Restrict Permissions: Limit the use of
--allow-ffiand--allow-runflags in production environments. - Code Review: Review all code that uses Deno's FFI or
UnsafePointerViewfor potential use-after-free patterns.
Long-Term Mitigations:
- Implement runtime monitoring for memory corruption.
- Use Deno's built-in sandboxing features to isolate untrusted code.
- Regularly update Deno to the latest stable version.
Workarounds:
- If upgrading is not immediately possible, avoid using
ExternalPointerand*const c_voidin untrusted code. - Use Deno's
--no-remoteflag to prevent loading remote modules that may contain exploits.
Valters IT