-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## \"Fixed in 3.11.0\" is an option named bufferAllocLimit\n\nThe patched code lives in two files. The cap itself is in `lib/setup-sandbox.js`, captured into a closure-scoped constant at sandbox initialization so a sandbox-side prototype-pollution attempt cannot mutate it post-init:\n\n```js\nconst { allowAsync, GeneratorFunction, AsyncFunction, AsyncGeneratorFunction, bufferAllocLimit } = data;\n\n// SECURITY (GHSA-6785-pvv7-mvg7): Buffer.alloc / allocUnsafe / allocUnsafeSlow\n// (and the deprecated Buffer(N) / new Buffer(N) forms) execute as a single\n// synchronous host C++ allocation. V8's `timeout` cannot interrupt them, so\n// an attacker controlling the size argument can amplify a small payload into\n// hundreds of megabytes of host RSS, crashing the host process in\n// memory-constrained environments (Docker/K8s/Lambda). Cap every allocation\n// size before it reaches the host implementation.\nconst localBufferAllocLimit = bufferAllocLimit;\nfunction checkBufferAllocLimit(size) {\n if (typeof size === 'number' && size > localBufferAllocLimit) {\n throw new RangeError('Buffer allocation size ' + size + ' exceeds bufferAllocLimit ' + localBufferAllocLimit);\n }\n}\n```\n\n`data` is built by the `VM` constructor in `lib/vm.js`. The default written into the constructor's destructure is `Infinity`:\n\n```js\nconst {\n compiler = 'javascript',\n compilerOptions,\n allowAsync: optAllowAsync = true,\n bufferAllocLimit = Infinity,\n} = options;\n```\n\n`checkBufferAllocLimit` is wired into every `Buffer.alloc`, `Buffer.allocUnsafe`, `Buffer.allocUnsafeSlow`, the deprecated `Buffer(N)`, and `new Buffer(N)` path on the sandbox-facing BufferHandler. The wrap is complete. The const-capture is deliberate, defended by a comment that explains why mutating prototype state post-init cannot defeat the cap. The fix, in mechanism, is sound.\n\nThe fix, by default, does nothing.\n\n## The primitive, end to end\n\nThe victim is the Node.js shop running vm2 in a containerized worker to execute customer-uploaded plugins. A SaaS automation builder. A workflow engine. A \"run this JavaScript snippet\" feature on a webhook receiver. The host process is a 512 MB container in K8s, or a 1 GB AWS Lambda, sized for the workload plus headroom. The user-supplied code runs through:\n\n```js\nconst { NodeVM } = require('vm2');\nconst vm = new NodeVM({ timeout: 1000 });\nvm.run(userCode, 'plugin.js');\n```\n\nThe customer submits, as their plugin:\n\n```js\nmodule.exports = function () {\n Buffer.alloc(1024 * 1024 * 1024); // 1 GB\n};\n```\n\nThe handler calls `vm.run(userCode)`. Control enters the sandbox. The sandbox-side `Buffer.alloc` is the vm2 BufferHandler, which is a proxy over the host realm's `Buffer`. On invocation, the handler passes the size argument through to the host's native `Buffer.alloc`. `Buffer.alloc` in Node.js is a synchronous V8 C++ binding that calls into `node::Buffer::Alloc`, which calls into V8's `ArrayBuffer` allocator, which calls into the platform allocator (`malloc` or its equivalent). The whole stack is one synchronous host C++ frame from V8's perspective; `vm.run`'s `timeout` option uses V8's interrupt API, which only fires on JS bytecode boundaries.\n\nThere are no JS bytecode boundaries inside `node::Buffer::Alloc`. The timeout cannot fire until the allocation returns. The allocation does not return until the OS supplies the pages. The OS supplies the pages by paging out the container's working set and then, when the container's memory limit is exceeded, killing the process: `FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory`.\n\nA roughly hundred-byte plugin terminates a roughly billion-byte container.\n\nThe fix is to set `bufferAllocLimit` on the `NodeVM` constructor. In 3.11.0 and later, with the cap set, the BufferHandler throws `RangeError` synchronously before the host allocation runs. Without the cap, the handler does what it did on 3.10.6.\n\n## The regression test names the default in writing\n\nThe repro file at `test/ghsa/GHSA-6785-pvv7-mvg7/repro.js` is the project's regression test for this CVE. It contains the following case, shipped alongside the fix:\n\n```js\nit.cond(\n 'default is permissive (Infinity): large allocations are allowed without an explicit cap',\n LARGE_ALLOC_RUNS,\n function () {\n this.timeout(30000);\n // Sanity: with no option, sandbox can allocate above what would have been the old default cap.\n const r = new VM().run('Buffer.allocUnsafe(64 * 1024 * 1024).length');\n assert.strictEqual(r, 64 * 1024 * 1024);\n },\n);\n```\n\nA bare `new VM()` with no options allocates a 64 MB buffer inside the sandbox without error. The test asserts that this allocation succeeds. The maintainer added the assertion as part of the fix that closes the CVE.\n\nThe same commit that introduced the option includes a documentation update with this line:\n\n> Default is `Infinity` (non-breaking). Embedders running untrusted code in memory-constrained environments need to know this exists and that they should opt in.\n\nThe commit message, the JSDoc on the option in `lib/vm.js`, the README section that follows the security disclaimer, and the regression test all say the same thing in slightly different words: the option exists, the default is unbounded, embedders need to opt in. The maintainer documents the choice to the standard the project's other security work is documented to.\n\nThe CVE record at NVD does not include the word `opt`. It does not mention `bufferAllocLimit`. It says \"This vulnerability is fixed in 3.11.0.\" Both the CVE record's description and the maintainer's commit message are public. Both cannot be operationally accurate.\n\n## The companion bug, buried in NodeVM\n\nThe GHSA-6785 fix landed two changes. The first introduced the option. The second, in `lib/nodevm.js`, fixed a separate bug nobody assigned a CVE to:\n\n```js\n// SECURITY (GHSA-6785-pvv7-mvg7): forward bufferAllocLimit so embedders\n// using NodeVM (the more common form for module-loading sandboxes) can\n// opt into the cap. Also forward timeout / allowAsync which were\n// previously silently dropped by the super() call.\nsuper({__proto__: null, compiler: compiler, eval: allowEval, wasm, timeout, allowAsync, bufferAllocLimit});\n```\n\nRead the second sentence of the comment.\n\nBefore this patch, `NodeVM`'s `super()` call to its parent `VM` constructor dropped `timeout`. Embedders who constructed a `NodeVM` with `{ timeout: 1000 }` got a sandbox with no timeout. The option was named, accepted at the API surface, and silently discarded one frame later. Same for `allowAsync`: an embedder who wrote `new NodeVM({ allowAsync: false })` got a sandbox that ran async code anyway.\n\n`NodeVM` is the form vm2's documentation describes as \"the more common form\" for module-loading sandboxes. The README's `Hardening recommendations` example uses bare `VM`, but most production embedders reach for `NodeVM` because they want `require`. Every one of them setting a timeout on `NodeVM` before 3.11.0 never had a timeout. Every one of them setting `allowAsync: false` got `true`.\n\nThis bug has no separate CVE. There is no GHSA for it. It is named in one comment in one commit and in no CVSS scoring authority's database. The CVE record for vm2 3.11.0 says one bug was fixed in this release. The release fixed two, plus eleven others.\n\n## The README says what the CVE record will not\n\nThe `Hardening recommendations` section vm2 added in this same release cycle opens:\n\n> vm2 prevents sandbox escapes (untrusted code obtaining host realm access). It does **not**, by itself, prevent every form of resource exhaustion or denial-of-service.\n\nThat is the project speaking honestly about what its sandbox does and what it does not. The section then walks through five layered defenses an embedder running untrusted code should add around the sandbox:\n\n1. Set `bufferAllocLimit` to a finite value.\n2. Install a host-side `unhandledRejection` handler.\n3. Run with `--max-old-space-size` or a container memory limit.\n4. Treat `require.builtin: ['*']` as a non-sandbox configuration.\n5. Treat `nesting: true` as an escape hatch.\n\nFive recommendations. The CVE record does not include any of them. The CVE record's `description` field says \"fixed in 3.11.0,\" which is true of exactly one fact about one of the five (`bufferAllocLimit` now exists as an option, and exposes a knob the embedder may turn).\n\nThe reader who installs the patch and closes the ticket has satisfied the CVE record. The reader who installs the patch and closes the ticket has not addressed the bug.\n\n## vm2's own changelog says this will happen again\n\nvm2's `Important Security Disclaimer`, written into the README in the same release window:\n\n> Despite our best efforts, researchers and security professionals continuously discover new ways to escape the vm2 sandbox. We actively patch these vulnerabilities as they are reported, but the cat-and-mouse nature of in-process sandboxing means that: New bypasses will likely be discovered in the future.\n\nThe disclaimer is real. The git log in the depth-50 history of the repository shows 22 distinct GHSA identifiers landing as commits, ten of them in 3.11.4 alone. The CHANGELOG names them by class: array species self-return, cross-realm symbol extraction, host intrinsic prototype pollution, async-generator yield-return thenable exception capture, WebAssembly JSPI prototype chain, Promise species hijack, NodeVM builtin denylist bypass via `process` and `inspector/promises` subpaths.\n\nvm2 is a [Design Debt Driver](/patterns/design-debt-driver). The component is a JavaScript interpreter that tries to enforce a security boundary inside the same V8 isolate as the host process. The README says so. The CHANGELOG demonstrates it. Each release closes the named instances; the design holds the primitive. A sufficiently dynamic language runtime sharing an isolate with its caller will keep producing new escape paths for as long as the runtime exists.\n\nThe \"fixed in 3.11.0\" framing belongs to a project where bug classes are patchable on a per-instance basis. vm2 itself does not think of its bug classes that way. Its own README explains that it does not. The disjoint between the record and the project is not the maintainer's framing of his own work. It is the CVE record's framing of vm2's work.\n\n## The pattern is safe-mode-was-opt-in\n\nThis is [safe-mode-was-opt-in](/patterns/safe-mode-was-opt-in), extending the pattern from authoring sinks into resource-exhaustion territory. The pattern's existing exhibits cover [EspoCRM's `defaultTransform`](/posts/espocrm-cve-2026-33657-triple-brace-was-correct), which exposed `no_markup` and `no_entities` as opt-in flags on a Markdown parser and called the unsafe factory anyway; and [DeepSeek-TUI's `task_create`](/posts/deepseek-tui-cve-2026-45374-defaults-were-doing-the-work), whose `unwrap_or(true)` lines distributed shell access to any caller that did not request its absence.\n\nvm2's `bufferAllocLimit` is the same shape on the DoS axis. The library exposes a security-relevant option with an unsafe default. The fix is to set it. The flags exist. The default chooses the unsafe behavior. The release ships the option plus a recommendation to use it; the CVE record ships only the option.\n\nThe EspoCRM exhibit's closing observation applies word for word.\n\nThe defaults are the bug.\n\nPoC: no public exploit repository exists for CVE-2026-44004; the primitive is `vm.run('Buffer.alloc(2**30)')` against any default-configured vm2 prior to 3.11.0, and against any default-configured vm2 from 3.11.0 onward whose embedder did not pass the new option. Vendor advisory at [GHSA-6785-pvv7-mvg7](https://github.com/patriksimek/vm2/security/advisories/GHSA-6785-pvv7-mvg7).","closing_line":"The CVE is closed in the record. The bug is closed in `Infinity` increments.","hook_md":"vm2 3.11.0 fixes CVE-2026-44004 by adding an option called `bufferAllocLimit`. The fix's own regression test contains a passing assertion named `default is permissive (Infinity): large allocations are allowed without an explicit cap`. The CVE record at NVD says \"This vulnerability is fixed in 3.11.0.\" The fix is a feature, not a behavior change. Embedders who upgrade to 3.11.0 and do nothing else stay exactly as vulnerable as they were on 3.10.6.","post_id":377,"slug":"vm2-cve-2026-44004-fix-is-off-by-default","title":"CVE-2026-44004: vm2's Fix for Buffer.alloc Is Off By Default","type":"initial","unreadable_sentence":"The regression test the maintainer shipped with the fix contains a passing assertion that a default-configured vm2 sandbox can still allocate 64 MB host buffers without error."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCalE/KQAKCRDeZjl4jgkQ JqegAQChVtRTcDz1EjP+uSPkvG1vd8lEnW5Pun5AwtJMlMeFggEAvXfy5GD3bOyq F2Z2hYpgAs7ZG8+Wa7QWCHCW+dpllQc= =r+IT -----END PGP SIGNATURE-----