Deny sandbox self-require of vm2 and sandbox the shipped CLI
fix(GHSA-j3hm-6rg5-mchv, GHSA-jxxv-8r27-vm4p): deny sandbox self-require of vm2 and sandbox the shipped CLI
Deny sandbox self-require of vm2 and sandbox the shipped CLI903017-fix-deny-sandbox-self-require-of-vm2-and-cve-2026-92946-cve-2026-92950fixdeny sandbox self require vm2 shipped
Committed by patriksimek-bot
commit message
fix(GHSA-j3hm-6rg5-mchv, GHSA-jxxv-8r27-vm4p): deny sandbox self-require of vm2 and sandbox the shipped CLI
GHSA-j3hm-6rg5-mchv (dup: GHSA-w9c4-gw9x-53mq) — sandboxed code running under
`require.external` could `require('vm2')` from disk and construct an
*unrestricted* nested `NodeVM`, defeating the guarantee that nesting is off by
default, and reach `child_process` through it.
Fix (lib/resolver-compat.js): `isVm2SelfRequire`, consulted at the top of
`CustomResolver.isPathAllowed` (inherited by `LegacyResolver`), denies a sandbox
`require()` of vm2's own importable surface — its `lib/` directory and package
main entry — matched by realpath so a symlinked candidate cannot dodge the
boundary. Denied by every spelling: bare `vm2`, the `lib/` path, `index.js`, and
the package main entry. Scoped to `lib/` plus the main entry rather than the whole
package root, because in the source tree that root also holds fixtures an
embedder's `require.root` may legitimately point at. `nesting: true` is
unaffected — it uses the builtin-override mechanism, not an external file require.
GHSA-jxxv-8r27-vm4p — the shipped CLI (`npx vm2 ./script.js`) ran the target
script with no effective sandbox boundary. `lib/cli.js` constructed
`NodeVM.file(path, {require: {external: true}})` with no `require.root` and the
default `require.context: 'host'`, so `CustomResolver.isPathAllowed` admitted
every candidate path and each admitted module loaded through the real host
`require()`. A script handed to the CLI could `require(__filename)` — or any other
absolute path — and have that file execute in the host realm with full host
authority. The tool whose only purpose is isolation provided none.
Fix (lib/cli.js): the CLI now confines requires to the target script's own
directory (`root: pa.dirname(script)`) and loads them inside the sandbox
(`context: 'sandbox'`). Verified end-to-end: under `node lib/cli.js <script>` the
target's `require('fs')` fails with "Cannot find module 'fs'" and no host marker
file is written.
Accepted residual, deliberately not changed here: `require.external` without
`require.root` still host-requires any named path, because
`isPathAllowed` returns true when `rootPaths === undefined`. That breadth is the
documented meaning of the option. Refusing the combination at construction is a
breaking change — it would reverse the shipped GHSA-cp6g-6699-wx9c invariant that
construction does not throw when `root` is unset, and breaks existing embedder
configurations — so it is deferred to the next major. A one-time `console.warn`
ships in the meantime, steering embedders toward `require.root` /
`context: 'sandbox'`.
Restores the Defense Invariant that sandboxed code cannot obtain host-realm
constructors capable of rebuilding an unrestricted sandbox.
Tests: test/ghsa/GHSA-j3hm-6rg5-mchv/ and test/ghsa/GHSA-jxxv-8r27-vm4p/ — the
vm2-self-require denial across all spellings, the CLI end-to-end posture, the
no-over-block cases, and an assertion pinning the accepted residual's current
no-throw behaviour so the next-major change is a conscious edit.
Docs: ATTACKS.md gains Category 47 plus a matching "How The Bridge Defends" row.
No package.json version bump (deferred to the release pass).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>Editor assessment
This commit patches CVE-2026-92946 and CVE-2026-92950. The body explains both advisories thoroughly - vm2 self-require creating an unrestricted nested NodeVM, and the CLI loading requires in the host realm - and describes the realpath-based denial and root/context confinement. Two GHSA ids in the scope and a 107-character subject violate CCv1 scope and length conventions, keeping it at 3. Style-wise the body is clear and separated; two GHSA ids in the scope and the 107-character subject are the formal flaws.