test: pin draft prototype-inspection behavior restored by #1271#1
Closed
jonatankruszewski wants to merge 1 commit into
Closed
test: pin draft prototype-inspection behavior restored by #1271#1jonatankruszewski wants to merge 1 commit into
jonatankruszewski wants to merge 1 commit into
Conversation
Drafts must stay safe for ecosystem introspection idioms: lodash's isPrototype (used by isEmpty/isEqual/isPlainObject) reads value.constructor.prototype, and fast-deep-equal compares constructor identity. The guard reverted in immerjs#1271 broke these (immerjs#1265, immerjs#1266, immerjs#1268) while its tests still passed, because try/catch made a crash and a successful block indistinguishable. These tests assert observable behavior directly, so they fail on 11.1.9-11.1.11 (verified: constructor.prototype throws, constructor identity and 'in' checks break, writes to own keys named prototype are dropped) and pass on main. setPrototypeOf remains forbidden; the applyPatches-layer pollution guards in patch.js are untouched.
jonatankruszewski
force-pushed
the
prototype-inspection-tests
branch
from
July 20, 2026 18:23
bb29947 to
9b0fc4e
Compare
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.
Note
Self-review PR — diff preview before opening against
immerjs:main.Follow-up to immerjs#1271, as offered in immerjs#1269.
The revert restored draft behavior that ecosystem libraries depend on, but that behavior is currently untested — the produce-side tests from immerjs#1259 were removed along with the guard, and the remaining pollution tests all live at the
applyPatcheslayer. This PR adds test-only coverage (no source changes) that pins the restored contract:draft.constructoris the real constructor (Object/Array/the class), with stable identity across drafts — thefast-deep-equalregression from Regression when comparing equality usingfast-deep-equalimmerjs/immer#1266draft.constructor.prototypeis readable and real — thelodash.isEmpty/isEqualcrashes from TypeError: 'get' on proxy: property 'prototype' is a read-only and non-configurable data property on the proxy target immerjs/immer#1265 and lodash.isEmpty() on a draft throws "TypeError: 'get' on proxy: property 'prototype'..." since 11.1.9 immerjs/immer#1268, exercised via lodash'sisPrototypeidiom replicated inline (no new devDependency)'constructor' in draftand own data keys namedconstructor/prototyperound-trip__proto__reads resolve to the real prototypeObject.setPrototypeOf(draft, …)still throws — the restrictive half of the contract is pinned tooThe tests assert observable behavior directly rather than wrapping attacks in
try/catch, so a crash and a successful defense are distinguishable. Verified: they fail on 11.1.9–11.1.11 (constructor.prototypethrows, constructor identity andinbreak, writes to an own key namedprototypeare dropped) and pass onmain.If a convincing case for hardening comes up later, these tests define what any future guard must preserve. The
applyPatches-layer guards inpatch.jsare untouched.Full suite: 3689 passed, 8 skipped (pre-existing).