Summary
vm2's NodeVM can incorrectly apply builtin-module denylist rules when wildcard access is combined with negative entries. Sandboxed code may bypass restrictions on the filesystem module through fs/promises or node:fs/promises and potentially create, modify, read, or remove host-accessible files.
Affected context
The issue affects vm2 NodeVM configurations that allow builtin modules through a wildcard while attempting to deny selected modules with negative entries. It becomes risky when sandboxed code can invoke module subpaths or alternate node:-prefixed names and the embedder relies on exact-name denylist matching to enforce filesystem restrictions.
Exploit preconditions
- Attack surface: Code executing inside a vm2 NodeVM sandbox - Required access: The ability to run or influence sandboxed JavaScript - Trigger point: A sandboxed require call targeting fs/promises or
node:fs/promises
- Configuration condition: Builtin modules are broadly allowed with a wildcard
while filesystem access is denied using entries that do not cover subpaths
- Why exploitation is possible: Denylist matching treats the denied module
name separately from its filesystem-related subpaths and alternate prefixes
Why this happens
The underlying bug is an incomplete privilege-boundary check in builtin-module filtering. Negative entries are matched against exact module names, so denying fs does not necessarily deny fs/promises, and prefix normalization is inconsistent for node:-qualified names. This maps to CWE-269, Improper Privilege Management, because code operating with reduced sandbox privileges can obtain a capability that the embedder intended to withhold.
Potential impact
- Sandboxed code may access host-visible filesystem APIs
- An attacker could create or modify files within the accessible filesystem scope
- Sensitive files may be read or altered where permissions allow
- Application data, configuration, or temporary artifacts could be removed or corrupted
- The sandbox isolation boundary could be weakened and enable further compromise
General mitigation guidance
Mitigation generally focuses on making capability restrictions complete, normalized, and deny-by-default. Secure-by-default configurations can avoid wildcard builtin access and explicitly permit only the modules and subpaths required by the application. Policy logic should normalize node:-prefixed names, account for subpath relationships, and evaluate restrictions before exposing module capabilities. Reducing trust in sandboxed code, isolating filesystem namespaces, restricting host permissions, and running the process with least privilege can limit consequences if a module-filtering mistake occurs.
How teams detect issues like this
Detection can include static analysis for wildcard builtin permissions combined with incomplete negative entries, as well as review of module-resolution and prefix-normalization logic. Code reviews should flag exact-name checks that do not account for subpaths or equivalent module identifiers. Runtime monitoring can alert on sandboxed processes loading filesystem-related modules or performing unexpected file operations. Policy enforcement in CI can require explicit allowlists and tests covering subpaths, aliases, and node:-prefixed names; automated review tools may help identify these patterns.

