Repository navigation
Commit 6880b04
fix(objectql): a read-only secret field keeps its stored value on update (#34620)
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:更新记录时,`readonlyWhen` 谓词为真而锁定的 `secret` 字段、以及静态 `readonly` 的
`secret` 字段,不再接受调用方写入;按 id
与按谓词(`multi`)两条更新路径都保持存储值,并像其它只读字段一样报告丢弃(`onFieldsDropped`、`X-ObjectStack-Dropped-Fields`、`strictReadonlyWrites`
拒绝)。
- 为什么改:规则是「调用方不可写的字段保持存储值,无论字段类型」,`secret` 字段同样适用。
- 风险与回滚:只涉及更新路径上两道只读剥离对 `secret` 字段的作者判定,以及 `sys_secret`
行只在语句仍引用它时写入;未锁定的 `secret` 照旧加密存为引用,hook 写入的值照旧保留。回滚即 revert 本 PR。
-
先看:`packages/objectql/src/engine-update-sealed-secrets.ts`(判定本身);`packages/objectql/src/engine-update.ts`
两个分支的调用点与两处
`persistSecretRows`;`packages/objectql/src/engine-update-locked-secret.test.ts`。
- 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run
src/engine-update-locked-secret.test.ts`,预期 12/12 通过。
- 需要你做的:无,席位落地。
## What changes
A field the caller may not write keeps its stored value, whatever its
type. This PR makes that hold for a `secret` field on both update paths,
by id and by predicate (`multi: true`):
- A `secret` field locked by a TRUE `readonlyWhen`, or declared static
`readonly`, takes no caller write: the stored reference is unchanged and
no `sys_secret` row is written for the value sent.
- The read-only strips report the field as they report any other:
`onFieldsDropped` (`readonly_when` / `readonly`), the REST
`droppedFields` body and `X-ObjectStack-Dropped-Fields` header, and the
`strictReadonlyWrites` refusal (`ERR_READONLY_FIELD_REJECTED`).
- New `packages/objectql/src/engine-update-sealed-secrets.ts`:
authorship of each `secret` key is read immediately before the
credential pass, and both strips (and the views they build) judge a
submission in which each caller-held key carries the reference that
stands for the caller's value. A sealed `sys_secret` row is written only
when the payload handed to the statement still names it.
- Unchanged: an unlocked `secret` is sealed and stored as a reference; a
value a `beforeUpdate` hook writes on a locked `secret` is the hook's
and is kept; hooks read `ctx.submitted` as before. As for every
`readonlyWhen` field, `isSystem` does not exempt a caller value on a
locked `secret`.
## Tests
- `packages/objectql/src/engine-update-locked-secret.test.ts` (new, 12
cases), by id and by predicate: a `readonlyWhen`-locked secret and a
static `readonly` secret keep their stored value and are reported;
`strictReadonlyWrites` refuses with `ERR_READONLY_FIELD_REJECTED` naming
both and writes nothing; `isSystem` does not exempt the `readonlyWhen`
lock; controls: an unlocked secret is sealed and stored as a reference,
a hook-written value on a locked secret is kept (alone, and over a
caller value).
- `packages/rest/src/rest-update-locked-secret.test.ts` (new, 2 cases):
`PATCH /data/:object/:id` on the locked secrets answers 200 with both
fields in `droppedFields` and the header, stored references unchanged;
control: an unlocked secret through the same door is sealed and stored
as a reference.
## Acceptance notes
- `Clause-②: no`. The declared contract already states the rule:
`packages/spec/src/data/field.zod.ts`, `readonly` — "server-enforced on
BOTH write paths: a non-system write to this field is silently dropped
from the payload on UPDATE and on INSERT ... symmetric with
`readonlyWhen`". No spec, schema, export or error code changes; no
published accept set or surface widens.
## Verification
Readings as of head `5abed35fbe` (the branch with `origin/main`
b019048 merged in). Readings not yet taken are named NOT MEASURED
with their reason; they follow to the seat, not into this body.
<details><summary>Reproduction on the base (temporary probe, not
committed)</summary>
Base `6c7d730f16`, non-system caller, by id and by predicate: 4 of 4
rule checks failed (2 locked secrets × 2 paths), 0 drops reported. Same
probe on head: NOT MEASURED (lock queue); the committed pins measure
head instead.
</details>
<details><summary>Engine pins</summary>
`pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2
src/engine-update-locked-secret.test.ts` on `8cedf9f52d` (before the
merge): 11 passed, 1 failed. The failure was the multi hook control's
own construction (its handler keyed on a value it rewrote, so the
matched rows' handlers wrote different keys and the engine refused the
write as designed); fixed in `3524713e38`. Re-run on the current head:
NOT MEASURED (shared verify lock held by a sibling's full dogfood run
for over an hour).
</details>
<details><summary>REST pin, package suites, typecheck</summary>
`packages/rest/src/rest-update-locked-secret.test.ts`, `pnpm --filter
@objectstack/objectql test`, `pnpm --filter @objectstack/rest test`,
both packages' `typecheck`: NOT MEASURED locally (same lock queue;
rest's test closure is 32 packages to build). CI's Test Core and
TypeScript Type Check run them on this PR.
</details>
<details><summary>Ablation</summary>
Planned one-shot: the authorship view in
`engine-update-sealed-secrets.ts` disabled, engine pins expected red on
the locked cases and green on the controls, then restored and proven by
blob hash. NOT MEASURED at open (lock queue); the reading goes to the
seat.
</details>
<details><summary>Gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` on `5abed35fbe`: 67 commands, each run, exit
captured before any pipe. 63 exit 0. Not passes:
- `check:dts-closure` exit 1: `packages/formula` and
`packages/metadata-core` dists were half-written by a build a container
restart killed; not from this diff. Re-run after the rebuild: NOT
MEASURED.
- `check:lean-entry-closure` exit 3, `check:dual-build-cjs-loads` exit
3: PREREQUISITE NOT MET (no built dist) — NOT MEASURED.
- `check:type-check-debt` exit 3: its closure build never got the lock
(99) — NOT MEASURED.
CI's Lint & Repo Gates and TypeScript Type Check carry all four.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYn5CmmdShCJifm6WYj)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 8bc0808 commit 6880b04
5 files changed
Lines changed: 640 additions & 11 deletions
File tree
- .changeset
- packages
- objectql/src
- rest/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
0 commit comments