Harden ObjectWrapper iterator helpers against foreign and revoked receivers#2681
Merged
Merged
Conversation
lahma
force-pushed
the
proxy-wrapper-iterator-hardening
branch
from
July 13, 2026 22:14
6eb1363 to
876f9a3
Compare
…eivers
The static Iterator and GetLength helpers installed on wrapped CLR objects
(Symbol.iterator and the length accessor getter) hard-cast thisObject to
ObjectWrapper. Two crash modes were reachable from script:
1. Foreign receiver: extracting the function and re-targeting it
(var f = clrList[Symbol.iterator]; f.call({}) or
Object.getOwnPropertyDescriptor(clrList, 'length').get.call({}))
threw an uncaught InvalidCastException out of the engine.
2. Revoked proxy receiver: extracting the function through a live
Proxy.revocable wrapper, revoking, then calling with the revoked proxy
as this recursed with the nulled proxy target; the null passed the
reference cast and crashed with NullReferenceException on first member
access.
Both helpers now resolve their receiver through UnwrapReceiver, which
unwraps (nested) proxy chains with a loop, throws a JS TypeError
"Cannot perform '...' on a proxy that has been revoked" for revoked
proxies (realm taken from the proxy), and a JS TypeError
"Method '...' called on incompatible receiver" for non-wrapper receivers
(realm taken from the receiving ObjectInstance when available, falling
back to Throw.TypeErrorNoEngine for primitive receivers which the
interpreter materializes as a TypeError). Valid receivers - wrapper,
proxy-over-wrapper, proxy-over-proxy-over-wrapper - behave as before.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EsHuKuE4UihKZp5HYapDHE
lahma
force-pushed
the
proxy-wrapper-iterator-hardening
branch
from
July 13, 2026 22:31
876f9a3 to
e2e1058
Compare
This was referenced Jul 15, 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.
Two engine-crash modes in the
ObjectWrapperinterop helpers, both reachable from script:this— theSymbol.iteratorClrFunction and thelengthgetter are script-extractable (Object.getOwnPropertyDescriptor(clrList, 'length').get.call({})), and both hard-cast(ObjectWrapper) thisObject→ uncaughtInvalidCastException.NullReferenceExceptionon first member access.Both helpers now share an
UnwrapReceiverthat unwraps nested proxy chains iteratively, throwsTypeError: Cannot perform '[Symbol.iterator]' on a proxy that has been revokedfor revoked proxies (V8 wording), andTypeError: Method '…' called on incompatible receiverfor foreign receivers — including primitivethis, where no engine is reachable and the deferred-realm TypeError path is used (verified catchable andinstanceof TypeErrorfrom script).for...ofdirectly over a revoked proxy still throws from the proxy's own[[Get]]guard first, matching node — covered by test. Regression tests confirm iteration over single and nested proxies wrapping CLR lists still works.6 new tests; full Jint.Tests, PublicInterface, and test262
~Proxygreen.🤖 Generated with Claude Code
https://claude.ai/code/session_01EsHuKuE4UihKZp5HYapDHE