A cross-field `@@validate` rule is skipped on a partial `update()` — the ABSENT operand makes the comparison pass
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend
Research direction
The update validator is built at packages/orm/src/client/zod/factory.ts:2094-2097, where addCustomValidation is called without the present-field set; the comparison semantics are in packages/zod/src/utils.ts:429-437 (ABSENT sentinel) and :463-472 (evalBinary returns true on ABSENT). Read both sites and the create() path to see how present fields are supplied there, then choose between merging omitted row fields into the payload or rejecting an ABSENT comparison. Done when a model with @@validate(endDate > startDate) throws on update({ data: { endDate: earlier-than-startDate } }).
Written by the indexing model from the issue text.
Description
Hi,
I run independent, pre-registered verification of AI-built software (Trenyx; the published engagements are at https://trenyx.io/audits.html) and did a static-only read of zenstackhq/zenstack at commit 3f1ed725, the plan hashed and anchored before reading. The access-control side held everywhere I pushed on it, and I want that on the record first: policies are injected at one query-executor choke point regardless of the ORM call shape (nested writes, createMany/updateMany/upsert, connect, polymorphic base/sub joins all reduce to the same enforcement), the RPC and REST adapters take the auth context only from the server-side getter, and every user-supplied key is gated by z.strictObject before a Kysely node exists (packages/orm/src/client/zod/factory.ts:500 makeWhereSchema, one of 63 strictObject sites). Nothing here is a security report. This is one correctness seam in validation.
The gap: a model-level @@validate rule that references two or more fields is silently skipped on update() when the payload omits one of them.
- packages/orm/src/client/zod/factory.ts:2094-2097 builds the update validator by calling
ZodUtils.addCustomValidationwithout the present-field set, so the evaluator has no way to know which referenced fields are absent from the payload versus absent from the row. - packages/zod/src/utils.ts:429-437 defines the
ABSENTsentinel and :463-472 (evalBinary) returnstruefor any comparison in which an operand isABSENT. A rule likeendDate > startDatetherefore passes whenever the update touches only one of the two fields. - The consequence is that a partial update is never checked against the row's true post-update state: an
update({ data: { endDate } })that makesendDateearlier than the storedstartDateis accepted, while the same pair supplied together increate()is rejected. The validation attributes on single fields (@length,@email,@regex) are unaffected; this is specifically the cross-field case.
Suggested direction: on update(), either load the referenced fields that the payload omits and evaluate the rule on the merged value, or treat an ABSENT operand in a comparison as "cannot evaluate" and reject rather than pass, at least for rules that reference more than one field. One test would fence it: a model with @@validate(endDate > startDate), a row created with a valid pair, then update({ data: { endDate: <earlier than startDate> } }) expected to throw.
Happy to re-check whatever you ship. The pre-registration hash and the full record publish with the write-up, and if you ship a fix the write-up says so.
SK
Trenyx
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 157
- Avg merge
- 11h 42m
- Merged PRs (30d)
- 20
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from zenstackhq/zenstack
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
zenstackhq/zenstack#2873 ·
Maintainers usually reply within 1 day
-
runtime
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zenstackhq/zenstack#2868 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
zenstackhq/zenstack#2694 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
zenstackhq/zenstack#2659 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
zenstackhq/zenstack#2542 · 1 comment ·
Maintainers usually reply within 1 day
All issues in zenstackhq/zenstack