Executive brief
vm2 is a sandbox library that allows Node.js code to execute untrusted scripts in an isolated environment. When the require.external option is enabled without explicitly setting require.root to exclude node_modules, attackers can bypass the sandbox entirely and execute arbitrary commands on the host system. This vulnerability affects applications using vm2's documented examples, making it a critical risk for any service running user-supplied code.
Technical details
The vulnerability is a sandbox escape via insecure defaults (CWE-1188) in vm2's require.external feature. When require.external is true and require.root is not explicitly set, the resolver's isPathAllowed() method returns true (unrestricted access), and the context parameter defaults to 'host', causing files to be loaded via the real Node.js require() instead of the vm2 sandbox. Attackers can require() vm2's own installed package from node_modules, instantiate an unrestricted NodeVM instance, and execute arbitrary host OS commands via child_process. The vulnerability is reachable when the require.external option is enabled in the NodeVM constructor without a properly configured root parameter. A fix is available in version 3.11.7 and later.
Affected products
- Patriksimek vm2 < 3.11.7
Timeline
- 2026-08-24: disclosed
- 2026-09-17: patched: version 3.11.7