Repository navigation
fix: await a remote JSON schema before validating - #19438
pcbeingused333 wants to merge 1 commit into
Conversation
A jsonSchema config with only a uri stored the fetch Promise on the field and passed that Promise to zod, which accepts every value. Await the fetch and allow schema to be omitted so the documented remote config type-checks.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Fixes #19399
A JSON field configured with only a remote
jsonSchema(uriandfileMatch, no inlineschema) accepts every value.validateJSONSchemaassigned the result offetchSchemawithout awaiting it. Whenschemais omitted, that result is a Promise. Zod'sfromJSONSchematreats the Promise as an empty schema andsafeParsesucceeds for any value. The Promise was also written onto the field config, so the next validation saw a truthyschema, skipped the fetch, and kept accepting everything. The same missingawaitdropped a rejectedfetch(undefined)whenuriwas absent, so that misconfiguration saved the value too, with an unhandled rejection.fetchSchemais now awaited before the schema is compiled, and the resolved document is what gets cached on the field.JSONField['jsonSchema']['schema']is optional, so the documented remote config type-checks. An inline schema passed together withuriis still used as-is and does not callfetch. A missinguristill goes throughfetch; the rejection is returned as the validation message instead of being ignored.packages/payload/src/fields/validateJSONSchema.spec.tscovers the three cases. On main, the remote-uri case and the missing-uri case fail:{ a: "x" }is accepted, and the missing uri also surfaces an unhandledTypeError. With this change all three pass. The inline schema rejects a string where a number is required and does not fetch. The remote uri fetches once, rejects{ a: "x" }, accepts{ a: 1 }, and caches the schema object rather than a Promise. A failed fetch is reported instead of accepted.This change was prepared with the help of an AI assistant (Claude Code).