//nefariousplan

CVE-2026-43998: vm2's require.root Ran a Lexical String Check. pnpm Was Already the Symlink.

vendor

patterns

cve

proof of concept

NodeVM's require.root option is the way vm2 callers tell the sandbox: do not load code from outside this directory. The pre-patch check in lib/resolver-compat.js was a String.prototype.startsWith test on a path.resolve() output. The loader was Node's native require(). path.resolve does not dereference symlinks. require() does. Any symlink inside the root pointing outside it passed the check and was loaded from the target. pnpm's canonical node_modules layout puts a symlink at every package entry by design. So does npm link. So do npm workspaces. The exploit prerequisite ships preinstalled.

CVE-2026-43998 is GHSA-cp6g-6699-wx9c, fixed in vm2 v3.11.0 on 2026-05-01.

The check ran on the lexical path. The loader followed the symlink.

The pre-patch isPathAllowed in lib/resolver-compat.js:

isPathAllowed(filename) {
    return this.rootPaths === undefined || this.rootPaths.some(path => {
        if (!filename.startsWith(path)) return false;
        const len = path.length;
        if (filename.length === len || (len > 0 && this.fs.isSeparator(path[len-1]))) return true;
        return this.fs.isSeparator(filename[len]);
    });
}

filename is the output of path.resolve() performed earlier in the resolver. path.resolve is purely lexical. It does not stat anything, does not follow links, does not touch the filesystem. The check is a prefix match between two strings.

The thing that actually loads the module is Node's native require(). require() calls fs.realpathSync on the resolved path before reading it, which dereferences every symlink in the chain. The two layers are looking at two different paths.

The file-level case is the bare statement of the problem. Inside the configured root, create a symlink whose target is /etc/passwd-reader.js or any host script outside the root. The symlink's path string starts with the root prefix. path.resolve returns the symlink's path. startsWith returns true. require() follows the symlink and loads from the target. With context: 'host' set, that target runs in the host realm with no bridge.

The published repro under test/ghsa/GHSA-cp6g-6699-wx9c/repro.js lays out four cases. The file-level symlink. The directory-level layout pnpm produces. A baseline with no symlinks that fails closed correctly. A root that is itself a symlink, which has to keep working because that is the legitimate caller pattern when require.root is given a tmpdir or a checkout that lives behind a symlinked path. The fourth case is the constraint on the fix: canonicalize both sides, not just the candidate, or every legitimate use under a symlinked root breaks.

pnpm's node_modules is the directory-level variant by design.

pnpm does not flatten dependencies into the root node_modules. It builds a content-addressed store under node_modules/.pnpm/ and creates a symlink for every package the project depends on. A path that looks like node_modules/some-pkg/index.js resolves through one symlink jump to node_modules/.pnpm/[email protected]/node_modules/some-pkg/index.js. The store directory is a sibling of the visible node_modules, not always a descendant. Transitive dependencies live in .pnpm/ subdirectories named by package and version, and the resolved real path can land anywhere under the store.

If a NodeVM is configured with require.root pointing at a project that uses pnpm, every require('some-pkg') from inside the sandbox resolves to a path string under the root, passes the prefix check, and gets loaded from a location outside the root. npm link produces the same shape: the linked package's entry under node_modules is a symlink to wherever the linked source actually lives, which is by definition outside the consuming project. npm workspaces also produces it: workspace packages are symlinked into the consumer's node_modules and point back up into the monorepo's packages/ directory.

The published exploit prerequisite is "an attacker who can create a symlink inside the root." On any pnpm project, the package manager already did that, dozens or hundreds of times, during install. The same is true for any project using workspaces or npm link for local development. The threat model the advisory describes as the prerequisite is, on a wide class of real deployments, the default install state.

Defense Invariant #1, applied one layer down.

vm2's docs/ATTACKS.md opens with thirteen Defense Invariants. The first one reads: "No host-realm object reaches sandbox code unwrapped. Every value crossing the boundary is a primitive, a sandbox-realm object, or a bridge proxy." That invariant is about the JavaScript bridge: every property access through a proxy must canonicalize what it returns before handing it to the guest.

The resolver violation is the same shape. The resolver and the loader must operate on the same canonical path namespace, or the gate runs on one set of strings while the loaded code lives at a different set. The patch commit message uses exactly that framing. ATTACKS.md was updated in the same patch series with an Attack Category 24 entry that documents both the file-level and directory-level (pnpm) canonical examples, and ties them back to Invariant #1.

The catalog has twelve prior posts on gate-before-canonicalize. Every one of them is a URL or HTTP-path exhibit: the SiYuan path traversal, the Gotenberg pair, the Alfresco and Spring proxy cases, the s3-proxy authorizer. Filter, then dereference. The dereference reaches a place the filter did not see.

This is the first filesystem-symlink exhibit. The substrate is different: realpath() instead of URL.normalize(), kernel-level link resolution instead of URL parsing. The structural defect is the same. Two layers, two views of the same logical resource, gate on the first view, action on the second. The pattern does not care whether the indirection is %2e%2e in a path segment or a lstat-returned S_IFLNK. It cares that the gate and the actor see different things.

The vm2 catalog also has prior posts that establish what the sandbox boundary is supposed to enforce. CVE-2026-24120 where the README admits the bridge has gaps. CVE-2026-43997 where util.inspect was the unwrapped path. CVE-2026-44001 where the Promise executor argument crossed the membrane raw. Those are bridge-layer holes. This one is one layer further out, in the part of vm2 that does not even wrap, it just gates access. The gate had the same defect.

The patch realpaths both sides. One day later it added an eager probe.

Commit b53a591 on 2026-04-30 makes three changes. The DefaultFileSystem and VMFileSystem adapters in lib/filesystem.js gain a realpath() method that wraps fs.realpathSync. The isPathAllowed check canonicalizes the candidate before the prefix test:

isPathAllowed(filename) {
    if (this.rootPaths === undefined) return true;
    let realFilename;
    try {
        realFilename = this.fs.realpath(filename);
    } catch (e) {
        return false;
    }
    return this.rootPaths.some(path => {
        if (!realFilename.startsWith(path)) return false;
        const len = path.length;
        if (realFilename.length === len || (len > 0 && this.fs.isSeparator(path[len-1]))) return true;
        return this.fs.isSeparator(realFilename[len]);
    });
}

And the root paths are canonicalized once at construction time via fsOpt.realpath(resolved) so the comparison happens between two canonical paths. The catch returns false. Fail-closed: if a path cannot be realpath'd because it does not exist or because the process cannot stat it, it is not allowed.

Commit 28d5f4d lands one day later, on 2026-05-01. It adds an eager probe at NodeVM construction: if require.root is configured and the FileSystem adapter does not implement realpath(), NodeVM throws immediately rather than constructing a sandbox that would silently fail-closed on every require. The commit message is explicit that this exists to prevent the case where a custom VMFileSystem was supplied without the new method.

The VMFileSystem extension point is the part of vm2 that lets a caller intercept all sandbox filesystem reads: in-memory filesystems, read-only overlays, whitelisted bundles. It is a published API. Anyone using it had to ship their own implementation against the pre-patch interface, which did not require realpath. After the primary patch lands, those implementations satisfy the type signature but cause the new isPathAllowed to catch on every call and return false. A caller updating from v3.10.x to v3.11.0 with a custom FileSystem would see every require() inside the sandbox start failing with "module not found," not "patched against a CVE." The eager probe converts that into a loud construction-time error that names the missing method.

Two patches, one day apart, addressing the same structural problem from opposite ends. The first one closes the bypass. The second one closes the silent regression in the closure. The pattern of the second patch is worth naming on its own: when a security fix requires a new primitive on an extension point, the fix is not complete until callers who do not implement that primitive get a loud signal at the earliest possible moment. Otherwise the fix degrades quietly from "sandbox now safe" to "sandbox now broken in a way that the caller will work around."

CWE-59 closed. CWE-367 documented.

The patch description names CWE-59, Improper Link Resolution Before File Access. That is the closed case. There is also a residual race window: between realpath() returning a canonical path and require() calling its own realpath, an attacker who can write to the filesystem can swap the symlink target. ATTACKS.md notes this under "Considered Attack Surfaces" and observes that the race is not closed structurally because Node does not expose openat or O_NOFOLLOW to user code. Closing it would require a native module or a different language for the loader.

The documented residual is honest. The exploit window is small and requires write access to the filesystem the sandbox is reading from, which is a different threat model from "I control the script that runs inside the sandbox." It is also a CWE-367 (TOCTOU) of the type that everyone using realpath-then-open lives with on POSIX. Naming it in the docs is the move. The vm2 sandbox now operates inside the same race window as every other userspace file-permission check on Linux, and the docs say so out loud rather than pretending the fix is complete.

v3.11.0 closed thirteen advisories. This is the one not in the bridge.

The 2026-05-01 release fixed thirteen GHSA advisories at once. Twelve of them are bridge-layer or V8-internal: the executor argument, the meta-builtin denylist, util.inspect, and the rest of the per-feature wraps that have been accumulating since the project began. CVE-2026-43998 is the only resolver-layer fix in the batch. The substrate is the filesystem instead of the V8 object graph, but the project is the same project, and the maintainer is fixing the same kind of defect on two different surfaces in one release.

unpatchable-primitive has been the catalog frame for vm2 since the beginning: the substrate keeps producing new ways for a host-realm thing to reach the sandbox. This post extends it. The substrate is not only the V8 object graph; it is also the host filesystem's link semantics. A library that wants to sandbox code execution against the host has to handle both, and the sandbox has no special privilege over either one. The set of primitives that can leak across the boundary is the set of primitives the host platform exposes, and that set grows with the host, not with the sandbox.

the-detector-is-the-target fits cleanly. The gate is the asset. The require.root check is what callers depend on when they set the option, which means the check is the entire value of the option. A bypass of the check is the entire bypass of the feature. There is no defense in depth behind isPathAllowed; if it returns true, require() runs, and if context: 'host' was set, the require runs in the host realm. The detector is one prefix match between two strings. When two strings are the detector, the attacker's job is to find two views of the same logical thing where the strings agree and the loaded code does not.

PoC: GHSA-cp6g-6699-wx9c.

vm2's bridge cannot see what V8 reads. vm2's resolver could not see what the kernel followed. Both are the same shape, one layer apart.