How to fix: Node.js vm Module Executed With Request Data
Node's vm module (runInNewContext, runInThisContext, runInContext, or vm.Script) is invoked with request-derived source code.
Why it matters
The vm module provides only a partial sandbox: numerous documented escapes exist, and untrusted code run through it can access the host process, read environment variables, and often achieve full remote code execution.
vm.runInNewContext and related APIs are frequently mistaken for a true sandbox because they run code in a separate V8 context, but Node's own documentation is explicit that they are not a security mechanism against malicious code.
How to fix it
- 1Never pass request-derived strings to the vm module.
- 2If arbitrary user code execution is a real product requirement, use a properly isolated environment (a separate process with OS-level sandboxing, or a vetted third-party sandboxing service), not vm.
- 3Validate and reject any input path that reaches this sink.
Code examples
Never eval request data via vm
// BAD
const vm = require('vm');
vm.runInNewContext(req.body.expression);
// GOOD: use a fixed allowlist of operations instead of executing arbitrary code
const ALLOWED_OPS = { add: (a, b) => a + b, sub: (a, b) => a - b };
const fn = ALLOWED_OPS[req.body.op];
if (!fn) throw new Error('Unsupported operation');References
Detected automatically by VulnRadar. The check id is code-eval-vm-module, stable across every scan so you can filter or diff on it.
More code checks
- CriticalForm Submits Data Over Insecure HTTP
- MediumPotential Prototype Pollution Sinks Detected
- HighPotential Command Injection Vectors
- HighJWT Decoded Without Signature Verification
- HighPotential Path Traversal Vulnerability
- HighInsecure Authentication Mechanisms Detected
- HighPotential Insecure Deserialization
- Mediumeval() Usage in Inline Scripts
Questions
- How severe is Node.js vm Module Executed With Request Data?
- VulnRadar rates this critical severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id code-eval-vm-module, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Node.js vm Module Executed With Request Data map to?
- It maps to CWE-94. In the OWASP Top 10 it falls under A03:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.