Skip to content

Commit 1ee3bb8

Browse files
fix(plugin-audit): an activity text names a referenced record by title only to a reader served that title field and admitted to its object (#34653)
Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:活动动态(sys_activity)里以标题指称被引用记录的文字——标题字段为查找字段的对象的记录标签、被跟踪查找字段的变更句、里程碑句中的引用占位——只服务给被服务该标题字段、且被准入读取该对象的读者;否则该行不带这段文字,仍带记录 id。目标对象的 API 暴露仍由写入时决定:写入方只为暴露 `get` 的目标取标题,其余按 id 写入,同一句可一处为标题、一处为 id。 - 为什么改:加固规则——经活动动态服务给读者的记录标题,遵从该读者的字段级安全;读者读不到的标题不随该行服务、只留记录 id,在标题字段与对象准入两层上与 `$expand` 的判法一致(`referenceNameVisible` 只放开对象级拒绝,不放开字段级规则)。 - 风险与回滚:只收窄读侧服务内容,不改存储、不改写入;能读到所有被引用标题的读者和系统读取不变;回滚即 revert 本 PR,无数据迁移。 - 先看:`packages/plugins/plugin-audit/src/activity-field-redaction.ts`(`referenceTitlesPerRead` 与 `redactActivityRows` 文本列判定处);`packages/plugins/plugin-audit/src/activity-field-redaction.test.ts`(末尾两个新 describe);`packages/core/src/security/second-object-read-exposure.pin.test.ts`(新增的 `executes` 一行)。 - 两分钟验证:`pnpm --filter @objectstack/plugin-audit exec vitest run src/activity-field-redaction.test.ts`,预期 1 个文件、35 个用例全部通过(其中新增 16 个)。 - 需要你做的:无,席位落地。 ## What changes Hardening rule: **an activity text that names a referenced record by its title is served only to a reader served that title field and admitted to its object.** An activity row names a referenced record by its title in three places: the record label of an object whose `nameField` is a lookup or `user` field, a tracked reference field's change, and a fired milestone's reference token. The `sys_activity` read redaction (`activity-field-redaction.ts`) now judges each such text against the object every such reference points at, by the two answers `$expand` judges a target's title by at that level: - the reader must be served the target object's title field (ADR-0079 `resolveDisplayField`) unmasked, by the same served-fields answer the redaction already uses, which also withholds a formula title computed from a field the reader may not read; - and the security service must admit the reader to the target object (`canReadObject`). A reference field that declares `referenceNameVisible` lifts this object-level admission and never the field-level rule, as on `$expand`. Otherwise the text is left out of the row the way any activity text composed from a field the reader is not served already is, and the row keeps its `record_id`. A reader served each referenced title field and admitted to each referenced object, and every system read, are served the row as before. The judgement is made at read time from the security service's answers, once per referenced object per read; no row is read for it, and stored rows are judged the same way. A target's declared API exposure (ADR-0049) stays decided where its title is read: the mirror titles a reference only when the target's exposure serves `get` (`servesSummaryTitleTarget`), and names every other referenced record by its stored id, per id, so one sentence can title one reference and name another by its id. The read redaction judges its reader against every reference a sentence names by the two answers above, whatever the target's exposure. The second-object exposure census (`packages/core/src/security/second-object-read-exposure.pin.test.ts`) classifies the redaction as executing the read `audit-writers.ts` decides: it reads no record of the target and no title. The notification door was measured too: an approval notification already names its record by a title its recipient may read, else not at all (a formula title over a withheld field included). This PR adds a door-level pin for it and changes no notification code. ## Tests - `packages/plugins/plugin-audit/src/activity-field-redaction.test.ts`, two new top-level describes in the shared harness: - a real engine, SQLite driver and the real `AuditPlugin` mirror, with a security double answering the field members and `canReadObject` per reader (8 cases): a reader not served the referenced title field, a reader refused the referenced object, `referenceNameVisible` on each, a tracked reference change, one change naming a target whose exposure serves no `get` by its id and an exposed target by its title (served to a reader who may read that title, to no reader withheld it), the by-id read, and the control reader; - `referenceTitlesPerRead` directly (8 cases): non-reference sources, every declared reference judged, field and admission halves, `referenceNameVisible`, fail closed on a throwing admission or an unregistered target, a title-less target, a target whose exposure serves no `get` judged by the reader like any other, no admission member. - `packages/core/src/security/second-object-read-exposure.pin.test.ts`: `activity-field-redaction.ts` classified in `CALLERS` as `executes`, decided in `packages/plugins/plugin-audit/src/audit-writers.ts`. - Door-level pins on a real boot (`bootStack` with the real `SecurityPlugin`): - feed door: `packages/qa/dogfood/test/activity-label-display-field.dogfood.test.ts`, new top-level describe: a reader whose permission set withholds the referenced title field against the control, through `GET /data/sys_activity` list and by id, armed on the data plane first; - notification door: `packages/qa/dogfood/test/approval-notification-body.dogfood.test.ts`, new top-level describe: two approvers of one request, one withheld a field of the record's formula title, read back from each approver's `GET /api/v1/notifications`, armed on the data plane first. - `packages/qa/dogfood/test/lookup-title-exposure.dogfood.test.ts` (unchanged) holds the exposure half: a summary names a target whose exposure serves no `get` by its stored id and the exposed control by its title, for an administrator and a member. ## Acceptance notes - A changed-fields summary (`Updated X "label": Field`) that names a changed reference field by its field label also declares that field as a source, so it is left out for a reader refused that reference's title, though the sentence carries no title of the referenced record. The fail-closed direction; noted, not changed. - Likewise a sentence naming a target whose exposure serves no `get` by its id is left out for a reader refused that target's title field or object, though it carries only the id. The fail-closed direction; noted, not changed. - Clause-② is `no`: no input is refused and no accepted set narrows; a reader is served a row without a text column it may not read, the shape every earlier change to this redaction declared. ## Verification All readings at head `e2133d6830` (branch `claude/sec2-ph96`, merged with `origin/main`), each run under `scripts/pm/os-verify-lock.sh`. <details><summary>plugin-audit, core's repo project and the second-object exposure pin</summary> ``` pnpm exec turbo run build --filter='@objectstack/dogfood^...' -> 70/70 tasks · exit 0 pnpm --filter @objectstack/plugin-audit exec vitest run src/activity-field-redaction.test.ts -> Test Files 1 passed · Tests 35 passed · exit 0 pnpm --filter @objectstack/plugin-audit test -> Test Files 101 passed (101) · Tests 1703 passed (1703) · exit 0 pnpm --filter @objectstack/plugin-audit typecheck -> exit 0 pnpm --filter @objectstack/core exec vitest run --project repo src/security/second-object-read-exposure.pin.test.ts -> Tests 4 passed (4) · exit 0 pnpm --filter @objectstack/core test:repo -> Test Files 8 passed (8) · Tests 105 passed (105) · exit 0 ``` </details> <details><summary>Dogfood: the whole battery, then the touched files and the battery's timed-out files</summary> ``` pnpm --filter @objectstack/dogfood test (no shard, no path) Test Files 4 failed | 474 passed | 3 skipped (481) Tests 5 failed | 4053 passed | 68 skipped (4126) ``` All five failures are `Error: Test timed out in 5000ms.`, in four files outside this diff (`bare-name-one-holder-request-family`, `external-import-walled-catalog-refusal`, `flow-provenance-server-held`, `package-commit-revert-path-package`), on a shared box under load (the battery held the lock 4035 s). The same four files were run again with the three files this change bears on (`lookup-title-exposure`, `activity-label-display-field`, `approval-notification-body`): ``` Test Files 7 passed (7) Tests 62 passed (62) ``` </details> <details><summary>Ablations (earlier rounds; the judged path is unchanged since)</summary> - The reference-title conjunct in `redactActivityRows` replaced with `true`: `src/activity-field-redaction.test.ts` 5 failed (the engine-level reader cases), then restored, blob == HEAD, `git diff HEAD` empty. </details> <details><summary>Gates: derived families, reconciled</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at this head: 73 commands, each run, exit code captured before any pipe; `--ran` reconciliation: ``` ✓ dispatch-gates --ran: 73 derived famil(ies) accounted for — 71 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3). ``` NOT MEASURED locally, prerequisite not met: `check:dual-build-cjs-loads`, `check:type-check-debt`; both run in CI. The derivation does not list core's `repo` project pin for this diff; it was run explicitly above. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYn5CmmdShCJifm6WYj)_ <!-- signed: security#2 · os-justin · 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 a8aa6ab commit 1ee3bb8

6 files changed

Lines changed: 848 additions & 5 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/plugin-audit': patch
3+
---
4+
5+
fix(plugin-audit): an activity text that names a referenced record by its title is served only to a reader served that title field and admitted to its object
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
**The rule.** An activity row names a referenced record by its title in three places: the record label of an object whose `nameField` is a lookup or `user` field, a tracked reference field's change, and a fired milestone's reference token. Each such text is served to a reader only when both of these hold for the object every such reference points at, the two answers `$expand` judges a target's title by at that level:
11+
12+
- the reader is served the target object's title field (its ADR-0079 `nameField`) unmasked, by the security service's field answer, which also withholds a formula title computed from a field the reader may not read; and
13+
- the security service admits the reader to the target object. A reference field that declares `referenceNameVisible` lifts this object-level admission and never the field-level rule, as it does on `$expand`.
14+
15+
Otherwise the text is served the way any activity text composed from a field the reader is not served already is: the row keeps its `record_id`, and the label or summary is left out of the row. A reader served each referenced title field and admitted to each referenced object, and every system read, are served the row as before.
16+
17+
A target's declared API exposure (ADR-0049) is decided where its title is read: the mirror titles a reference only when the target's exposure serves `get`, and names every other referenced record by its stored id, so one sentence can title one reference and name another by its id. Such a sentence is judged by the two answers above for every reference it names, whatever the target's exposure.
18+
19+
The judgement is made at read time from the security service's answers, once per referenced object per read; no row is read for it, and rows already written are judged the same way.

‎packages/core/src/security/second-object-read-exposure.pin.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ const CALLERS: Record<string, Classification> = {
195195
wiring: { file: 'packages/plugins/plugin-audit/src/audit-writers.ts', call: 'servesSummaryTitleTarget(objectName' },
196196
pin: 'packages/plugins/plugin-audit/src/audit-lookup-summary.test.ts',
197197
},
198+
'packages/plugins/plugin-audit/src/activity-field-redaction.ts': {
199+
kind: 'executes',
200+
read:
201+
"the activity timeline's read redaction, serving per reader the referenced records' titles the mirror's " +
202+
'`resolveLookupTitles` wrote (`referenceTitlesPerRead` judges each reader against the title field and the object ' +
203+
'of every reference a text names)',
204+
decidedIn: 'packages/plugins/plugin-audit/src/audit-writers.ts',
205+
also:
206+
'reads no record of the target and no title: `referenceTargetOf` names the object whose title field and read ' +
207+
'admission a reader is judged against; the title was read at write time, only from a target whose exposure ' +
208+
'serves `get` (`servesSummaryTitleTarget`). Pinned in `activity-field-redaction.test.ts`',
209+
},
198210
// The engine's relation group join: an analytics cross-object dimension as one `LEFT JOIN … GROUP BY`.
199211
'packages/objectql/src/relation-group-join.ts': {
200212
kind: 'decided',

0 commit comments

Comments
 (0)