zod
4.6.7 · 12 Oct 2026MIT468.6M / weekRepositoryHomepagenpmAtom feed
4.6.7 is the newest release of 4.x.
Summary· from the note as AI read it
Security fixUpgrade: this release fixes a security issue.
Before you upgrade
- Check tuple parse output; defaults now appear in parsed results
- Parsed tuples are now dense when optionals precede defaults; check array handlingTo check
- Check tuple length and z.function() argument error output
- Add .optional() to z.undefined() keys that may be absentTo check
- z.undefined() keys now required; add .optional() if key may be absent
- Check .catch/.partial/.default/.prefault combos with z.undefined() keys
- .merge() throws when receiver has refinements; use .extend()
- .merge() throws when receiver has refinements; use .extend()
Deprecated
- Prefer .extend() or .safeExtend() over .merge()
Security
- Upgrade to block __proto__ keys in object catchallTo check
- Upgrade to block __proto__ keys in object catchallTo check
- Upgrade to block __proto__ keys in object catchallTo check
New
- Codec inversion was added.
- Conditional
.superRefine()withwhen - The
whenoption was added for.superRefine(). Added in #5741, with related abort behavior fixed. - Reduced memory usage from lazy-bound methods
- Fixed in #5897. Classic builder methods are now lazy-bound through a shared internal prototype instead of eagerly attached per schema instance. This significantly reduces per-schema method allocation overhead, especially in codebases that construct many schemas. Detached methods continue to work:
In short
30 breaking3 security1 deprecated16 new9 faster58 fixed48 internal
- Breaking
Tuple defaults now materialize output values correctly
- BreakingTo check
When optional elements appear before later defaults, the parsed tuple is now dense so array operations behave predictably.
- Breaking
Tuple length errors are also more consistent now. Since
z.function()arguments are tuple-shaped, function input errors may look different. - BreakingTo check
Required object properties with
z.undefined() - Breaking
- Breaking
This also affects related
.catch(),.partial(),.default(), and.prefault()combinations that previously relied on missingz.undefined()keys being treated as optional. - Breaking
Safer
.merge()behavior with refinements - Breaking
Fixed in #5856. The
.merge()method now throws when the receiver has refinements, rather than silently producing ambiguous refinement behavior. Refinements from the second schema are preserved.
Security
1 advisory affects 4.4.0; 4.6.6 fixes them
- HighZod can exhaust memory while validating oversized constrained collectionsGHSA-mrhx-c7xc-m3w5 · 1 Oct 2026Fixed in 4.6.6
Release note
This is a minor release with a wide set of correctness and soundness fixes. Some fixes intentionally make Zod stricter, so code that depended on previously accepted invalid or ambiguous inputs may need small updates.
Potentially breaking bug fixes
Tuple defaults now materialize output values correctly
Fixed in #5661. Tuple parsing now more accurately reflects defaults, optional tails, explicit undefined, and under-filled inputs. The headline behavior is that defaults in tuple positions now properly appear in parsed output.
const schema = z.tuple([
z.string(),
z.string().default("fallback"),
]);
schema.parse(["a"]);
// ["a", "fallback"]Trailing optional elements that are absent still stay absent; they are not filled with undefined.
const schema = z.tuple([ z.string(), z.string().optional(), ]); schema.parse(["a"]); // ["a"]
But explicit undefined values supplied by the caller are preserved.
schema.parse(["a", undefined]); // ["a", undefined]
When optional elements appear before later defaults, the parsed tuple is now dense so array operations behave predictably.
const schema = z.tuple([
z.string(),
z.string().optional(),
z.string().default("fallback"),
]);
schema.parse(["a"]);
// ["a", undefined, "fallback"]Tuple length errors are also more consistent now. Since z.function() arguments are tuple-shaped, function input errors may look different.
Required object properties with z.undefined()
Fixed in #5661, with follow-up coverage in 57d80a82. A property whose schema is z.undefined() is now treated as required. The key must be present, but its value may be undefined.
const schema = z.object({
value: z.undefined(),
});
schema.safeParse({}).success;
// false
schema.safeParse({ value: undefined }).success;
// trueUse .optional() when the key itself may be absent.
const schema = z.object({
value: z.undefined().optional(),
});
schema.safeParse({}).success;
// trueThis also affects related .catch(), .partial(), .default(), and .prefault() combinations that previously relied on missing z.undefined() keys being treated as optional.
Safer .merge() behavior with refinements
Fixed in #5856. The .merge() method now throws when the receiver has refinements, rather than silently producing ambiguous refinement behavior. Refinements from the second schema are preserved.
const a = z.object({ a: z.string() }).refine((val) => val.a.length > 0);
const b = z.object({ b: z.string() });
a.merge(b);
// throwsPrefer
.extend()or.safeExtend()for object composition. The.merge()method is still supported for compatibility, but it is discouraged for new code because its semantics around overlapping keys and refinements are easier to misread.
JSON Schema $defs entries no longer include redundant id
Fixed in #5759. JSON Schema conversion through z.toJSONSchema() now strips redundant id fields from $defs entries. This is required for correctness in older JSON Schema dialects from before $id was introduced: in those dialects, id changes the resolution scope, so leaving it inside an extracted definition can make references resolve incorrectly. The removed value was redundant because the schema had already been extracted into $defs, so the definition key itself is the identifier. This may affect consumers that were reading those internal id fields directly.
Other JSON Schema fixes in this release:
- Breaking
Draft-04/OpenAPI 3.0 min/max intersections
- Breaking
Recursive lazy schemas with
.describe() - Breaking
Falsy prefault values emitted as defaults
- Breaking
CUID pattern output tightened
String validators are stricter
Base64 validation now rejects whitespace instead of allowing atob()-style whitespace stripping. Fixed in #5888.
z.base64().safeParse("Zm9v").success;
// true
z.base64().safeParse("Zm 9v").success;
// falseOther string validator changes:
- Breaking
CUID validation through
z.cuid()has been tightened, and CUID v1 is now deprecated. Fixed in #5880. - Breaking
HTTP URL validation through
z.httpUrl()now rejects malformed HTTP(S) URLs with a missing slash after the protocol. The underlyingURLconstructor normalizes inputs likehttps:/example.com, but Zod now rejects them instead of accepting the repaired URL. Fixed in #5672, related to #5284.
z.httpUrl().safeParse("https://example.com").success;
// true
z.httpUrl().safeParse("https:/example.com").success;
// false
z.httpUrl().safeParse("http:/www.apple.com").success;
// falseUnion paths are fixed in formatted errors
Two union-related error fixes landed:
Nested union paths are now preserved correctly in the output of
z.treeifyError()andz.formatError(). Fixed in #5708 and60ff3987.Invalid discriminated union errors now include discriminator options and improved messages. Fixed in #5723. This may affect users snapshotting
ZodErroroutput.
Other fixes
Record key transforms now run
Fixed in #5891. Record schemas now run transforms on record keys.
const schema = z.record(
z.string().transform((key) => key.toUpperCase()),
z.number()
);
schema.parse({ foo: 1 });
// { FOO: 1 }Related record fixes:
Key refinement failures now surface as structured
invalid_keyissues. Fixed in #5719.Non-enumerable properties are skipped more consistently. Fixed in #5719.
The v3-style single-argument
z.record(valueType)form works again. Fixed in0e960108.
Metadata and input handling in fromJSONSchema()
Schema generation from JSON Schema now applies metadata more consistently across enum, const, not, anyOf, and multi-type schemas. Fixed in #5758. It also rejects or normalizes more non-JSON-like inputs, including cyclic objects and BigInt. Fixed in 87cf0f93.
Codecs
Codec changes:
Encoding through
z.discriminatedUnion().encode()now works when the discriminator uses a codec. Fixed in #5769.Codec inversion was added in #5770.
const stringToNumber = z.codec(
z.string(),
z.number(),
{
decode: Number,
encode: String,
}
);
const numberToString = z.invertCodec(stringToNumber);Transform context
Transform callbacks now support ctx.addIssue(). Fixed in #5699.
Conditional .superRefine() with when
The when option was added for .superRefine(). Added in #5741, with related abort behavior fixed in #5681.
Defaults for Map and Set
Defaults for Map and Set are now cloned instead of shared across parses. Fixed in #5855.
const schema = z.map(z.string(), z.number()).default(new Map()); const a = schema.parse(undefined); const b = schema.parse(undefined); a === b; // false
Empty unions
Empty z.union(), z.xor(), and discriminated unions no longer crash at construction time. They construct and fail at parse time. Fixed in #5869.
Floating-point multiples
Number multipleOf() / step() validation is more accurate for decimal and exponent edge cases. Fixed in #5687 and #5793.
Global config and jitless
Configuration fixes:
Global configuration is now shared through
globalThis, improving behavior across mixed CJS/ESM module instances. Fixed in #5889.Jitless mode now avoids eval probing when set before first access. Fixed in #5864.
Prototype pollution hardening
Object catchall paths now skip __proto__ keys. Fixed in #5898.
Performance improvements
Reduced memory usage from lazy-bound methods
Fixed in #5897. Classic builder methods are now lazy-bound through a shared internal prototype instead of eagerly attached per schema instance. This significantly reduces per-schema method allocation overhead, especially in codebases that construct many schemas. Detached methods continue to work:
const schema = z.string(); const optional = schema.optional; optional.call(schema); // still works
Improved tree-shaking
Implemented in 195e8696 and #5689. Top-level factory calls are annotated as pure, and generated stub package manifests now include sideEffects: false. This gives bundlers more room to remove unused Zod code.
This is intended as the conclusive fix for a long-standing class of tree-shaking and bundle-size issues, especially in Next.js and Turbopack projects. The most visible symptom was that unused validators and locales could survive bundling even when importing from zod/mini or from a narrow subpath.
Related reports include:
Next.js and Turbopack tree-shaking reports
Locale and
zod/minibundle-size reportsBroader v4 bundle-size reports
{
"sideEffects": false
}Locales
Added or updated locale support:
Croatian
Greek
Romanian
Uzbek map support
Georgian translation fix
French issue origin translations
Italian validation message updates
Locale message text changed in some cases, which may affect snapshots.
Closed issues
The following issues were closed by PRs included in this release:
Closed #5466 via #5632: preserve context immutability in parse functions.
Closed #5617 via #5655: correct Georgian translation for
string.Closed #5229 via #5661: align object and tuple optionality handling.
Closed #5680 via #5681: respect
abort: truein.refine()checks withwhen.Closed #5678 via #5699: add missing
addIssueto transform context.Closed #5714 via #5719: skip non-enumerable properties in record validation.
Closed #5670 via #5723: add discriminator
optionsto invalid discriminator errors.- Security
Closed #5743 via #5744: increase timeout for the datetime ReDoS checker test.
Closed #5732 via #5758: apply description and default metadata in
fromJSONSchema().Closed #5731 via #5759: strip redundant
idfrom$defsentries in JSON Schema output.Closed #5605 via #5763: update
z.custom()docs for v4 compatibility.Closed #5593 via #5769: support
discriminatedUnion().encode()with codec discriminators.Closed #5792 via #5793: correct floating-point
multipleOf()validation.Closed #5777 via #5797: resolve recursive lazy JSON Schema stack overflow.
Closed #5842 via #5856: align
.merge()refinement semantics with.extend().Closed #4461 and #5414 via #5864: honor
jitlessconfig in the eval probe.Closed #5296 via #5891: apply key schema transforms in
z.record().Closed #5824 via #5893: emit falsy prefault values in JSON Schema output.
Commits
Commit
44f6a03efix(locales): correct Georgian translation for 'string' to 'ველი'Commit
7b43bc64docs(ecosystem): add Hono TakibiCommit
119376b9feat: add map support to Uzbek localeCommit
8fbf701etest: add edge case tests for boundary valuesCommit
f1f93c2bFix order of brand method examples in api.mdxCommit
2d367139feat: add hr translationCommit
54902cb7chore: update pullfrog.yml workflowCommit
89ba70f2chore: add sideEffects false to stub package.json for tree-shakingCommit
eaa3c2c3Update positive checks to use alias.gt(0)in the docsCommit
5b574501fix: respectabort: truein.refine()for checks withwhenfunctionCommit
539de140docs: fix README links for async refinements/transformsCommit
46cd10e7docs: fix README anchor links for async APIsCommit
55747b3cRemove deprecated downlevelIteration optionCommit
3a818de1fix(v4): handle multi-digit exponents in floatSafeRemainderCommit
3cd45ebcfix(v4): add strict validation tohttpUrl()Commit
7d98c909add Sanity as silver sponsor and Mintlify as bronze sponsorCommit
c7805073move Sanity and Mintlify to top of sponsor listsCommit
bee2dc8ddocs: movez.iso.time()from format to pattern sectionCommit
2f8414bcfix: add missing addIssue to transform contextCommit
d3c0ec87docs: add note about removed.errorsalias in v4 changelogCommit
fa338a3bfix(v4): JSON schema min/max intersection for draft-04 and openapi-3.0Commit
3473b288chore: bump zshy to ^0.7.1Commit
f5336717feat: add json-up to ecosystemCommit
60ff3987fix(v4): preserve parent path when treeifying nested union/key/element issuesCommit
08b14b51perf: avoiddeleteinfinalizeIssueto keep V8 fast modeCommit
9cf868d2fix(v4): treeify error nested union bugCommit
28f39a6dAdd JSONType exportCommit
65fab33efeat: allowwhenparameter in.superRefine()Commit
7f87df1erefactor(v4): remove unnecessary type assertionsCommit
518f15ddPreprocess is not deprecatedCommit
2e5b23dcfix: add options to invalid discriminator errorsCommit
7f789deffix: skip non-enumerable properties in record validationCommit
ee15fa19docs: add AGENTS notes for JSDoc, PR comments, and PR worktree workflow- Security
Commit
ddb41391test: increase timeout for redos checker in datetime.test.ts Commit
bc07e459docs: fix docCommit
e06af5deUpdate Hey API descriptionCommit
28c156e2fix: apply description and default metadata to enum, const, and not schemas in fromJSONSchemaCommit
f457edf1Fix grammar in CONTRIBUTING.mdCommit
411f6c64fix(v4): resolve stack overflow in toJSONSchema for recursive lazy with describeCommit
45dd421edocs: add tone guidelines for issue and PR comments to AGENTS.mdCommit
ddd20a30test: align optional property assertions with actual inferred typesCommit
a1cf8a93docs: update z.custom example for v4 compatibilityCommit
b6a3b336fix: strip redundant id from$defsentries in toJSONSchemaCommit
c7a8ccc0fix: discriminatedUnion encode() with codec discriminatorCommit
87cf0f93fix(fromJSONSchema): normalize input via JSON round-tripCommit
7163e6f2feat: add.invert()method to ZodCodecCommit
b59b9b13fix: replace.defaultwith.prefaultCommit
93bba686docs: add Zod AOT to ecosystem pageCommit
2564caa4fix(docs): add custom 404 page with proper theme supportCommit
5b7ed214fix: correct multipleOf float validation using tolerance-based comparisonCommit
cc9139d2docs: fix self-referencing schema in refine when() exampleCommit
0e960108fix(v4): support v3-style single-arg z.record(valueType)Commit
41b25af9docs(agents): refine PR comment tone guidanceCommit
4c03c20dUpdate Italian locale error messages for validationCommit
37ac1ba0fix(fr): translate issue.origin in too_big/too_small errorsCommit
345be203docs: add validex to ecosystemCommit
3c1f32bdfeat(locales/en): handle instanceof and add comprehensive locale testsCommit
888e52bbfeat(locales): add Greek (el) localeCommit
bf6d99edRevert "feat(locales/en): handle instanceof and add comprehensive locale tests"Commit
e8196a8dfix(resolution): align expected fr message with translated localeCommit
b6b12882correct logic for validating lengthCommit
34f60159fix(v4): clone Map and Set in shallowClone to prevent shared state across.default()parsesCommit
91a7d0d1fix(v4): reject whitespace in z.base64() to close atob bypassCommit
23edf484Revert "fix(v4): reject whitespace in z.base64() to close atob bypass"Commit
15cafa13fix(v4): throw on.merge()receiver with refinements; preserve refinements from second schemaCommit
584b1089fix(v4): reject whitespace in z.base64() to close atob bypassCommit
b9b62c65fix(core): honourjitlessconfig inallowsEvalprobeCommit
fffe99bdfix(v4): construct empty unions instead of crashingCommit
285bde7ffeat(core): shareglobalConfigacross module systems viaglobalThisCommit
195e8696perf(v4): mark top-level factory calls as/*@__PURE__*/for tree-shakingCommit
61d7bedbfix(v4): apply key schema transforms in z.record()Commit
45acd2adci(release): switch to npm trusted publishing via OIDC- Deprecated
Commit
476ae243Tighten cuid() regex and deprecate CUID v1 Commit
6217527edocs(agents): document push-to-main footgun and version-bump ruleCommit
757f0b0ffix(v4): apply util.Writeable<T> in strictObject/looseObject for shape display parityCommit
fa4a3740fix(v4): apply util.Writeable in mini object constructors and extend/safeExtend/partial/requiredCommit
ebc8287cfix(v4): emit falsy prefault values in toJSONSchemaCommit
8fcb71a5perf(v4): lazy-bind builder methods to shared internal prototypeCommit
76e8f706fix(v4): skip__proto__key in object catchallCommit
f0b0608eecosystem:eslint-plugin-zod-xiseslint-plugin-zodnowCommit
0b5c3bc2docs: fix refinements examples in api.mdxCommit
327e152edocs(agents): refine PR comment tone guidance furtherCommit
57d80a82test(v4): pin object/tuple key optionality through optout propagationCommit
f19860f1fix: preserve context immutability in parse functionsCommit
ec979ad7feat: add Romanian (ro) localeCommit
b6066b3efix(v4): align object and tuple optionality handlingCommit
ad0b8271ci: update release workflow for trusted publishingCommit
6db607befix(release): keep JSR manifest publishableCommit
f778e02abuild: bump zshy for JSR wildcard exports
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.