Repository navigation
harden(js): lock call/apply/bind and wrapped intrinsics against own-property steering (#494) - #499
Merged
Merged
Conversation
…roperty steering (#494) Function.prototype.call/apply/bind were locked on Function.prototype (#450), but the held functions themselves still took an own `call` or a new prototype: `Function.prototype.apply.call = evil` hijacked every `apply.call(listener, ...)` in events.js, and `Array.prototype.push.call = evil` hijacked the callerN `fn.call(t, ...)` wrappers. node runs neither. lockIntrinsics() now makes call/apply/bind, and exactly the set of methods a primordials wrapper closes over, non-extensible. The set is recorded by the wrapper factories themselves, so a newly wrapped method is covered; a factory call after the lock (the loader's pristine-Buffer uncurryThis) locks on the spot. The wrappers keep `fn.call`: `call.call(fn, ...)` was measured slower than Reflect.apply on Linux JSC (new URL 2.64x). Deviation: the locked functions answer as under node --frozen-intrinsics (isExtensible false, own props and setPrototypeOf throw) but are not frozen. Pinned by cmd/lava/function_call_lock_test.odin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s not Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #494.
What changed
lockIntrinsics(internal/primordials.js) now makesFunction.prototype.call/apply/bindand every method a primordials wrapper holds non-extensible. The wrapper factories (caller0..3,callerN, souncurryThistoo) record their method withtrack(fn), so a newly wrapped method is covered without a hand list. A factory called after the lock (the loader'spristineBuffer) locks its method at once.fn.call. events.js keepsapply.call(listener, …), and its// primordials-ok: invokemarkers now give the reason: the receiver is the lockedFunction.prototype.apply.Before this PR,
Function.prototype.apply.call = evilhijackedEventEmitter.emit, andArray.prototype.push.call = evilhijacked the callerN wrappers (URLSearchParams threw). Node is unaffected by both.Deviation (§1, approved)
Measured on node 26.13. Lava now gives the same answers as
node --frozen-intrinsicsfor call/apply/bind and the wrapped set:isExtensibleis false;callthrows in both modes;definePropertywith a new key throws, and so doessetPrototypeOf.Unlike that flag, these functions are not frozen:
namestays configurable. Default node allows all of the above. Intrinsics no wrapper holds (e.g.Array.prototype.at) behave exactly as in node.Pinned by
main.function_call_lock, rows ext, keys, own-, new-key-, setproto, wrapped-ext, push-own/fresh-sloppy, at-own, emit-hijack, push-hijack.Rejected alternative
Routing calls through
call.call(fn, t, …)is slower thanReflect.apply, because JSC inlines onlyfn.call. Measured on Linux arm64:caller1alone: about 1 ns vs about 55 ns per call;new URL2.64x,URLSearchParams.get3.81x.Reuse verdict
No native code. The fix uses
Object.preventExtensionsand the existinglockIntrinsics.Tests
trackskips apply. Linux docker, clean clone,make test-mutation CHANGED=1: 50/50 died as recorded.finds for 72-events-parity are retargeted at the new marker text.Gates
--changedtests from open tooling: run-mutations --changed tests fail on a clean checkout; check-md scans .claude/worktrees #420.Bench
Linux arm64, JSC 2.52.6, master→branch, medians of 11 interleaved launches:
Startup (
lava eval 0, 31 interleaved runs per arm, 3 sessions): 0.992 / 1.001 / 0.999.Still open (filed separately)
structured_clone.jstoString.callandbuffer.jsu8Fill.call: intrinsics captured outside primordials..callreads.🤖 Generated with Claude Code