Skip to content

fix(v4): skip a record key that converts to __proto__ at the write - #6760

Merged
colinhacks merged 2 commits into
mainfrom
fix-record-key-coercion
Nov 16, 2026
Merged

colinhacks merged 2 commits into
mainfrom
fix-record-key-coercion

Conversation

@colinhacks

Copy link
Copy Markdown
Owner

A record's key schema can return an object, and the parser compared that object to "__proto__" before the assignment converted it to a string. A key whose toString() answered "__proto__" passed the guard and then replaced the parsed record's prototype. The key is now converted once, and both the guard and the write use the converted value.

The same check is fixed in the compiled record path and in zod/v3. The compiled exhaustive branch (z.record(z.enum([...]).transform(...))) had no check at all, so even a plain-string "__proto__" produced by a key transform got through there. The runtime already skipped it.

Bundle cost is about 20 B gzipped on a record fixture, classic or mini, and nothing for bundles that don't use records. Schema memory is unchanged.

A key schema can return an object. The record parser compared that object to "__proto__" and only then let the assignment convert it to a string, so a key whose toString answered "__proto__" replaced the output's prototype. The key is now converted once and the guard reads the converted value, in the runtime parser, the compiled record path (whose exhaustive branch had no check at all) and zod/v3.
Copilot AI balanced review requested due to automatic review settings November 16, 2026 01:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@colinhacks
colinhacks merged commit 90bf57b into main Nov 16, 2026
8 checks passed
@colinhacks
colinhacks deleted the fix-record-key-coercion branch November 16, 2026 02:19

This branch was successfully deployed

1 active deployment
Preview – zod-v4 — 7894e4eb Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants