VDB
Sign up
MEDIUM5.8

GHSA-x6m4-chr9-cg97

vm2 leaks absolute host filesystem paths to sandbox code via error stack formatting

Quick fix

GHSA-x6m4-chr9-cg97 — vm2: upgrade to the fixed version with the command below.

npm install vm2@3.11.7

Details

## Summary

Attacker-controlled code can trigger a host-realm syntax error and read its stack through the vm2 bridge. Host-realm stack formatting bypasses the sandbox-side redaction, so the returned value exposes absolute paths from vm2, Node.js internals, and the embedding application. Default VM and NodeVM configurations are affected without requiring special options.

## PoC

A default-configured `VM` runs attacker-supplied code. Calling `eval` with deliberately malformed source makes the host-side source transformer throw a `SyntaxError`; reading `.stack` on the caught error exposes the host call stack to the sandbox.

```js const { VM } = require("vm2"); console.log(new VM().run(` var s; try { eval("@@@ catch") } catch (e) { s = e.stack } s; `)); ```

### Observed output

```text SyntaxError: Unexpected character '@' at makeNiceSyntaxError (.../lib/transformer.js:41:16) at transformer (.../lib/transformer.js:116:8) at Object.transformAndCheck (.../lib/vm.js:76:14) at Object.apply (.../lib/setup-sandbox.js:2585:16) at VM.run (.../lib/vm.js:529:16) ```

The stack string returned to the sandbox contains absolute host paths for `lib/transformer.js`, `lib/vm.js`, `lib/setup-sandbox.js`, Node internals, and the embedding application's own source file.

## Impact

Sandboxed code running under the default `new VM()` or `new NodeVM()` configuration can read absolute filesystem paths of the embedding application's source tree plus host function names, bypassing the host-path redaction added for GHSA-v27g-jcqj-v8rw. On a multi-tenant code-runner this discloses deployment layout such as `/home/app/...` or `/var/task/...`, useful for fingerprinting and for chaining into further attacks. The bridge forwards `.stack` reads to the host-realm formatter (`lib/bridge.js:1482`), so the sandbox-side stack redaction never runs; the leak does not require special configuration and persists when string eval is disabled, because the host-side transformer throws before eval is handled. Information disclosure only, no code execution.

Are you affected?

Enter the version of the package you're using.

Affected packages

npm/vm2
Introduced in: 3.11.0Fixed in: 3.11.7
Fixnpm install vm2@3.11.7

References