Low

vm2 setup-sandbox.js violates Defense Invariant #11 in stack-trace formatter

  • Disclosed: 29.05.2026
  • Updated: 11.10.2026 10:22

Summary

defaultSandboxPrepareStackTrace in lib/setup-sandbox.js (lines 605, 607) appends to a fresh sandbox-realm lines = [] via lines[lines.length] = value. This is the exact invariant-violating pattern that GHSA-9qj6-qjgg-37qq (commit ca195f0, 2026-05-01) just patched in neutralizeArraySpeciesBatch and codified as Defense Invariant #11 ("Bridge-internal containers must not invoke sandbox code"). A sandbox-installed Array.prototype[N] setter fires during the bridge's safe-default stack-trace formatting and observes / intercepts each appended line.

Details

The post-9qj6 audit note in docs/ATTACKS.md (line 2111) states:

Equivalent pattern elsewhere in the bridge: audited; thisFromOtherArguments, otherFromThisArguments, and every other index-write site already use thisReflectDefineProperty or otherReflectDefineProperty. neutralizeArraySpeciesBatch was the lone outlier.

The audit is scoped to lib/bridge.js. lib/setup-sandbox.js was not covered. defaultSandboxPrepareStackTrace (added under post-#563 hardening for GHSA-v27g) constructs a sandbox-realm [header] array and appends each frame via the prototype-walking index assignment:

// lib/setup-sandbox.js, lines 601-610
const lines = [header];
for (let i = 0; i < callSites.length; i++) {
    try {
        lines[lines.length] = '    at ' + callSites[i];
    } catch (e) {
        lines[lines.length] = '    at <error formatting frame>';
    }
}
return lines.join('\n');

This function runs every time sandbox code reads error.stack (or any path that triggers Error.prepareStackTrace). At the time it runs, user code has already had the opportunity to install a setter on Array.prototype[N]. Because lines starts at length 1, the first iteration writes index 1; if lines[1] has no own data property, V8 walks the prototype chain and invokes the sandbox-controlled setter.

The currently-assigned value is the string ' at ' + callSites[i] (the wrapped CallSite class's safe toString() returns 'CallSite {}'), which limits the immediate impact to a side channel, not an RCE pivot. The concern is structural rather than exploit-today:

  • The just-codified Defense Invariant #11 explicitly requires that any list, set, or map allocated for the bridge's exclusive use must read and write through identity-stable, prototype-bypassing primitives. This site does not.
  • The catch branch at line 607 also uses the same pattern, so a sandbox getter that throws on callSites[i] access still routes its retry write through the prototype chain.
  • A future change that makes the appended slot value an object holding a host-realm reference (for example, an enriched frame record) would re-introduce the exact GHSA-9qj6 attack shape against this codepath.

The fix is mechanical and mirrors the GHSA-9qj6 patch: install entries via localReflectDefineProperty so each appended slot is an own data property and the prototype-chain setter is bypassed.

js
// Suggested patch (sketch)
let linesLen = 1;
function append(s) {
    localReflectDefineProperty(lines, linesLen, {
        __proto__: null,
        value: s,
        writable: true,
        enumerable: true,
        configurable: true,
    });
    linesLen++;
}
for (let i = 0; i < callSites.length; i++) {
    try {
        append('    at ' + callSites[i]);
    } catch (e) {
        append('    at <error formatting frame>');
    }
}

The same pattern at callSiteGetters[callSiteGetters.length] = {...} (line 649) runs only at sandbox setup, before user code can install setters, so it is safe today. Converting it for symmetry would be cheap and forward-compatible.

PoC

vm2 v3.11.2, Node v24.

js
const { VM } = require('vm2');
const result = new VM().run(`
    var observed = { setterFired: false, capturedValue: null, indexFired: null };
    Object.defineProperty(Array.prototype, 1, {
        configurable: true,
        set(value) {
            observed.setterFired = true;
            observed.indexFired = 1;
            observed.capturedValue =
                typeof value === 'string' ? value.slice(0, 40) : typeof value;
        },
        get() { return undefined; }
    });
    var e = new Error('x');
    e.stack;
    observed;
`);
console.log(result);
// {
//   setterFired: true,
//   capturedValue: '    at CallSite {}',
//   indexFired: 1
// }

Sandbox code observed and intercepted the bridge-internal write to lines[1]. Repeating the PoC with the setter installed at multiple indices (0, 1, 2, ...) captures every frame the formatter would otherwise return.

Impact

Hardening / Defense Invariant #11 violation. No direct sandbox escape on the current codebase: the value passed to the setter is a primitive string after the wrapped CallSite.toString(), so attacker-controlled code does not gain a host-realm reference from the setter argument alone. The GHSA-9qj6 entry's "Considered Attack Surfaces" note states the audit covered lib/bridge.js index-write sites; this filing reports the equivalent pattern in lib/setup-sandbox.js so the invariant is uniform across the bridge boundary and future enrichments of the appended record cannot regress into the GHSA-9qj6 shape.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
npm package vm2 < 3.11.4 3.11.4

References

CVSS score -
CVSS vector
CVSS:4.0/AV:L/AC:H/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:N/SI:L/SA:N
Weakness (CWE)
CWE-693
Platform
npm
Package
vm2
Disclosed
29.05.2026
Updated
11.10.2026 10:22

Sources and licenses

OSV / GitHub Advisory Database - GHSA-q3fm-4wcw-g57x - CC BY 4.0

Vulnerability history: vm2

All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.

All (78) in the archive
Total entries
78
First → latest
10.2021 10.2026
Without a fix
1
Exploited in attacks
0

Severity breakdown

  • Critical 51
  • High 14
  • Medium 12
  • Low 1

Disclosures per year

  1. 2021: 1
  2. 2022: 4
  3. 2023: 7
  4. 2024: 0
  5. 2025: 0
  6. 2026: 66
Severity:
  1. Critical · 10.0 CVE-2026-93605 < 3.12.1 3.12.1
  2. Critical · 10.0 CVE-2026-100721 < 3.12.2 3.12.2
  3. Critical · 10.0 CVE-2026-92955 < 3.11.8 3.11.8
  4. Critical · 10.0 CVE-2026-92956 >= 3.10.1, < 3.11.7 3.11.7
  5. Critical · 9.9 CVE-2026-92948 >= 3.9.6, < 3.11.7 3.11.7
  6. Critical · 10.0 CVE-2026-92940 >= 3.11.3, < 3.11.7 3.11.7
  7. Critical · 9.0 CVE-2026-92935 >= 3.11.4, < 3.11.7 3.11.7
  8. Critical · 10.0 CVE-2026-92937 >= 3.11.6, < 3.11.7 3.11.7
  9. Critical · 9.9 CVE-2026-92938 >= 3.11.3, < 3.11.7 3.11.7
  10. Critical · 9.9 CVE-2026-92939 >= 3.11.3, < 3.11.7 3.11.7
  11. Critical · 9.8 CVE-2026-92944 >= 3.10.2, < 3.11.7 3.11.7
  12. Critical · 10.0 CVE-2026-92941 >= 3.11.3, < 3.11.7 3.11.7
  13. High · 7.5 CVE-2026-92961 < 3.11.6 3.11.6
  14. Critical · 9.8 CVE-2026-47698 < 3.11.6 3.11.6
  15. Critical · 9.8 CVE-2026-47210 < 3.11.4 3.11.4
  16. Critical · 10.0 CVE-2026-47208 < 3.11.4 3.11.4
  17. vm2 setup-sandbox.js violates Defense Invariant #11 in stack-trace formatter this entry
    Low CVE-2026-92962 < 3.11.4 3.11.4
  18. Critical · 10.0 CVE-2026-47131 < 3.11.4 3.11.4
  19. Critical · 9.8 CVE-2026-45411 < 3.11.3 3.11.3
  20. Critical · 9.8 CVE-2026-44009 < 3.11.2 3.11.2
  21. Critical · 9.8 CVE-2026-44008 < 3.11.2 3.11.2
  22. Critical · 10.0 CVE-2026-44005 >= 3.9.6, < 3.11.0 3.11.0
  23. Critical · 10.0 CVE-2026-43997 < 3.11.0 3.11.0
  24. Critical · 10.0 CVE-2026-44006 < 3.11.0 3.11.0
  25. Critical · 9.8 CVE-2026-26956 < 3.10.5 3.10.5
  26. Critical · 9.8 CVE-2026-26332 < 3.11.0 3.11.0
  27. Critical · 9.8 CVE-2026-24781 < 3.11.0 3.11.0
  28. Critical · 9.8 CVE-2026-24120 < 3.10.5 3.10.5
  29. Critical · 9.8 CVE-2026-24118 < 3.11.0 3.11.0
  30. Critical · 9.8 CVE-2026-22709 < 3.10.2 3.10.2
  31. Critical · 9.8 CVE-2023-37466 < 3.10.0 3.10.0
  32. Critical · 9.8 CVE-2023-37903 <= 3.9.19 no fix
  33. Critical · 9.8 CVE-2023-32314 < 3.9.18 3.9.18
  34. Critical · 9.8 CVE-2023-30547 < 3.9.17 3.9.17
  35. Critical · 9.8 CVE-2023-29199 < 3.9.16 3.9.16
  36. Critical · 9.8 CVE-2023-29017 < 3.9.15 3.9.15
  37. Critical · 9.8 CVE-2022-25893 < 3.9.10 3.9.10
  38. Critical · 10.0 CVE-2022-36067 < 3.9.11 3.9.11
  39. High · 8.3 CVE-2019-10761 < 3.6.11 3.6.11
  40. Critical · 9.8 CVE-2021-23555 < 3.9.6 3.9.6
  41. Critical · 9.8 CVE-2021-23449 < 3.9.4 3.9.4

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.