Repository navigation
Commit 467b13b
fix(runtime): platformSystemApi on an action handler's ctx.api keeps the 'action' mark, and what it returns stays seam-wrapped (#35383)
repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb
Fixes #35174
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:用户无感;宿主代码写的动作处理器若把自己拿到的接口交给「平台自用系统接口」函数(或两个公开的预置钩子辅助函数),拿回的接口仍带动作标记,改成员、岗位、权限集分配、邀请会像文档写的那样被拒,读系统元数据表也仍是投影形态。
-
为什么做:修正「审计写入不再被当作自动化写入」那次改动留下的口子,让权限文档对动作处理器的承诺重新成立,并补上运行时两层包装漏掉的路;动作再调用动作的那条路已在文档里注明不覆盖,另立卡跟进。
- 出错会怎样:最坏是某个宿主动作处理器经此函数写身份分配对象时被拒;目前仓库里没有这样的调用方,审计写入路径不变,回滚本次合并即可。
- 要你做什么:无,席位落地。
## 席位核对
### What changes
Ruling record 7000291725 (maintainer, verbatim: 「A+B 补包装且保留标记」), plus
the scope-addition comment 6975046219 (N1, F3). Contract review
7003367719 (PASS, S1/S2) is addressed in fix round 2.
- **A, the walk**
(`packages/runtime/src/stored-metadata-reader-seam.ts`):
`deriveThroughSeam` now walks symbol-keyed members. Since fix round 2
(L2 S1), the default arm answers EVERY symbol-keyed member through a
wrapper. Its result, awaited when it is a promise, is wrapped as
`sudo()`'s is when it is an api of the same kind; anything else passes
through. This covers the member `platformSystemApi` reads
(`Symbol.for('objectstack.objectql.platformSystemApi')`, named in
runtime as `PLATFORM_SYSTEM_API`, a module export only, not on runtime's
package entry) and the published `seedHookUserGrants` /
`seedHookUnreadMembership`. So what they return stays inside the
stored-metadata read seam and the landed-write answer. Before, the
`default` arm bound the member to the unwrapped target.
- **B, the origin flag** (`packages/runtime/src/action-execution.ts`):
`buildActionApi` builds the action door's api over a third layer,
`keepActionDoorProvenance`, beneath the landed-write and read-seam
layers. It is the same shared walk with its own marker,
`Symbol.for('objectstack.runtime.actionDoorOrigin')`, so the api and
every api derived from it carry the flag. On each, the walk's new
`answeredBy` option answers the platform-system member with the api's
`sudo()`, so the `'action'` mark and any `flowRunId` stay. It is a NEW
flag, not the engine's `appAuthored`, so a host handler keeps the
engine's permanent delete (ADR-0148 D3). Repositories pass through this
layer unchanged.
- **Docs**:
- N1, the `packages/objectql/src/platform-system-api.ts` module header.
"its own `sudo()` marks again" becomes "not app-authored, so its own
`sudo()` adds no mark". The "the line stops there" gap paragraph now
describes the apis the line holds on, and names
`ObjectRepository.execute`'s api as not covered (L2 S2).
- F3, `content/docs/permissions/system-context.mdx` row 1b. One clause
names `platformSystemApi` as the producer that takes the mark off a
platform hook's api only, and answers `sudo()` on an app-authored hook's
api and on the action door's api. So the refusal, and the action body's
owner stamp in the next row, hold through it. The row also names
`ctx.api.object(o).execute(name)`'s api as not covered; follow-up
#35434.
- Changeset: `@objectstack/runtime` patch, with a "Not covered" bullet.
`@objectstack/objectql` changes only in a module-header comment.
### Tests
Head `6bec461ee` (fix round 2).
- Round-2 pins: 2 new cases, one per published seed helper. Through
`platformSystemApi(await seed(ctx.api))`, an insert into `sys_member` is
refused `PERMISSION_DENIED` / 403 and nothing lands. The seeded api
answers the origin flag and both seam markers. The file is 10/10.
- Round-2 ablation: the symbol-key wrapper in
`stored-metadata-reader-seam.ts` was removed (blob `da23f6d7` →
`67b1f3bf`). Result: 3 failed, 7 passed. Both seed pins and the walk pin
were red; the B pins and both CONTROLs stayed green. Restored: blob
equals HEAD.
- Full runtime suite at `6bec461`: 11578 passed, 1 failed. The failure
is a QuickJS CPU-budget case (`app-artifact-handlers.jobs.test.ts`) that
timed out under load. It passes alone (41/41) and was green on
`bb4bdda`.
- dispatch-gates at `6bec461`: 101 derived, 99 exit 0, 2 NOT MEASURED
(prerequisite builds; both exit 0 at `2919fe6ac`).
- CI is green at `6bec461`.
Round-1 record (head `2919fe6ac`):
- New file
`packages/runtime/src/action-door-platform-system-api.integration.test.ts`
(real `ObjectQL`, a real SQL driver, the real `SecurityPlugin`; the
store is read back past the middleware). Each ruling clause maps to a
pin:
1. **B, mark kept**: through `platformSystemApi(api)`,
`platformSystemApi(api.sudo())` and `platformSystemApi(trx)` inside
`api.transaction`, an insert into each of `sys_user_position`,
`sys_user_permission_set`, `sys_invitation`, `sys_member` is refused
`PERMISSION_DENIED` / 403 with the action-body prescription, and no row
lands (4 cases). Its insert into an ordinary object is owner-stamped
with the caller (the row-2 stamp).
2. **A, walk**: `platformSystemApi(api)`,
`platformSystemApi(api.sudo())` and `api.sudo()` each answer both
layers' markers and the origin flag. CONTROL: a bare
`engine.createContext` api answers none.
3. **CONTROL, the audit writer's path**: a hook registered in code,
fired by the action api's insert, writes `sys_member` and
`sys_audit_log` through `platformSystemApi(hctx.api)`, and both land. In
the same hook, `hctx.api.sudo()` is refused, which proves the hook's
context carried the mark.
4. **CONTROL, ADR-0148 D3**: the host handler's `delete({ where,
permanent: true })` runs through `api` and through
`platformSystemApi(api)`.
- `pnpm --filter @objectstack/objectql typecheck` and `pnpm --filter
@objectstack/runtime typecheck`: exit 0, with test layers OK.
<details><summary>Round-1 ablations (one per clause, both on runtime
src, which the suite imports relatively; no build in the path)</summary>
- **A**: `ablation-replace.mjs` deleted `case PLATFORM_SYSTEM_API:` from
the walk. Result: 1 failed, 7 passed; the walk pin was red. Restored.
(Round 2 folded that case into the symbol-key arm; the round-2 ablation
above covers it.)
- **B**: `ablation-replace.mjs` replaced
`keepActionDoorProvenance(scoped)` with `scoped`. Result: 6 failed, 2
passed. The four identity pins, the owner stamp, and the walk pin's
origin-flag assertion were red, and the two CONTROLs stayed green.
Restored.
</details>
### Acceptance notes
- **Where B's flag lives, measured against A4.** The flag first rode as
a private `ScopedContext` field. That grew
`packages/objectql/src/engine.ts` past its facade ceiling of 6854
(`check:facade-delegation-only`, ruling 6897467376; raising it is
maintainer-only). So the flag is a runtime layer over the action api, on
the same shared walk. `engine.ts`, `engine-scoped-context.ts` and
`hook-run-as.test.ts` end byte-identical to main.
- **What B is not**: not a security boundary. A host handler's package
registered through the engine it holds, and that engine's
`createContext({ isSystem: true })` builds an unmarked system api. B
keeps the documented answer for the api a handler was handed, as the
ruling says.
- **Reach of the layer**: it covers every api the shared walk derives:
`sudo()`, `withRunAs(...)`, a transaction's context, the
`beginTransaction()` ctx, and the api any symbol-keyed member returns
(awaited when it is a promise). That last group includes
`platformSystemApi` and the published `seedHookUserGrants` /
`seedHookUnreadMembership` (objectql entry), each pinned.
- **Not covered**: the api `ObjectRepository.execute` hands the action
it dispatches (`ctx.api.object(o).execute(name)`,
`engine-object-repository.ts`). That api is a bare engine
`ScopedContext` carrying the `'action'` mark and no action-door flag, so
`platformSystemApi` still takes the mark off there. Row 1b and the
objectql header say so. The engine side is follow-up #35434 (nested
under #35174).
- `Clause-②: no` on the final diff. No package-entry export is added,
and `deriveThroughSeam`'s signature is unchanged in round 2.
`platformSystemApi` is unreleased, so the narrowing reaches no published
consumer.
### Verification
<details><summary>Gates</summary>
- Round 2, `node scripts/pm/dispatch-gates.mjs --commands` at `6bec461`:
101 derived, 99 run with exit 0, 2 NOT MEASURED. Those two
(`check:skill-examples`, `check:dual-build-cjs-loads`) need a full
build; both exited 0 at `2919fe6ac` and run in CI.
`check:system-context-census` exit 0.
- Round 1 at `2919fe6ac`: 101 of 101 exit 0.
- `node scripts/pm/overlap-check.mjs --branch=HEAD`: clean (#34817
shares `system-context.mdx` and merges cleanly).
- Full-repo scans (`pnpm lint`) and the `test:repo` project belong to
CI.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6Ca1jJvsA1dHsPwMiQb)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: os-bill <noreply@objectstack.ai>1 parent 89364b4 commit 467b13b
6 files changed
Lines changed: 375 additions & 35 deletions
File tree
- .changeset
- content/docs/permissions
- packages
- objectql/src
- runtime/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 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 38 | + | |
| 39 | + | |
42 | 40 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 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 | + | |
59 | 67 | | |
60 | 68 | | |
61 | 69 | | |
| |||
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
67 | | - | |
| 75 | + | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| |||
0 commit comments