Repository navigation
feat(security): read the recycle bin's grants for restore and purge (#30237 PR 4) - #31438
Conversation
…r restore and purge (wip) The evaluator maps restore to allowRestoreOwnDeleted and purge to manageRecycleBin; plugin-security's write-class sites read rlsOperationForVerb; the engine refuses a caller the tenant wall denies, scopes the bin's removals by the recorded verdict, and restores another caller's entry only for a recycle-bin manager. Claude-Session: https://claude.ai/code/session_01FEkQ5nYzXijPZzrM68FB5J Co-authored-by: Claude <noreply@anthropic.com>
…o liveness rows go live ObjectPermissionVerbTarget gains allowRestoreOwnDeleted and manageRecycleBin, and objectPermissionGrants answers them as Q5 = A rules: each is bounded by read, modifyAllRecords implies both, manageRecycleBin implies allowRestoreOwnDeleted, and allowDelete implies neither. The [PLANNED] describes and docblock now say what reads the keys, and the two liveness rows cite the evaluator mapping and the engine's own-entry check. Spec consent: 6718336940. Co-Authored-By: Claude <noreply@anthropic.com>
… check and the tenant wall on purge/empty/restore The evaluator's restore/purge cells (named, exhaustive over the bits the bin keys read, and a present/absent sweep over all ten bits), the own-entry check (another member's entry refused without manageRecycleBin, with a throwing resolver, and with no resolver), and the deny verdict on purge, empty and restore, engine and recorded. The old fail-closed pins of the unmapped verbs are rewritten for the mapping. verify's write observer sees purge and restore; the grants cache keeps its three write verbs. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…; core pins the bin keys on a super-user wildcard Regenerated by check:generated --fix (gen:docs, gen:liveness-counts). Co-Authored-By: Claude <noreply@anthropic.com>
… elevation reads Rows 29d (recycleBinWallDenies) and 29e (assertCallerMayRestoreEntry); the site register regenerated by check-system-context-census --write. Co-Authored-By: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 7 package(s): 35 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 10 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 182 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 23e7487366c828a5040bf62fb348e81d2c20442e && git checkout 23e7487366c828a5040bf62fb348e81d2c20442e
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 7d0b47ca19c8c41563964b3889ae81e8e015788e 95d2a17f6e585d9503a4ac3e7ca1626683ea27d7 && git checkout -B drift-repro 7d0b47ca19c8c41563964b3889ae81e8e015788e && git merge --no-ff 95d2a17f6e585d9503a4ac3e7ca1626683ea27d7
node scripts/docs-audit/affected-docs.mjs --json 7d0b47ca19c8c41563964b3889ae81e8e015788e
|
|
domain:server#3 · os-project-manager · session_01FEkQ5pXkgNXVpCn2GZDjyy Contract reviewServed-tier: Inputs read: card #30237 body and all 32 comments (one page); PR #31438 body and file list (29 files, +775/-229); the net diff ① Derived judgmentsThe hits file, against consent 6718336940 and Q5 = A.
One fold (#18785). Right. The evaluator asks
The mapping and the plugin-security sites the hand-over lists.
Security, tried along the brief's lines.
Landing condition (PR 2 review should-fix 1). Closed as asked. The two object-level dispatches carry Check-runs on the head (read 2026-11-08 08:00Z): 42 check-runs; 13 success (Auto Label, Check Changeset, Check Documentation Links, Check PR Size, Dogfood Regression Gate, Flag docs affected, Governed Surface Queue Guard, Lint · PM dispatch-gates, Lint · scoped · tooling self-tests, PR-body guards, Plan Test Core shards, Spec property liveness, filter), 7 skipped, 22 in progress (Build Core, Build Docs, Build UI Deps, Lint · CI/release/engine gates, Lint · ESLint, Lint · docs & code guards, Lint · repo & tooling gates, two scoped Lints, Live E2E UI, Test Core 1-8, Type Check × 4). Every in-progress family is NOT MEASURED by this record, ② Semver levelConfirmed. ③ Boundary flags
④ Design judgment
Implementing files in the diff, each against the contract it implements.
No must-fix. Two should-fixes (the retirement prose in the hits file and its liveness twins; explain-engine's raw Implemented-by: VERDICT: PASS |
… write gate and in explain Review round 1 of the recycle-bin permission reader. The sharing middleware gated by-id writes on update/delete only, so a by-id purge (the permanent delete) reached no canDelete once purge became grantable; it now picks the gate by the write class (rlsOperationForVerb), and passes the bin's own id-less, AST-less restore/purge dispatches through untouched. The mapping moves to @objectstack/core so plugin-security and plugin-sharing read one definition. security/explain picks the gate, the deferral verb and the fault sentence by the same class. The permissions matrix and the ObjectQL security page no longer say restore/purge do not exist; the changeset names the skills follow-up and the sharing change. Co-Authored-By: Claude <noreply@anthropic.com>
…cycle bin's grants The tombstones and their accept set are unchanged. Their refusal text, the bare restore/purge guidance and the docblock no longer say the operations were never shipped and that the keys return with M2: the operations exist with the recycle bin (ADR-0148), and their grants are spelled allowRestoreOwnDeleted and manageRecycleBin. The "Delete the key" sentence stays its own sentence, so the residue lint's fix line is unchanged. The lint rule's explanation drops the same claim. References regenerated. Consent: 6720657486. Co-Authored-By: Claude <noreply@anthropic.com>
|
domain:server#3 · os-project-manager · session_01FEkQ5pXkgNXVpCn2GZDjyy Contract reviewServed-tier: This is the delta review of record 6719122724 (PASS on ① Derived judgmentsSF1 closed — the hits file, inside consent 6720657486.
SF2 closed — explain reads the write class as the door does.
The seat's added item — plugin-sharing's write gate (
Lint and hand-written docs.
Check-runs on the head (read 2026-11-08 12:03Z): 66 check-runs; 27 success (Auto Label, Build Docs, Build UI Deps, Check Changeset ×2, Check Documentation Links, Check PR Size, Dogfood Regression Gate, Flag docs affected, Governed Surface Queue Guard, Lint & Repo Gates, Lint · CI/release/engine gates, Lint · ESLint, Lint · PM dispatch-gates, Lint · docs & code guards, Lint · repo & tooling gates, three scoped Lints, Live E2E UI, PR-body guards ×2, Plan Test Core shards, Spec property liveness, Type Check · debt ledger, Type Check · source gates, filter); 10 skipped; 29 in progress (Build & E2E UI, Build Core, Test Core 1-8, Test UI 1-16, Type Check UI, Type Check · consumer gates, Type Check · workspace). Every in-progress family is NOT MEASURED by this record — the new plugin-sharing / plugin-security / spec / lint tests, the workspace typecheck of the core export and of the ② Semver levelConfirmed. ③ Boundary flags
④ Design judgment
Implementing files in the delta, each against the contract it implements:
Findings — no must-fix, no should-fix; three nits, none moving the head:
Implemented-by: VERDICT: PASS |
|
domain:server#3 · os-project-manager · session_01FEkQ5pXkgNXVpCn2GZDjyy 席位意见:ACCEPT · Head-sha 席位核对
|
domain:server#3 · os-project-manager · session_01FEkQ5pXkgNXVpCn2GZDjyy
Body: seat refresh (round 2) · 2026-11-08T12:15Z
Requested by Leehom · project thread
Part of #30237
Clause-②: yes (widening)
Metadata-protocol: none
Skills-docs: follow-up #30847
Spec consent: 6718336940 (
permission.zod.tsObjectPermissionVerbTarget+objectPermissionGrantsQ5 cells + describes/docblock;liveness/permission.jsontwo rows planned→live) and 6720657486 (theallowRestore/allowPurgetombstone prescriptions and therestore/purgeguidance strings name the recycle bin's grants). Reviews: 6719122724 (round 1), 6721290796 (delta, head 95d2a17). PR 4 of 5 (hand-over 6690307585): the recycle-bin permission reader. PR 5 (REST doors) follows after this merges.维护者速读
restore读allowRestoreOwnDeleted,purge(清除单条、清空、永久删除)读manageRecycleBin;普通成员只能恢复自己删除的记录,恢复别人删的需要manageRecycleBin;被组织墙拒绝的调用者看不到任何回收站条目。共享层与 explain 按写入类别判定生命周期动词:按 id 的永久删除(purge)问canDelete,无删除权限的调用者得 403(仅有编辑共享不够),security/explain也按删除门报告purge。purge便能到达共享层,故共享门与 explain 必须按删除类判定(评审 6719122724 SF1/SF2)。modifyAllRecords的人获得 restore/purge;allowDelete不蕴含任何一项(Q5 = A)。无解析器或解析器抛错时,恢复他人条目一律拒绝(fail closed)。共享层对按 id 的purge是收紧方向(与普通 delete 同门)。回滚即 revert,无数据迁移。packages/objectql/src/recycle-bin/restore.ts(assertCallerMayRestoreEntry,自有条目检查);packages/objectql/src/recycle-bin/purge.ts(recycleBinWallDenies与recordedVerdict);packages/plugins/plugin-sharing/src/sharing-plugin.ts(按写入类别选门);packages/core/src/security/lifecycle-verb-rls-operation.ts(rlsOperationForVerb/LIFECYCLE_VERB_RLS_OPERATION移入 core 并导出,plugin-security 与 plugin-sharing 共用);packages/spec/src/security/permission.zod.ts(objectPermissionGrants两个新单元与墓碑文案)。pnpm --filter @objectstack/objectql exec vitest run src/recycle-bin/restore.test.ts src/recycle-bin/purge.test.ts与pnpm --filter @objectstack/plugin-sharing exec vitest run src/lifecycle-verb-write-gate.test.ts,预期全部通过,含「another member's entry … 403」「tenant wall」与「refuses FORBIDDEN when the row is not the caller's to delete」。What changes
The mapping (plugin-security).
OPERATION_TO_PERMISSIONgainsrestore → allowRestoreOwnDeletedandpurge → manageRecycleBin, spelled fromRECYCLE_BIN_GRANT_KEYS. The evaluator answers both through the one fold (objectPermissionGrants, #18785);DESTRUCTIVE_OPERATIONSstays as the backstop for any future unmapped destructive verb.MODIFY_ALL_WRITE_KEYSnow derives both keys, andcrudBucketForOperationfolds restore →update, purge →delete. The system context is unchanged.The fold (spec, under consent 6718336940).
objectPermissionGrantsanswers the two keys as Q5 = A: each bounded by read;modifyAllRecordsimplies both;manageRecycleBinimpliesallowRestoreOwnDeleted;allowDeleteimplies neither.OBJECT_PERMISSION_VERBSandcan()are unchanged. Core'sGRANT_BITSadds the two keys, so/me/permissionsreports them.The write-class map moves to core.
LIFECYCLE_VERB_RLS_OPERATION/rlsOperationForVerb(transfer / restore → update, purge → delete) are now declared inpackages/core/src/security/lifecycle-verb-rls-operation.tsand exported from@objectstack/core; plugin-security's module re-exports them, so its importers are unchanged and plugin-sharing reads the same map.Every write-class site reads
rlsOperationForVerb:rls-compiler.tsmapOperationToRLS,security-plugin-rls-filter.ts,security-plugin-addressed-writes.ts,security-plugin-cbp-write-gate.ts,platform-ownership-policies.ts. The authz middleware's epoch bump listspurgeandrestorebeside the other writes.The sharing write gate judges the write class (review SF1, plugin-sharing).
buildSharingMiddlewarepicks its gate byrlsOperationForVerb(op): a by-idpurge(the permanent delete) is askedadmitsByIdWrite(object, id, 'delete', …), exactly as an ordinary delete is, so a caller without delete authority on the row is refused403 FORBIDDEN; an edit share no longer suffices. A bulkpurgeis scoped bybuildWriteFilter(object, ctx, 'delete'). The recycle bin's own doors (restore(entryId),purge(entryId),empty(object)) dispatch with no id and no AST: they address no live row, so the gate passes them on untouched.security/explainreports by the write class (review SF2, plugin-security).explain-engine.tsderiveswriteClass = rlsOperationForVerb(engineOp)and uses it for the record's sharing gate, the authored-deferral verb, the queue guard and the fault sentence:purgeis explained againstcanDeleteRecord, nevercanEditRecord, so explain no longer reports an edit share as admitting a purge the door refuses.The engine's own-entry check (
restore.ts). After therestoredispatch clears the evaluator,assertCallerMayRestoreEntryrefuses403 PERMISSION_DENIEDwhen the entry'sdeleted_byis not the caller'suserId, unless the caller's effective permissions (the registered_effectiveObjectPermissionsResolver) grantmanageRecycleBinon the entry's object. No resolver, or a resolver that throws → refused.attributedUserIdis not consulted (attribution only). No new engine member: therestore()/purge()/empty()host literals gain closures over existing state (amendment 6718183894).The tenant wall on the bin (should-fix 1,
purge.ts).recycleBinWallDeniesanswersdenyfor a caller the Layer-0 verdict denies:restore→null,purge→false,empty→0, before anything is read. Thepurgeandemptyexecutors re-check againstopCtx.tenantLayer0Verdictand pass{ recordedVerdict }to the driver, so the removal is scoped by the verdict the security layer recorded.restore's executor makes the same check.The retired keys' prose (spec + lint, under consent 6720657486). The
allowRestore/allowPurgetombstone prescriptions, and therestore/purgeguidance strings, now say the key granted nothing when it was retired and name the recycle bin's grants (allowRestoreOwnDeleted,manageRecycleBin, ADR-0148) instead of promising the bit back with M2; "Delete the key." stays its own sentence, so the lint'sretiredKeyRemedyhint is unchanged.packages/lint/src/rule-explanations.tssays the same. References regenerated.verify / core.
observeWrites(packages/verify/src/handle.ts) now seespurgeandrestore.resolve-user-grants-cache.tsWRITE_OPERATIONSstays insert/update/delete: the bin never takes a platform object, and every object that cache watches is asys_object (comment added).Docs.
content/docs/permissions/system-context.mdxrows 29d/29e own the two new elevation reads (check:system-context-census).permissions/permissions-matrix.mdx(lifecycle callout) andprotocol/objectql/security.mdx(the two flag rows and the retired note) now describe the live keys. References and liveness counts regenerated bycheck:generated --fix.Tests
permission-evaluator.test.ts: named Q5 cells; exhaustive 3-state sweep over the six bits the bin keys read (729 × 2); a present/absent sweep over all ten bits × eight verbs (no bit widens another verb); cross-set read half.security-plugin.test.ts: the old fail-closed pins of the unmapped verbs are rewritten: the object gate answersrestore/purgefrom their keys and reads no row.restore.test.ts: another member's entry refused with no resolver, withallowRestoreOwnDeletedonly, withallowDeleteonly, with manage-without-read, with manage on another object, and with a throwing resolver; allowed withmanageRecycleBinormodifyAllRecords; own entry asks no resolver; wall deny →null; recorded deny →null.purge.test.ts: wall deny →false/0with no dispatch; recorded deny →false/0; recordedorganizationverdict scopes the removal (cross-tenant purge throughrecordedVerdict); system exempt.plugin-sharing/src/lifecycle-verb-write-gate.test.ts(new): a by-idpurgeis askeddeleteand refusedFORBIDDENwhen the row is not the caller's to delete, passed when admitted; a bulkpurgeis scoped by the delete filter; the bin's ownrestore/purgedispatches pass untouched with nothing asked; the ordinary by-id delete stays on the same gate.plugin-security/src/explain-lifecycle-verb-sharing-gate.test.ts(new):purgeanddeleteaskcanDeleteRecord, notcanEditRecord, and report the row not writable;updateaskscanEditRecord(control).permission.test.ts(spec): the fold cells; the retirement pins name ADR-0148 andmanageRecycleBin, not M2.validate-retired-permission-residue.test.ts(lint): the new explanation.effective-object-permissions.test.ts(core): the super-user wildcard shape.Ablations (21, each red, each restored to HEAD by scripts/ablation-replace.mjs)
Mutations by
scripts/ablation-replace.mjs(anchor must hit once; restore proven blob == HEAD). A* runrestore.test.ts+purge.test.ts, B*permission-evaluator.test.ts+security-plugin.test.ts, C* specpermission.test.ts, D1–D2 plugin-sharinglifecycle-verb-write-gate.test.ts, D3 plugin-securityexplain-lifecycle-verb-sharing-gate.test.ts.A1-not-manager-refusal: Tests 4 failed | 84 passed; restored=1; e.g. "refuses another member's entry for allowRestoreOwnDeleted only, 403"A2-no-resolver-refusal: Tests 1 failed | 87 passed; restored=1; e.g. "refuses another member's entry, 403, when no permission resolver answers: it fails closed"A3b: Tests 1 failed | 41 passed; restored=1; e.g. "refuses, 403, when the resolver throws: it fails closed"A4-own-entry-check-call: Tests 6 failed | 82 passed; restored=1; e.g. "refuses another member's entry, 403, when no permission resolver answers: it fails closed"A5-engine-wall-deny: Tests 3 failed | 85 passed; restored=1; e.g. "purge answers false for a caller the wall denies, before reading or dispatching anything"A6-recorded-deny: Tests 3 failed | 85 passed; restored=1; e.g. "purge answers false, and removes nothing, when the security layer recorded a deny verdict on the dispatch"A7-purge-recorded-scope: Tests 1 failed | 87 passed; restored=1; e.g. "purge's removal is scoped by the recorded verdict: an organization it does not name keeps its entry"A8-empty-recorded-scope: Tests 1 failed | 87 passed; restored=1; e.g. "empty's removal is scoped by the recorded verdict, not by the caller's own organization"A9-restore-executor-wall: Tests 1 failed | 87 passed; restored=1; e.g. "answers null when the security layer recorded a deny verdict on the dispatch"A10-purge-pre-read-wall: Tests 1 failed | 87 passed; restored=1; e.g. "purge answers false for a caller the wall denies, before reading or dispatching anything"A11-empty-pre-wall: Tests 1 failed | 87 passed; restored=1; e.g. "empty answers 0 for a caller the wall denies, and removes no organization's entries"A12-restore-pre-wall: Tests 1 failed | 87 passed; restored=1; e.g. "answers null for a caller the tenant wall denies (no active organization), and leaves the entry"B1-restore-map-row: Tests 9 failed | 260 passed; restored=1; e.g. "the Modify-All write-bypass CLASS is exactly what this file derives from its own dispatch map"B2-purge-map-row: Tests 9 failed | 260 passed; restored=1; e.g. "the Modify-All write-bypass CLASS is exactly what this file derives from its own dispatch map"B3-purge-maps-to-restore-key: Tests 5 failed | 264 passed; restored=1; e.g. "the Modify-All write-bypass CLASS is exactly what this file derives from its own dispatch map"C1-spec-manage-reads-delete: Tests 1 failed | 121 passed; restored=1; e.g. "[engine: snapshot deletes into the recycle bin, restore under original ids, purge, and the TTL reap (#3146 slice 3) #30237 Q5 = A] folds the recycle-bin keys: bounded by read; manage implies restoring your own; modifyAll impl"C2-spec-restore-unbounded: Tests 1 failed | 121 passed; restored=1; e.g. "[engine: snapshot deletes into the recycle bin, restore under original ids, purge, and the TTL reap (#3146 slice 3) #30237 Q5 = A] folds the recycle-bin keys: bounded by read; manage implies restoring your own; modifyAll impl"C3-spec-manage-no-own-restore: Tests 1 failed | 121 passed; restored=1; e.g. "[engine: snapshot deletes into the recycle bin, restore under original ids, purge, and the TTL reap (#3146 slice 3) #30237 Q5 = A] folds the recycle-bin keys: bounded by read; manage implies restoring your own; modifyAll impl"D1-sharing-write-class: Tests 3 failed | 3 passed; restored=1; e.g. "askscanDelete(verbdelete) of a by-idpurge, and refuses FORBIDDEN when the row is not the c"D2-sharing-bin-door-skip: Tests 2 failed | 4 passed; restored=1; e.g. "passes the recycle bin's own restore(entryId) dispatch on untouched: no id, no AST, nothing asked"D3-explain-write-class: Tests 1 failed | 2 passed; restored=1; e.g. "purge asks canDeleteRecord, not canEditRecord, and reports the row not writable"Acceptance notes
purge(entryId)pre-dispatch entry read cannot carry the recorded verdict: it runs before the dispatch, so it is scoped by the engine's own verdict (which grants no exemption). The removal itself carriesrecordedVerdict.opCtx.tenantLayer0Verdictonly on AST operations, so for the AST-lessrestore/purgedispatches it is normally absent today and the engine verdict decides. The recorded-verdict path is exercised by a test middleware.restore/purge(no predicate path; RBACsys_tables only), as before.rlsOperationForVerb. It is AST-only, and [finding] The bulk AST write path passesopCtx.operationraw, sopurge/transfer/restorederive no row scope whileupdate/deletenow do (#7665 asymmetry) #7809 keepspurge/restoreAST-free, so no lifecycle verb reaches it.restore/purgedispatches keepsrestore(write classupdate) out of the bulk path; the delta review (6721290796) judged it unreachable by a request a caller can shape. An ordinaryupdate/deletewithout id or AST is not passed through./me/permissionsmap now shows the two bin keys onsys_objects too, where the engine refuses to bin them; the map reports the grant, not the bin's reach.plugin.tscomment, the dead liveness rows, the lintretiredKeyRemedydocblock) are tracked in permission: four texts still say allowRestore / allowPurge "return with M2" after #30237 PR 4 corrected the tombstones (migration entry 18, conversion entry 18, ui permission slice, metadata plugin comment) #31508.Verification
Head
95d2a17f(origin/maindb502314merged). 39 files changed, +1088 / −325.node scripts/pm/dispatch-gates.mjs --commands: 124 families; every one run with its exit captured before any pipe;--ranreconciliation:124 derived, 124 run, 0 NOT-MEASURED, 0 UNRUN; 124/124 exit 0 on the final tree (aftergit fetch --unshallowand a fullpnpm --workspace-concurrency=2 build).check:system-context-census(two newisSystemreads) answered by rows 29d/29e +--write.pnpm --filter {objectql,plugin-security,plugin-sharing,core,verify,spec,lint} typecheck: exit 0. eslint over the touched source: exit 0.handle.observe-writes.test.ts🤖 Generated with Claude Code
https://claude.ai/code/session_01FEkQ5nYzXijPZzrM68FB5J