Repository navigation
Commit 601832b
refactor(core): serve the unreact and personal-view doors from one own-row delete door (#29757)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ873kbFcJFx4LxoFFBNwCohp)_
Fixes #29636
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:撤销表情(`DELETE /api/v1/comments/reactions/:id`)和删除个人视图(`DELETE
/api/v1/personal-views/:id`)这两扇"只删自己那一行"的门,原本是两份几乎逐行相同的复制;现在共用
`@objectstack/core`
里的一扇门,两个插件各自只提供对象名、所有者列、路由和回答用词。另附三处注释/测试:系统身份跳过也放行提权的应用自动化、`manifest.ts`
的过时注释、偏好"替别人建"的 REST 对照测试。
-
为什么改:这段安全顺序(以调用者身份读行→404,核对所有者→403,再以系统身份删除并记到调用者名下)只要两份就会改一处漏一处;合一后只有一个地方要审。
- 风险与回滚:纯搬移,任何一扇门的回答都不变(下面有 17 种请求的前后逐字节对比)。回滚即 revert 本 PR。
-
先看:`packages/core/src/security/own-row-delete-routes.ts`(`removeOwnRow`
的第 5、6 步与系统删除的上下文),然后
`packages/plugins/plugin-audit/src/comment-reaction-routes.ts` 与
`packages/plugins/plugin-auth/src/personal-view-routes.ts` 的门描述。
- 两分钟验证:`pnpm --filter @objectstack/plugin-audit exec vitest run
src/comment-reaction-routes.test.ts`,预期全绿,其中 "its verdict on the row"
一组钉住 404 / 403 / 200 + 归属。
- 需要你做的:无,席位落地。
## What changes
**One own-row delete door, in `@objectstack/core`.**
`packages/core/src/security/own-row-delete-routes.ts` holds the sequence
both doors ran, moved without change: resolve the caller through
`resolveRequestExecutionContext`, refuse anonymous, a held sign-in and
any query parameter, read the row as the caller (`404 RECORD_NOT_FOUND`
when it cannot be read), check its owner column (`403 PERMISSION_DENIED`
when it names someone else), then remove it under `{ isSystem: true,
attributedUserId: caller, tenantId: caller's }` and answer `200 { id,
deleted: true }` (a removal that matched nothing is `404`). It exports
`registerOwnRowDeleteRoute(http, door, deps)`, `removeOwnRow(engine,
door, id, context)` and `ownRowDeleteCallerResolver(sources)`, with the
types `OwnRowDeleteDoor`, `OwnRowDeleteWords`, `OwnRowDeleteEngine`,
`OwnRowDeleteRoutesDeps` and `OwnRowDeleteCallerSources`.
**Each object supplies its part.** An `OwnRowDeleteDoor` names the
route, the object, the owner column and the words its answers use:
| door | route | object | owner column | words (noun / short / owner) |
| :--- | :--- | :--- | :--- | :--- |
| unreact (`plugin-audit`) | `/api/v1/comments/reactions/:id` |
`sys_comment_reaction` | `created_by` | reaction / reaction / member |
| personal view (`plugin-auth`) | `/api/v1/personal-views/:id` |
`sys_personal_view` | `user_id` | personal view / view / user |
The words rebuild each door's existing sentences exactly, so no refusal
text moves. Each plugin keeps its route file, every name it exported
(`registerCommentReactionRoutes`, `platformCallerResolver`,
`removeOwnCommentReaction`, `CommentReactionEngine`, …, and the
personal-view twins, now thin delegations), its route ledger and its
conformance test; neither mount site (`audit-plugin.ts`,
`auth-plugin.ts`) changes.
**Why core.** Both plugins already depend on `@objectstack/core`,
`@objectstack/types`, `@objectstack/spec` and
`@objectstack/platform-objects`, so no new dependency edge is possible
elsewhere. Core is the one that already holds every piece the door
composes (`resolveRequestExecutionContext`, the anonymous floor,
`evaluateAuthGate`, the API-key and authz-store refusals,
`recordNotFoundError`) and already depends on `@objectstack/types` for
the envelope writers. `@objectstack/types` could not host it without
depending on core (a cycle); spec holds no runtime logic;
platform-objects holds object definitions.
**Ledgers that follow the move.**
- `scripts/check-single-authz-resolver.mjs` `DELEGATORS`: the core
door's row (`resolveRequestExecutionContext`) is added, and the two
plugin rows now delegate through `ownRowDeleteCallerResolver`; the
comment above the map says so.
- `scripts/check-route-envelope.mjs` `MODULES`: the core door is
declared at `0 / 0 / 0` (every body through `sendOk` / `sendError` /
`sendServerFault`), and the two plugin rows stay at zero with their
comments updated.
- Tenant-audit census regenerated (`node scripts/tenant-audit-census.mjs
--write`): the census reads only `packages/plugins` and
`packages/services`, so the two elevated deletes, now one call in core,
leave it (256 → 254 sites, 146 → 144 decidably elevated). The six
hand-written figures on
`content/docs/permissions/tenant-audit-census.mdx` follow (57%
unchanged).
**Comment items carried on the card.**
- (a) Census row 26c (`content/docs/permissions/system-context.mdx`) and
the `owner-fixed-rule.ts`, `personal-view-hooks.ts` and
`user-preference-hooks.ts` docblocks now say the `isSystem` skip also
admits app-authored automation elevated to system (a `runAs: 'system'`
flow, a hook's `runAs: 'system'` api or `ctx.api.sudo()`, an action
body's `ctx.api`), the family `flow-system-identity-write-refusal.ts`
names; the rule reads no app-automation elevation mark.
- (b) `packages/plugins/plugin-auth/src/manifest.ts`: the stale "default
flag" comment on `SysPersonalView` is replaced (the default view is the
reader's per-object pin), and `SysUserPreference` gets a comment naming
its owner rule.
- (c) The `user-preference-hooks.ts` create parenthesis is **kept and
pinned**: `[member-create]` in
`packages/qa/dogfood/test/user-preference-owner-fixed.dogfood.test.ts`,
a member creating a preference in another member's name over REST
answers `403 PERMISSION_DENIED` and stores nothing. The docblock names
the pin.
`.changeset/29636-own-row-delete-door.md`: `@objectstack/core`,
`@objectstack/plugin-audit`, `@objectstack/plugin-auth` patch, both
declaration lines.
## Why
The card (should-fix S3 of contract review 6586971553, plus the comment
items of record 6590198210 and S1–S3 of review 6593114814): a
security-relevant sequence lived in two hand-copied files, so a fix to
one, such as the 404/403 order or the attribution, would silently miss
the other. Triage 6591885150 ruled it move-only: no door may answer
differently afterwards.
## Tests
**Measured first, on main's code.** Commit `c5ec5fbc` adds, before any
move, a top-level `describe` to each door's existing shell test
(`comment-reaction-routes.test.ts`, `personal-view-routes.test.ts`): a
row the caller cannot read answers `404 RECORD_NOT_FOUND` with the read
asked as the caller and nothing removed; a row owned by someone else
answers `403 PERMISSION_DENIED` and nothing is removed; the owner's row
answers `200 { id, deleted: true }`, removed under `{ isSystem: true,
attributedUserId, tenantId }` (none without an organization); a row gone
between read and removal answers `404`. The personal-view file also pins
that the owner is judged on `user_id`, not `created_by`. On `c5ec5fbc`:
plugin-audit 2 files 15/15, plugin-auth 3 files 43/43 (VERDICT
command-exit 0).
**The same pins after the move**, on `3f6d5b6a` with core rebuilt:
plugin-audit 15/15, plugin-auth 43/43 (`personal-view-hooks.test.ts`'s
engine-level door pins included), VERDICT command-exit 0.
**Byte-for-byte answer comparison (one-time, not committed).** A scratch
test drove each door's registered handler through 17 requests (authz
store outage, resolver fault, two anonymous shapes, held sign-in, query
parameter, blank and missing id, no engine, engine fault, unreadable,
foreign, own with and without an organization, vanished as `0` and
`false`, a `409` from the delete) and recorded status, full body, and
the engine's `findOne` / `delete` arguments. Before (`c5ec5fbc`) and
after (`3f6d5b6a`) are identical: unreact sha256 `350545f0…b628a6`,
personal view `e7322879…65a435`, `cmp` clean for both.
**Through the real stack, at the head:**
`personal-view-row-scope.dogfood.test.ts` and
`user-preference-owner-fixed.dogfood.test.ts` 2 files 24/24 (the new
`[member-create]` included); plugin-security
`comment-reaction-unreact-door.integration.test.ts` 8/8.
**Package suites, at the head:** `pnpm --filter
@objectstack/plugin-audit test` 68 files 1114/1114; `pnpm --filter
@objectstack/plugin-auth test` 216 files 3708 passed, 10 skipped; `pnpm
--filter @objectstack/core test` 132 files 2934/2934 (VERDICT
command-exit 0). `pnpm typecheck` for core, plugin-audit and
plugin-auth: exit 0.
## Acceptance notes
- The tenant-audit census no longer lists the two elevated deletes,
because `SURFACE_ROOTS` does not read `packages/core`. Nothing about the
write changed (same object, same elevated, tenant-carrying context);
widening the census to core is the census's own question.
- `removeOwnRow` throws `removeOwnRow(OBJECT): the caller context names
no user` where each copy named its own function. That error is
unreachable through the door (step 2 refuses first) and reaches only the
fault log of a direct caller.
- The plugin route files keep their exported names as thin delegations
so no import site, test or mount moves; a later card can retire them if
nobody outside the package needs them.
## Verification
Head `c15745df`. Every gate reading below was taken on `0cfd9309` or
later; the derived family set re-derived on `c15745df` is identical (116
families), and the families reading the files changed after `0cfd9309`
(the census page, row 26c) were re-run on `c15745df`.
<details><summary>Derived gates</summary>
- Prerequisite builds under the lock: the plugin-audit and plugin-auth
closures, the dogfood and plugin-security closures (VERDICT command-exit
0, 7m19s), the client-react closure for `check:skill-examples` (VERDICT
command-exit 0).
- `node scripts/pm/dispatch-gates.mjs --commands`: 116 families (17
paths vs merge base `0822122fd`, +627/-529, under the 3000 human-merge
threshold). Each run once with its exit captured before any pipe: 115
exit 0.
- One real finding on the first pass, fixed:
`check:system-context-census` exit 1, `[unresolved-path]` on row 26c's
bare `flow-system-identity-write-refusal.ts`; the row now cites the full
path (`c15745df`), and the gate exits 0.
- Two prerequisite refusals on the first pass, re-run after the
prerequisite: `check-plugin-teardown-shape.mjs --self-test` (exit 3
until its pinned fixture commit was fetched, then 0, 48 cases);
`check:skill-examples` (exit 3 until the client SDK was built, then 0,
283 examples).
- `pnpm check:dual-build-cjs-loads`: exit 3, PREREQUISITE NOT MET (most
workspace packages unbuilt in this container). NOT MEASURED locally; CI
runs it on a full build.
- `dispatch-gates --ran`: 116 derived, 115 run, 1 NOT-MEASURED
(dual-build, from its recorded exit 3), 0 UNRUN.
- `pnpm lint` (repo-wide eslint): exit 0.
- No ablation: no tested behaviour changed (the move is pinned as
unchanged, and the one new pin, `[member-create]`, is a control on
behaviour that already existed).
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: not touched.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01JQwxbWMy2AkJ9oN4WfpecN)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 946a173 commit 601832b
17 files changed
Lines changed: 627 additions & 529 deletions
File tree
- .changeset
- content/docs/permissions
- docs/audits
- packages
- core/src/security
- plugins
- plugin-audit/src
- plugin-auth/src
- qa/dogfood/test
- scripts
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
200 | | - | |
| 200 | + | |
201 | 201 | | |
202 | | - | |
203 | | - | |
| 202 | + | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
| 220 | + | |
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
| 224 | + | |
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
| 236 | + | |
237 | 237 | | |
238 | | - | |
| 238 | + | |
239 | 239 | | |
240 | 240 | | |
241 | | - | |
| 241 | + | |
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
| 246 | + | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
| 260 | + | |
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
310 | | - | |
| 310 | + | |
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
315 | | - | |
| 314 | + | |
| 315 | + | |
316 | 316 | | |
317 | | - | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
124 | 123 | | |
125 | 124 | | |
126 | 125 | | |
| |||
166 | 165 | | |
167 | 166 | | |
168 | 167 | | |
169 | | - | |
170 | 168 | | |
171 | 169 | | |
172 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
204 | 218 | | |
205 | 219 | | |
206 | 220 | | |
| |||
0 commit comments