The vulnerability, identified as GHSA-6785-pvv7-mvg7, allows sandboxed code in vm2 to cause a Denial of Service (DoS) by exhausting host memory. This is achieved by calling Buffer allocation methods like Buffer.alloc() with an arbitrarily large size. These native C++ allocation calls are synchronous and cannot be interrupted by vm2's timeout mechanism, allowing a single small request to crash the entire Node.js process with an Out-of-Memory (OOM) error.
The vulnerability is not caused by a flaw within a single function but by the lack of size validation on multiple functions that bridge Buffer allocations from the sandbox to the host. The fix introduces a new bufferAllocLimit option in the VM and NodeVM constructors. This limit is then enforced within wrappers around the vulnerable allocation functions.
The analysis of the patch identified the exact locations where these checks were added, revealing the vulnerable pathways:
-
VM.constructor and NodeVM.constructor: The vulnerability was exploitable by default. The patch adds the bufferAllocLimit option to allow users to opt into the protection. The NodeVM.constructor was also patched to correctly propagate this security setting to the underlying VM.
-
BufferHandler.apply and BufferHandler.construct: These methods in lib/setup-sandbox.js handle the deprecated Buffer(N) and new Buffer(N) syntax. They were vulnerable because they passed the allocation size directly to the host without validation.
-
alloc, allocUnsafe, and allocUnsafeSlow: These functions in lib/setup-sandbox.js are wrappers for the corresponding Buffer methods. The patch added the checkBufferAllocLimit call to them to prevent unbounded allocations. The vulnerability existed because this check was previously absent.
An engineer seeing this CVE in their environment should understand that any vm2 instance without a properly configured bufferAllocLimit is vulnerable to a DoS attack from the sandboxed code.