Repository navigation
Conversation
|
Important Review skippedThis review includes 2 billable files. This on-demand review is free during your promotion. Your included review limit has been reached. Run
⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
You can disable this status message by setting the Comment |
Status: superseded by #39588#39588 (dylan-conway) rewrites every Nothing here is needed once #39588 lands. The one thing this PR has that #39588 does not is that it applies to today's WebKit: #39588 depends on an unmerged WebKit change and currently has conflicts with What this PR found, for the record
Review writeups: JIT / strict-mode / symbol · the |
|
Updated 1:08 AM PT - Aug 19th, 2026
✅ @robobun, your commit 259483b0afc27fab27db7974da82fa1cc7bbdb42 passed in 🧪 To try this PR locally: bunx bun-pr 33486That installs a local version of the PR into your bun-33486 --bun |
There was a problem hiding this comment.
I didn't find any bugs, but this changes property-store semantics in NodeVMGlobalObject::put (JSC bindings) — worth a human look to confirm the mirroring gate and the value.isSymbol() → propertyName.isSymbol() swap don't regress anything the test matrix doesn't cover.
Extended reasoning...
Overview
This PR modifies NodeVMGlobalObject::put in src/jsc/bindings/NodeVM.cpp to change when a guest-side global assignment is mirrored onto the underlying JSC global object versus stored only on the sandbox. It replaces a dead slot.type() == NewProperty check with a real own-property lookup on the base global (via a qualified JSC::JSGlobalObject::getOwnPropertySlot call), adds an early-return that skips the mirror when the property isn't declared on the global, and swaps value.isSymbol() → propertyName.isSymbol(). Nine tests are added to test/js/node/vm/vm.test.ts.
Security risks
None apparent. node:vm is not a security boundary, and this change narrows (rather than widens) where writes land. The extra getOwnPropertySlot lookup runs against the base JSGlobalObject method table, not user-controllable traps.
Level of scrutiny
High. This is the C++ put hook for every global property write inside a contextified vm — a hot, semantics-defining path in the JSC integration. The change is well-reasoned and mirrors V8 contextify's PropertySetterCallback, and the PR description addresses inline-cache safety (ProhibitsPropertyCaching). But the interaction between the new early-return, PutPropertySlot state, strict-mode contextual stores, and var/function symbol-table bindings is subtle enough that someone familiar with this file should confirm the reasoning.
Other factors
The verification matrix and negative-contract tests are thorough, and the qualified-static-call idiom matches what defineOwnProperty in the same file already does. The value.isSymbol() → propertyName.isSymbol() fix is a real behavior change (symbol-keyed writes now bypass the sandbox entirely) that deserves an explicit sign-off. No CODEOWNERS cover this path and there are no prior review comments.
|
Good call on all three. Two of them weren't covered by the original matrix, so I went and closed the gaps; pushed as The mirroring gate under JIT warmupThe interesting one. A store site hot enough to warm its inline cache could in principle start writing a second copy onto the global behind the sandbox's back. It doesn't in bun, and asserting it turned up something worth recording: node has the original bug too, above an IC-warmup threshold. // 500 stores, each from a fresh script (no IC warmup on any one store site)
for (let i = 0; i < 500; i++) vm.runInContext(`globalThis.hot = ${i};`, box);
delete box.hot;
vm.runInContext("typeof hot", box); // node: undefined bun: undefined
// the same 500 stores, from one hot loop (one store site, IC warms up)
vm.runInContext(`for (let i = 0; i < 500; i++) globalThis.hot = i;`, box);
delete box.hot;
vm.runInContext("typeof hot", box); // node: number bun: undefinedNode flips at roughly 100 iterations, and it flips under Bun can't regress into this: Strict-mode contextual stores
For the record, The symbol swapIt's a real behavior change, and it's the behavior node has. Node checks the key, not the value: if (!is_declared && property->IsSymbol()) return Intercepted::kNo;Both halves of the swap were observable divergences: vm.runInContext("globalThis[Symbol.for('s')] = 1", box); // key is a symbol
typeof box[Symbol.for('s')] // node: undefined bun before: number bun after: undefined
vm.runInContext("globalThis.x = Symbol('q')", box); // value is a symbol
typeof box.x // node: symbol bun before: undefined bun after: symbolReads inside the context are unaffected either way, since Where that leaves the test file11 tests in the new block. 7 fail with Agreed that a human should sign off on the semantics; the |
|
Good catch on the sibling, though not for the reason given. Fixed in The stated repro doesn't reproducevm.runInContext("Object.defineProperty(globalThis,'a',{value:1,writable:true,enumerable:true,configurable:true});", box);
delete box.a;
vm.runInContext("typeof a", box); // node: undefined bun, before this PR: undefined
That also means the "poisoning" follow-on doesn't happen: nothing is seeded on the global, so (The But the structural point was right, and it is observableLeaning on that accidental suppression is exactly as fragile as it sounds. It breaks down the moment the global object has a binding of its own, because then vm.runInContext("var v = 1; Object.defineProperty(globalThis,'v',{value:2,writable:true,enumerable:true,configurable:true});", box);
// node v26.3.0: succeeds
// bun on main: TypeError: Attempting to change configurable attribute of unconfigurable propertyThe FixDefine on the sandbox and stop, matching V8's contextify Four tests added. One residual divergence, pre-existing and out of scopeFixing the TypeError exposes a layer underneath, which I want to flag rather than bury: vm.runInContext("var v = 1;", box);
box.v = 2; // host overwrites the sandbox's copy
vm.runInContext("v", box); // node: 2 bun: 1
vm.runInContext("globalThis.v", box); // node: 2 bun: 2JSC's Where the diff stands
15 tests in the new block, 8 of which fail with |
There was a problem hiding this comment.
Thanks — b33b5cc addresses the defineOwnProperty mirroring I flagged, with tests for the fresh-property, var-collision, builtin, and accessor cases. No further issues found, but since put and defineOwnProperty together now change where every global write in a contextified vm lands (and defineOwnProperty goes sandbox-only even for names already on the global), a human should confirm the semantics before merge.
Extended reasoning...
Overview
This PR changes two method-table overrides on NodeVMGlobalObject in src/jsc/bindings/NodeVM.cpp:
put(): replaces the always-falseslot.type() == NewPropertygate with a realJSC::JSGlobalObject::getOwnPropertySlotlookup, adds an early return so plain assignments to undeclared names stay sandbox-only, and fixesvalue.isSymbol()→propertyName.isSymbol().defineOwnProperty()(new commit b33b5cc, in response to my prior review): drops the fall-through toBase::defineOwnPropertyentirely; after the read-only+non-configurable guard, all defines go to the sandbox only. This is more aggressive than the fix I suggested (it never mirrors, even whenisDeclaredOnGlobalProxyis true), which the commit message justifies via thevar-collision case and Node v26'sPropertyDefinerCallbackreturningIntercepted::kYesunconditionally.
15 new tests in test/js/node/vm/vm.test.ts cover both paths, including negative-contract tests for var/function bindings, builtins, accessors, strict mode, and a JIT-warmup probe.
Security risks
node:vm is a soft sandbox but not a security boundary. The change moves where global writes land (sandbox vs JSC global), which affects isolation semantics between host and guest. No new unchecked casts, no new allocation, exception scopes look correct (RETURN_IF_EXCEPTION after the new getOwnPropertySlot call). I don't see auth/crypto/injection surface here.
Level of scrutiny
High. NodeVMGlobalObject::put runs on every global assignment inside every contextified vm, and defineOwnProperty on every Object.defineProperty(globalThis, ...) and any [[DefineOwnProperty]] path JSC routes there. The author (robobun) explicitly noted "a human should sign off on the semantics." The defineOwnProperty simplification also removes a getPropertySlot on the sandbox and the accessor-descriptor branch — worth a maintainer confirming JSC doesn't route hoisted var/function declarations through this hook in a way that now diverges.
Other factors
- My prior inline comment on
defineOwnPropertywas addressed by b33b5cc with 4 dedicated tests. - The bug-hunting system found no issues on the current revision.
- CI on the previous commit (3b65536) had an unrelated
cookie-map.test.tsfailure; CI status on b33b5cc is not yet visible in the timeline. - Test coverage is thorough (positive + negative-contract + JIT-tier probe), and the Node parallel test suite reportedly passes.
Checked, from both ends. JSC does not route them through
Confirmed empirically too: nothing appears on the sandbox at hoist time, in either engine. const box = {};
vm.createContext(box);
try { vm.runInContext("var b = (function(){ throw new Error('x') })();", box); } catch {}
Object.getOwnPropertyNames(box); // node: [] bun: []The sandbox copy of a
Deliberate, and it's what node does. Every case I could construct where the global already has the name agrees:
The CIBoth red lanes on
Not retriggering: the cookie failure is deterministic, so a re-roll can't clear it. This branch, latest commit: |
b33b5cc to
f5428f5
Compare
|
Checked against #39588 on a build of its branch: this still applies. The |
37e0a8d to
dae6431
Compare
NodeVMGlobalObject::put mirrored every guest assignment onto the JSC global object as well as the sandbox, so deleting the sandbox copy from the host left the global copy behind and the guest kept seeing the property. Only let the store fall through to the global object when the property is already declared there (a var/function binding, or a builtin), matching V8's contextify PropertySetterCallback. isDeclaredOnGlobalObject now does a real own-property lookup instead of reading slot.type(), which is Uncachable on entry and so never matched. Also check propertyName.isSymbol() rather than value.isSymbol(), mirroring node's `if (!is_declared && property->IsSymbol())`.
A store site hot enough to reach the JIT tiers must not start writing a second copy onto the context's global object: the inline caches are disabled for the contextified global, but assert it rather than assume it. The strict-mode branch reads isDeclared, which now accounts for bindings on the global object, so pin down that stores to a builtin, a declared var, and a host-provided property all still reach the sandbox.
NodeVMGlobalObject::defineOwnProperty defined the property on the sandbox and
then called Base::defineOwnProperty as well, the same mirroring put() did.
It only looked harmless because the mirror almost always no-ops: the global's
[[DefineOwnProperty]] re-reads the current descriptor through this class'
getOwnPropertySlot, which consults the sandbox first and finds the value that
was just written there, so validateAndApplyPropertyDescriptor sees an identical
descriptor and returns early.
That suppression breaks down when the global already has a binding of its own.
Redefining a `var` is rejected, because the global's symbol-table entry is
non-configurable and the guest asks for a configurable property:
var v = 1;
Object.defineProperty(globalThis, 'v', { value: 2, configurable: true });
// node: succeeds bun: TypeError
Define on the sandbox and stop there, matching V8's contextify
PropertyDefinerCallback. The accessor and already-on-the-sandbox branches did
exactly that already, so they collapse into the single remaining call.
dae6431 to
259483b
Compare
There was a problem hiding this comment.
I re-reviewed after the defineOwnProperty follow-up and the rebase onto current main; the automated pass found no bugs. My earlier concern about the sibling hook is addressed (and the collapsed tail subsumes #36709's PropertySlot fix, whose regression test still passes). Given this changes where every global write inside a contextified vm lands — and the open note about redoing part of it on top of #39588 once that merges — a human read on the semantics is still worthwhile.
What was reviewed:
put(): the new qualifiedJSGlobalObject::getOwnPropertySlotlookup replacing the never-trueslot.type() == NewPropertygate, and thepropertyName.isSymbol()fix — checked exception-scope placement and thatProhibitsPropertyCachingkeeps the early-return'sslot.base()from being IC'd.defineOwnProperty(): the collapsed sandbox-only tail — confirmed the removedisDeclaredOnSandboxprobe is what #36709 was guarding, so no reintroduced assert path.- Tests: 15 new cases cover the host-delete, hot-site, strict-mode, symbol, var/function, builtin-overwrite, and defineProperty variants; 8 fail-before verified per the description.
Extended reasoning...
Overview
The PR changes two method-table overrides on NodeVMGlobalObject in src/jsc/bindings/NodeVM.cpp (put and defineOwnProperty) so that guest-created globals in a node:vm context are stored only on the contextified sandbox object rather than mirrored onto the JSC global. This makes host-side delete sandbox.key actually remove the binding from the context, matching Node v26. Fifteen tests are added to test/js/node/vm/vm.test.ts, eight of which fail on the unfixed build.
Security risks
node:vm is not a security boundary, but the change does affect where writes land inside a contextified global. The direction of the change (fewer writes onto the real JSC global object, more confined to the sandbox) is if anything a reduction in cross-realm surface. No new user-controlled data reaches native APIs; the added lookup is a qualified static call into JSGlobalObject::getOwnPropertySlot on thisObject itself, guarded by RETURN_IF_EXCEPTION. I don't see auth/crypto/permissions implications.
Level of scrutiny
High. This is a semantic change to the storage model for every global assignment inside a vm context, implemented by editing JSC method-table hooks. The PR body itself documents subtle interactions (inline caches, ProhibitsPropertyCaching, symbol-table var bindings vs property cells, the accidental suppression in defineOwnProperty via validateAndApplyPropertyDescriptor) and lists three pre-existing divergences left for follow-up. The author's own status comment says it wants a human read, and there is an open note that once #39588 lands the remaining fix needs to be redone on top of its put. That is exactly the kind of design/merge-ordering call a maintainer should make.
Other factors
- My prior inline concern (the
defineOwnPropertysibling still mirroring) was investigated and addressed in a follow-up commit; the thread is resolved and covered by four of the new tests. - The rebase note explains the conflict with #36709 and that its regression test still passes on the merged result — I confirmed the removed sandbox probe is what that PR's separate
PropertySlotwas guarding, so the collapsed tail subsumes it. - Exception-scope hygiene looks correct: the throw scope was hoisted above the new
getOwnPropertySlotcall andRETURN_IF_EXCEPTIONfollows it; the removed code'sRETURN_IF_EXCEPTION/RELEASE_AND_RETURNpairs are replaced by a single tailRELEASE_AND_RETURN. - Test coverage is thorough (12-row behavior matrix vs Node v26.3.0, hot-site JIT test, strict-mode negative-contract tests, symbol key/value both directions, defineProperty over var/builtin/accessor). The 97
test-vm-*parallel tests also pass per the description. - Comment-cop threads were addressed (comments trimmed to one line each in 259483b).
|
The #39588 ordering question is resolved: it supersedes this PR rather than building on it. dylan confirmed on that thread that #39588 fixes this case with the same gate and added tests for it, and it also covers everything this PR listed as out of scope. Details in the status comment at the top. This PR stays open only as a possible stopgap, since #39588 depends on an unmerged WebKit change. Whether to land it in the meantime or close it is a maintainer's call; nothing further will be pushed here. |
|
Closing as stale: this PR conflicts with main, and its last commit is from 2026-08-19. The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR. |
Repro
A global the guest creates, and the host then deletes from the sandbox object, stays visible inside the context:
That breaks the common pattern of reusing one context and resetting it between runs by deleting the keys the guest added (
for (const k of Object.keys(box)) delete box[k]): under bun the guest keeps seeing every stale global from the previous run.Cause
Both of the method-table hooks that write a property onto a contextified global store it on the sandbox and mirror it onto the JSC global object. The host's
delete box.aremoves only the sandbox copy, so the global copy keeps answering lookups.V8's contextify callbacks report the operation handled, so the sandbox is the only store. The one exception is a property the global object already declares (a
var/function binding, a builtin), whose global copy does stay in sync.put— the gate that was supposed to decide this never fired:slot.type()isUncachableon entry toput, before anything has written through the slot, so this was alwaysfalseand the mirroring was unconditional.defineOwnProperty— mirrors too, and only looked harmless.JSObject::defineOwnNonIndexPropertyre-reads the current descriptor throughmethodTable()->getOwnPropertySlot, which consults the sandbox first and finds the value written one line earlier, sovalidateAndApplyPropertyDescriptorseescurrent.equalTo(descriptor)and returns early. The mirror was suppressed by accident, and the suppression breaks down as soon as the global has a binding of its own:The
varleaves a non-configurable symbol-table entry on the global; the guest asks forconfigurable: true.Fix
putcomputesisDeclaredOnGlobalObjectwith a real own-property lookup on the global object, bypassing this class' sandbox interception (the same qualified-static-call idiomdefineOwnPropertyalready used, and it sees symbol-tablevar/function bindings as well as regular properties). When the property isn't declared there, the sandbox is the only store, so a host-sidedeleteremoves it from the context too.defineOwnPropertydefines on the sandbox and stops. The accessor branch and the already-on-the-sandbox branch were doing exactly that already, so the tail collapses into the one remaining call. TheReadOnly && DontDeletebail stays; node returns "not intercepted" there too.putalso checkedvalue.isSymbol()where node checks the key:if (!is_declared && property->IsSymbol()). Fixed topropertyName.isSymbol(), which corrects two more divergences (a symbol-keyed assignment was landing on the sandbox, and a symbol value assigned to a string key was not).Verification
A behaviour matrix run against node v26.3.0 and bun, covering every direction the store can take.
bun bdoutput is now byte-identical to node on all twelve rows; before the fix, rows 1, 2, 3, 9 and 12 diverged.undefinednumberundefinedundefinednumberundefinedundefinednumberundefinedvar, host deletenumbernumbernumberfunctionfunctionfunctionObjectnumbernumbernumbertoStringfunctionfunctionfunction5|75|75|7undefined,numbernumber,numberundefined,number999ReferenceErrorReferenceErrorReferenceErrorundefined1undefinedFifteen tests added to
test/js/node/vm/vm.test.ts. Eight fail withsrc/jsc/bindings/NodeVM.cppreverted tomain; the other seven are negative-contract tests that must pass both ways (var/function bindings survive, builtin overwrites stay mirrored, sandbox accessors still fire, strict-mode stores still reach the sandbox, and the threedefinePropertycases that previously only worked by accident).Test runs
Rebase onto current main
Main gained twelve
node:vmcommits since this branch was cut. One conflicted: #36709 (322f3abf9d) fixed a debug assertion indefineOwnPropertyby giving the sandbox probe its ownPropertySlotinstead of reusing the one already filled by the global-object lookup. This PR deletes that probe entirely (the function now defines on the sandbox and stops), so the second lookup #36709 was guarding no longer exists and the fix is subsumed. Resolution: take this branch's collapsed version. #36709's regression test (Object.definePropertyon the context global when the sandbox is an uncacheable dictionary holding an accessor) still passes on the merged result, and the fail-before count is unchanged on the new base (8 of the 15 new tests fail withsrc/jsc/bindings/NodeVM.cppreverted tomain), so none of the intervening commits fixed this independently.Notes for review
Inline caches.
put's early return leavesslot.base()pointing at the sandbox rather than the global object, which is already the case on the pre-existing accessor early-return a few lines above. No inline cache can pick it up:NodeVMGlobalObject'sStructureFlagscarryProhibitsPropertyCaching, sotryCachePutBybails afterCommonSlowPaths::originalStructureBeforePutunwraps theJSGlobalProxyto the target, andtryCachePutToScopeGlobalbails independently onslot.base() != scope. A test hammers one assignment site 2000 times and then checks the sandbox is still the store.Still divergent from node, pre-existing and untouched:
globalThis[0] = 1lands on the global, not the sandbox).read_onlyearly-return in the setter is unimplemented.varcannot be shadowed by the sandbox for a free-variable read. JSC'screateGlobalVarBinding<Global>callsaddSymbolTableEntry, so avaris a scope slot rather than a property, andop_get_from_scoperesolves it toGlobalVarand reads the slot directly without consultinggetOwnPropertySlot. V8 uses a property cell, which its interceptor does see. So aftervar v = 1; box.v = 2,vreads1in bun and2in node, whileglobalThis.vreads2in both. Reachable onmainwith nodefinePropertyinvolved, and not fixable without changing how JSC creates global var bindings for contextified globals.--jitless), node itself leaves a stale copy on the global and exhibits the original bug. Bun is consistent at every iteration count.