Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

A cross-field `@@validate` rule is skipped on a partial `update()` — the ABSENT operand makes the comparison pass

Aperta
#2,833 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend

Direzione di ricerca

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 } }).

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.addCustomValidation without 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 ABSENT sentinel and :463-472 (evalBinary) returns true for any comparison in which an operand is ABSENT. A rule like endDate > startDate therefore 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 makes endDate earlier than the stored startDate is accepted, while the same pair supplied together in create() 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

Lingua principale
TypeScript
Stelle
2.9k
Fork
157
Merge medio
11h 42m
PR unite (30g)
20

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di zenstackhq/zenstack

Tutte le issue di zenstackhq/zenstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.