NodeVM Sandbox Escape via Unrestricted OS and DNS Built-ins
The vm2 sandbox library fails to restrict the 'os' and 'dns' built-in modules when using the 'builtin: ['*']' configuration, enabling host-level information disclosure and process-wide DNS hijacking.
The NodeVM component within the vm2 sandbox library contains a critical flaw where the 'os' and 'dns' built-in modules are not correctly identified as dangerous when using the 'builtin: ['*']' configuration. While prior security updates (GHSA-9g8x-92q2-p28f) restricted modules like 'diagnostics_channel' and 'perf_hooks' to prevent host-process state exposure, 'os' and 'dns' were omitted. Because NodeVM relies on a 'vm.readonly()' proxy, these modules expose host-process state that cannot be localized to the sandbox. Attackers can leverage 'os' to fingerprint the host environment (UID, GID, network interfaces) and 'dns.setServers()' to hijack DNS lookups for the entire host process. This allows for sophisticated supply-chain attacks, credential exfiltration, and service authentication subversion, effectively granting the sandboxed code control over the host's communication and configuration.
Attack Chain
- The attacker identifies an application leveraging vm2 with the 'builtin: ['*']' configuration.
- The attacker injects malicious JavaScript into the sandboxed environment.
- The attacker calls 'os.userInfo()' or 'os.networkInterfaces()' to perform host environment reconnaissance.
- The attacker invokes 'dns.setServers()' to point the host process's DNS resolution to an attacker-controlled resolver.
- The host process performs legitimate outbound requests (e.g., npm dependency installation, API calls, OIDC authentication).
- The attacker's DNS resolver intercepts these queries and returns malicious IPs.
- The host process connects to the attacker's infrastructure, facilitating data exfiltration, dependency substitution, or authentication bypass.
Impact
Successful exploitation allows for full compromise of the host process's network communication, enabling credential theft, supply-chain attacks via malicious package substitution, and bypass of host-side security controls. This vulnerability affects any Node.js application utilizing vm2 for untrusted code execution, including webhooks and CI/CD runners, potentially impacting production environments hosting multiple tenants.
Recommendation
Prioritize upgrading vm2 or modifying the 'builtin' allowlist immediately.
- Audit all vm2 configurations to identify instances using 'builtin: ['*']' and ensure '-os' and '-dns' are explicitly added to the exclusion list.
- Implement the following Sigma rule to detect attempts to invoke sensitive 'os' or 'dns' methods within a sandboxed environment if logs are instrumented.
- Monitor host process DNS configurations or anomalies in outbound HTTP request patterns for hosts running untrusted code.
Immediate actions
Audit vm2 configuration files across the organization to identify usage of 'builtin: ['*']'
Mitigations
Explicitly exclude 'os' and 'dns' from the builtin configuration in all vm2 instances.
NodeVM configuration