Repository navigation
Commit d5f3bc5
fix(core): lower modifyAllRecords in the managed write clamp where the write guard refuses edit or delete (#30474)
domain:server#3 · os-bill · session_01Utp6CZUqByp4kJMhCQDWZ2
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgJHeo7w1wp7HQ5HRJRCx6FL)_
Fixes #30440
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 改了什么:受管对象(better-auth / engine-owned /
append-only)的权限视图里,显式的「修改全部记录」在写守卫拒绝编辑或删除时被降为「查看全部记录」,并保留对象仍开放的动作;未开放编辑的对象上「转移」也一并清掉(超级管理员之前在这些对象上被告知可以转移)。
- 为什么改:之前只要权限集写了 modifyAllRecords,`current_user.can()`
和控制台按钮就说可以编辑、删除、转移,但写守卫实际一律拒绝。
- 风险与回滚:只改服务端返回的能力答案,不改任何写入的放行与拒绝;回滚即还原本 PR 的单个函数。
- 先看:`packages/core/src/security/effective-object-permissions.ts` 的
`clampManagedObjectWrites` 与新 helper
`lowerModifyAllRecords`;`packages/plugins/plugin-security/src/get-effective-object-permissions.test.ts`
一致性表的 `CLAMPED` 与新行;测试块 `[#30440]`。
- 两分钟验证:`pnpm --filter @objectstack/core exec vitest run
src/security/effective-object-permissions.test.ts`,预期 55 个全绿。
- 需要你做的:无,席位落地。
## What changes
`clampManagedObjectWrites`
(`packages/core/src/security/effective-object-permissions.ts`) cleared
`allowEdit` / `allowCreate` / `allowDelete` on an object in a guarded
`managedBy` bucket that does not opt the verb in through `userActions`,
but never touched `modifyAllRecords`, which the spec's
`objectPermissionGrants` reads as edit, delete and transfer on its own.
A permission set naming such an object with `{ modifyAllRecords: true }`
therefore answered `current_user.can(object, 'edit' | 'delete' |
'transfer')` true while the write guard refused every one of those
writes.
- New private helper `lowerModifyAllRecords(acc, kept)`: when the entry
carries `modifyAllRecords: true` and a layer refuses at least one of
edit / delete / transfer, the bit becomes `false`, `viewAllRecords`
becomes `true` (the read it implies, so read is unchanged), and each
verb `kept` names is carried over as its plain `allow*` bit.
- `clampManagedObjectWrites` calls it with `{ allowEdit: edit,
allowDelete: delete, allowTransfer: edit }` from the object's
`userActions` opt-ins.
- **Claim amendment 6658639729 (seat):** `clampManagedObjectWrites` also
clears a plain `allowTransfer` on a guarded object that does not opt
`edit` in. The super-user wildcard fold copies the transfer bit
`modifyAllRecords` grants onto every entry it covers, so the shipped
platform admin was served `can(object, 'transfer')` true on every such
object while the guard refused the update. Measured on `c5800818`: an
engine-owned object opting nothing in, wildcard `{ allowRead,
viewAllRecords, modifyAllRecords }`, map entry `allowTransfer: true`,
and `assertEngineOwnedWriteAllowed(…, 'update', user)` throws
`PermissionDeniedError`. After the fix the same probe answers transfer
`false`.
- **Same amendment, the agreement table** in
`packages/plugins/plugin-security/src/get-effective-object-permissions.test.ts`
(can() over the served map vs
`PermissionEvaluator.checkObjectPermission`, which does not model the
guard): its `CLAMPED` set, the cells it forgives in the refuse direction
on a guarded object, gains `allowTransfer`, and it gains a row `[#30440]
explicit modifyAllRecords entries on guarded managed objects`
(`sys_user` opting edit in, `sys_member` opting nothing in, private
`sys_secret`).
- `clampExternalReadOnlyWrites` (#30370, PR #30416) now goes through the
same helper with nothing kept; its behaviour is byte-identical (its
existing tests are unchanged and green).
**The partial opt-in choice (dispatch scope item 2).**
`objectPermissionGrants` answers edit as `read && (allowEdit ||
modifyAll)`, delete as `read && (allowDelete || modifyAll)` and transfer
as `allowTransfer || modifyAll`, so a `false` beside `modifyAllRecords`
takes nothing away: an entry cannot keep `modifyAllRecords` and refuse
only delete. So:
| object opts in | `modifyAllRecords` | served `can()` |
|:--|:--|:--|
| nothing (`sys_automation_run`, `http_delivery`) | lowered to
`viewAllRecords` | read only |
| `edit` only (`sys_user`, `sys_organization`, `sys_api_key`) | lowered;
`allowEdit` + `allowTransfer` kept | read, edit, transfer; no delete |
| `edit` and `delete` | kept | unchanged |
Transfer follows `edit` because an owner change is an update: the
engine-owned guard maps it to the `edit` affordance, and #30416's
external clamp already treats it the same way. What is lost when the bit
is lowered on an `edit`-only object is record-level "all records" scope
for edit, which only the server evaluator reads (unchanged here); the
served map's consumers read the object-level verbs (`current_user.can`,
`MePermissionsProvider`'s transfer check), and those keep edit and
transfer.
## Tests
New block `[#30440] a guarded managed object grants no verb its write
guard refuses, modifyAllRecords included` in
`packages/core/src/security/effective-object-permissions.test.ts` (the
existing harness file for this map), through
`buildEffectiveObjectPermissions` and the spec's real
`objectPermissionGrants`:
- explicit `{ modifyAllRecords: true }` on an engine-owned object opting
nothing in: no edit / delete / transfer, same read;
- the same on a `sys_user`-shaped object (edit opted in): edit and
transfer kept, delete gone;
- an object opting edit and delete in keeps `modifyAllRecords`;
- CONTROL: the same entry on an unguarded object keeps every verb
`modifyAllRecords` grants;
- a plain `allowTransfer` on an object not opting edit in answers no
transfer; on `sys_user` (edit opted in) it stays;
- CONTROL: the super-user wildcard fold answers exactly as on `main` on
every object except the folded transfer bit on the object opting nothing
in, which now reads `false` (the fold copies granted bits, never
`modifyAllRecords`).
plugin-security's agreement table: one new row (above) and
`allowTransfer` in `CLAMPED`; 68/68.
## Acceptance notes
- The `allowTransfer` half was first handed back as out of scope (first
commit `47fe789a` cleared it and red 13 rows of the agreement table;
`5dd16ba3` took it out); the seat chose to take it here and amended the
claim (6658639729); `04b5cbbe` puts it back with the table change.
- Observation, not filed: on the same measurement `apiOperations` for
the engine-owned object lists `create` / `update` / `delete`. That
annotation reads `enable.apiMethods` exposure, a different layer from
the guard; noted only.
## Verification
<details><summary>Measured on main first (c580081), probe deleted after
use</summary>
```
PROBE map probe_engine_owned = {"modifyAllRecords":true,"allowEdit":false,"allowCreate":false,"allowDelete":false,…} · can: allowRead=true allowCreate=false allowEdit=true allowDelete=true allowTransfer=true
PROBE map sys_user_like = {"modifyAllRecords":true,"allowCreate":false,"allowDelete":false,…} · can: allowRead=true allowCreate=false allowEdit=true allowDelete=true allowTransfer=true
PROBE guard probe_engine_owned update: REFUSED PermissionDeniedError [Security] Access denied: 'probe_engine_owned' is engine-owned (managedBy:'engine-owned', …
PROBE guard probe_engine_owned delete: REFUSED PermissionDeniedError …
```
The same probe after the fix: `probe_engine_owned` can
edit/delete/transfer = false/false/false, read true; `sys_user_like`
edit/delete/transfer = true/false/true; the unguarded control unchanged.
</details>
<details><summary>Tests and ablation</summary>
- `pnpm --filter @objectstack/core test`: Test Files 134 passed, Tests
3001 passed (lock VERDICT command-exit 0); `pnpm --filter
@objectstack/plugin-security typecheck` exit 0.
- `pnpm --filter @objectstack/core typecheck`: exit 0, test layer OK.
- Downstream readers of the map, run against the rebuilt core:
plugin-hono-server `current-user-endpoints-effective-objects.test.ts` +
`fold-wildcard-superuser.test.ts` 20/20; plugin-security
`get-effective-object-permissions.test.ts` 68/68.
- Ablation (`scripts/ablation-replace.mjs --delete` of the
`lowerModifyAllRecords(…)` call in `clampManagedObjectWrites`; anchor 1
→ 0 on disk; the test imports the source module relatively, so no
`dist/` leg): on `5dd16ba3`, 2 failed / 52 passed, the two
explicit-`modifyAllRecords` cases; restored blob equals HEAD, `git diff
HEAD` empty.
- Ablation 2 on `04b5cbbe` (`--delete` of `if (!edit) acc.allowTransfer
= false;`, core rebuilt, `ablation-dist-preflight --absent` confirmed
the marker gone from all 14 dist files): core file 2 failed / 53 passed
(the plain-transfer case and the wildcard CONTROL); the agreement table
stays 68/68, as expected: without the clear the map is broader, the
evaluator agrees, and the table only flags the refuse direction.
Restored blob equals HEAD; core rebuilt, preflight finds the marker back
in `dist/index.js` and `dist/index.cjs`.
- Ablation 3 on `04b5cbbe` (the table's `CLAMPED` back to create / edit
/ delete): 14 failed / 54 passed, the 13 super-user rows on
`sys_member.transfer` / `sys_secret.transfer` plus the new `[#30440]`
row; restored blob equals HEAD.
</details>
<details><summary>Derived gate families on head 04b5cbb: 62 derived, 62
run exit 0</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 62 commands from the 4 changed paths
(146 changed lines); each was run on `04b5cbbe` and its exit code
recorded before any pipe; `--ran` reconciles: "62 derived famil(ies)
accounted for, 62 run, 0 NOT-MEASURED". The amendment's test file added
`check-tenant-audit-census` (+ `--self-test`), `check:i18n` and
`check:i18n-stale-fill`.
- `pnpm check:dual-build-cjs-loads` (NOT MEASURED on `5dd16ba3`) now
exit 0: 116 require entry points across 71 packages load.
- `node scripts/check-plugin-teardown-shape.mjs --self-test` exit 0 (48
cases) after `git fetch origin 621a487`
on the shallow clone.
- Also run on `5dd16ba3`: `pnpm --filter @objectstack/spec
check:liveness` exit 0 (no spec path in the diff).
- Not in the local set, left to CI: the type-check lanes, Build Core,
Test Core shards, and the repo-wide scans.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZUqByp4kJMhCQDWZ2)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent c23eafa commit d5f3bc5
4 files changed
Lines changed: 137 additions & 9 deletions
File tree
- .changeset
- packages
- core/src/security
- plugins/plugin-security/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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
558 | 625 | | |
559 | 626 | | |
560 | 627 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
242 | 254 | | |
243 | 255 | | |
244 | 256 | | |
| |||
249 | 261 | | |
250 | 262 | | |
251 | 263 | | |
252 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
253 | 267 | | |
254 | 268 | | |
255 | 269 | | |
256 | 270 | | |
257 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
258 | 274 | | |
259 | 275 | | |
260 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
261 | 300 | | |
262 | 301 | | |
263 | 302 | | |
| |||
551 | 590 | | |
552 | 591 | | |
553 | 592 | | |
554 | | - | |
| 593 | + | |
555 | 594 | | |
556 | 595 | | |
557 | 596 | | |
| |||
563 | 602 | | |
564 | 603 | | |
565 | 604 | | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
| 605 | + | |
570 | 606 | | |
571 | 607 | | |
572 | 608 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
357 | | - | |
| 357 | + | |
| 358 | + | |
358 | 359 | | |
359 | 360 | | |
360 | 361 | | |
| |||
473 | 474 | | |
474 | 475 | | |
475 | 476 | | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
476 | 486 | | |
477 | 487 | | |
478 | 488 | | |
| |||
484 | 494 | | |
485 | 495 | | |
486 | 496 | | |
487 | | - | |
| 497 | + | |
488 | 498 | | |
489 | 499 | | |
490 | 500 | | |
| |||
0 commit comments