Sanitize host error carriers reaching the sandbox
fix(GHSA-m283-3h24-438v): sanitize host error carriers reaching the sandbox
Sanitize host error carriers reaching the sandbox7e3faa-fix-sanitize-host-error-carriers-reaching-the-cve-2026-47686fixsanitize host error carriers reaching sandbox
Committed by patriksimek-bot
commit message
fix(GHSA-m283-3h24-438v): sanitize host error carriers reaching the sandbox
Root cause: handleException recursively sanitized SuppressedError.{error,
suppressed} and AggregateError.errors[] but never inspected Error.cause
(ES2022). When an embedder-exposed host function threw with
`{ cause: process }`, sandbox code caught the error and pivoted straight
through `e.cause.mainModule.require('child_process')` to host RCE.
docs/ATTACKS.md Defense Invariant #3 already claimed .cause was covered; the
implementation did not match the claim.
Four distinct channels were found and closed, each a superset of the last.
1. `.cause` on host-wrapped carriers is stripped with a sealed descriptor
(configurable: false, writable: false). ECMA-262 §10.5.6 forces an
invariant throw on a lying defineProperty trap and §10.5.8 forces a sealed
get trap to return the locked value, so neither a Proxy that reports
success without mutating nor an accessor returning undefined on the first
read and a host object on the second can survive. Strip failure falls
through to substituting a fresh sandbox-realm Error.
2. SuppressedError / AggregateError carriers are snapshot-and-rebuilt: the
sub-errors are read once, sanitized, and packaged into a fresh
sandbox-realm carrier, and the original is dropped. This closes the same
accessor TOCTOU on .error / .suppressed / .errors[], where a read-then-
assign silently no-ops against a getter-only accessor.
3. sanitizeHostOwnProps generalizes that from spec-defined slots to every own
key of a host-wrapped carrier: each is sealed to its captured primitive,
or to undefined when non-primitive. message, stack, name, code, errno,
syscall and path survive automatically without an allowlist, while
arbitrary carriers such as `e.detail = process` or
`e.originalError = require('child_process')` are neutralized.
4. Prototype-inherited references are out of reach of own-key enumeration
entirely, because Reflect.ownKeys does not report inherited properties:
const e = new Error('x');
Object.setPrototypeOf(e, { leak: process });
throw e; // sandbox: e.leak is a live bridge proxy
Confirmed on the pre-fix tree: sandbox read host `process.pid` and
`process.env.HOME`, and completed
`e.leak.mainModule.require('child_process').execSync(...)` for full RCE.
Widening the enumeration to walk the chain is not a fix -- the chain is
attacker-shaped, arbitrarily deep, and every link may itself be a lying
Proxy, so the walk is another TOCTOU surface. Instead the carrier is
rebuilt: sanitizeHostOwnProps constructs a fresh sandbox-realm error and
copies across only the primitive own properties it has already sealed. The
host prototype chain is discarded wholesale, so the returned object is
structurally incapable of referencing the host realm.
Two details of the rebuild are load-bearing:
The six standard error constructors are captured at module load beside
LocalError, for the same reason localStringStartsWith is captured for
GHSA-m5q2-4fm3-vfqp. The rebuild runs at exception-handling time, long
after guest code has run; reading the mutable sandbox globals there would
let `RangeError = function () { ... }` from inside the sandbox execute
attacker code inside the sanitizer and choose its return value. Covered by
a regression test that hijacks the global and asserts it is never invoked.
The subclass is resolved from the carrier's `name` string rather than
instanceof. A host-wrapped carrier's chain reaches the *host*
RangeError.prototype, never the sandbox's, so instanceof against a sandbox
constructor is false for every host error and the subclass would collapse
to plain Error. Matching is prefix-based because Node <= 11 reports
internal errors as "RangeError [ERR_INVALID_OPT_VALUE]" -- an exact
comparison silently degraded every Node-internal error to plain Error
there, which the Node 8-26 sweep caught via the GHSA-248r async-generator
test asserting `e.constructor === RangeError`.
Subclass fidelity improves as a side effect: `e instanceof TypeError` and
`e instanceof RangeError` now hold for host-thrown errors, where previously
the carrier's prototype chain was host-realm.
Node < 15 fix found by the sweep: handleException carried two copies of the
short-circuit
`if (localSuppressedErrorProto === null && localAggregateErrorProto === null) return e;`,
both predating own-property sanitization. On any runtime without
AggregateError they returned before sanitizeHostOwnProps ran, so channel 3
stayed fully exploitable on Node 8/10/12/14 while the tests passed on 16+.
One copy was removed during conflict resolution; the other now guards only
the prototype walk, so the walk is still skipped when neither intrinsic
exists but execution always falls through to the sanitizer.
Conflict resolution, lib/setup-sandbox.js handleException: this work deletes
the first copy of that short-circuit, while GHSA-cfcw-xp6x-25gj adds an
isForeignSeveredHostValue refusal immediately above it. Both intents are
preserved -- the cfcw guard is kept and the early return stays deleted, with
a comment recording why.
docs/ATTACKS.md: this work also claimed Category 36, already taken by
GHSA-v836 (36) and GHSA-cfcw (37); renumbered to 38 with its header,
cross-references, and anchors updated, and its Mitigation and Detection Rules
extended with the prototype-inherited channel and the rebuild.
Tests: test/ghsa/GHSA-m283-3h24-438v/repro.js. For the rebuild specifically,
14 cases -- canonical PoC, RCE pivot, two-level chain, prototype accessor,
symbol key, inherited host function, inherited `constructor` pivot, the
constructor-hijack regression, subclass identity, diagnostic preservation,
plus four red-team regressions (spoofed `isProxy: false`, lying-Proxy carrier
hiding its own keys, and inherited leaks nested inside AggregateError and
cause sub-errors). 9 of the 10 security assertions fail against the
own-key-only fix; the tenth is a compat check.
Red team: 11 attack vectors run against the rebuild -- isProxy spoofing,
throwing isProxy accessor, lying-Proxy carrier, Symbol.toPrimitive on name,
sandbox-polluted Error.prototype, 50-deep prototype chain, non-primitive own
name, AggregateError and cause sub-error nesting, prototype getters, and
Object.prototype.valueOf pivot. No leaks.
Full suite green on Node 8/10/12/14/16/18/20/22/24/25/26.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>Editor assessment
This commit patches CVE-2026-47686. The body is almost a design document: it identifies Error.cause as the unsanitized carrier, closes four channels with sealed descriptors, snapshot-and-rebuild of SuppressedError and AggregateError, generalized own-key sealing, and wholesale prototype-chain discard, and explains why walking the chain is another TOCTOU surface. It also records the load-bearing detail of capturing constructors at module load and resolving subclasses by name, plus the Node older-than-15 short-circuit fix. That depth is admirable but sprawling, running to many paragraphs and a full test matrix. The GHSA-as-scope header caps a message that would otherwise be near-exemplary.