Skip to content

Commit 13057ce

Browse files
feat(spec, lint): a permission set can acknowledge a meant roll-up read with rollupSourceUnreadableReason (#34775)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi94c3JZDWgKZEMu2AsnddNtK)_ Fixes #34664 Clause-②: yes (widening) — one new optional authorable key, `rollupSourceUnreadableReason` on `FieldPermissionSchema` (a permission set's `fields` entry); nothing that parsed before is refused Metadata-protocol: added Skills-docs: follow-up #34742 ## 维护者速读 - 改了什么:权限集里某个汇总列的字段条目可以写 `rollupSourceUnreadableReason: '理由'`,声明「这个集本就该看汇总、不看明细」;写了之后,这个集这一列的 `security-rollup-source-unreadable` 由 warning 降为 info 并引出理由,`os lint --strict` 不再因它失败。 - 为什么改:这条规则自己说「这种组合合法且常是有意的」,但 `--strict` 把 warning 判失败、又没有任何确认办法,HotCRM(hotcrm#2557/#2560,账户下挂发票与收款)只能二选一:给子对象开读权限(会放开所有行)或藏掉总额。键名与落位由席位定(卡上 6943835606)。 - 风险与回滚:纯新增可选键,运行时不读这个键;但理由只能写在字段条目上,而条目本身在字段合并里投 `readable: true` 一票(最宽者胜),原本没有该列条目的集为挂理由新加条目,会让同时持有屏蔽集的用户重新看到这一列,文档与 describe 已写明(L2 S1)。空白理由、`readable: false` 旁带理由在解析时拒收。其它集、其它列和 row-scoped 提示不受影响。回滚即还原本 PR。 - 先看:`packages/lint/src/validate-rollup-source-visibility.ts` 的 `acknowledgedReason` 与 `unreadable` 闭包;`packages/spec/src/security/permission.zod.ts` 新键与第二个 `.refine`;`packages/lint/src/validate-rollup-source-visibility-acknowledged-34664.test.ts`。 - 两分钟验证:`pnpm --filter @objectstack/lint exec vitest run src/validate-rollup-source-visibility-acknowledged-34664.test.ts`,预期 9 例全绿。 - 需要你做的:契约改动(packages/spec/src),L1 与 L2 通过后由席位请 os-zhuang 批准。 ## What changes `security-rollup-source-unreadable` is advisory by its own header ("the pair is legal and is often meant"), but it emits a `warning`, `os lint --strict` fails on any warning (`packages/cli/src/commands/lint.ts:1175-1179`), and `packages/lint` / the CLI had no per-finding acknowledgement. The seat named the key and its placement (card comment 6943835606): option A of the three offered. - **Spec (`packages/spec/src/security/permission.zod.ts`).** `FieldPermissionSchema` gains `rollupSourceUnreadableReason: string` (optional). Two parse refusals: a blank reason (`NON_BLANK_STRING`, which projects into the JSON Schema), and a reason beside `readable: false` (a second object `.refine` on path `rollupSourceUnreadableReason`; the column is hidden, so there is no read to acknowledge). The describe says the key is read only at authoring time, and (contract review S1) that the entry carrying it is an ordinary declaring entry: it votes `readable: true` in the field merge, so on a set with no entry for the column, adding one restores the column for holders whose other sets mask it. The same sentence is in the jsdoc, `rule-explanations.ts`, `fields.mdx` and `security.mdx`. `FieldPermissionSchema` is also reused by `GetObjectPermissionsResponseSchema.fieldPermissions`; per the seat the type is not split, and the server never sends the key. - **Lint (`packages/lint/src/validate-rollup-source-visibility.ts`).** `acknowledgedReason(set, column)` reads the set's OWN entry for the summary column. When it carries a non-blank reason, every `security-rollup-source-unreadable` finding for that set and column (object, aggregated-field and filter-field arms) is emitted at `info`, same rule id, message ending `Acknowledged on the set: ` plus the reason as a JSON string literal (quotes and line breaks stay escaped), path `permissions[i].fields["OBJECT.SUMMARY"].rollupSourceUnreadableReason`, and a hint saying how to restore the warning. Other sets, other columns, and `security-rollup-source-row-scoped` are unchanged. Docblock table and a new section document it. - **Docs.** `rule-explanations.ts` (the rule's explanation gains the acknowledgement paragraph), `content/docs/data-modeling/fields.mdx` (roll-up section, with an example), `content/docs/deployment/validating-metadata.mdx` (the advisory row), `content/docs/protocol/objectql/security.mdx` (the field permission reference, which enumerates the entry's keys; added after the docs-drift comment named the page). - **Ledgers and generated.** `packages/spec/liveness/permission.json` gains `fields.children.rollupSourceUnreadableReason` = `live` (lint is the whole feature, the same posture as dashboard `widgets.suppressWarnings`); regenerated `authorable-surface/security.json`, `liveness/state-counts/permission.md`, `content/docs/references/security/permission.mdx`, `content/docs/references/api/protocol.mdx`. - **Changeset** `.changeset/34664-rollup-source-unreadable-reason.md`: `@objectstack/spec` minor, `@objectstack/lint` minor. ## Tests - New `packages/lint/src/validate-rollup-source-visibility-acknowledged-34664.test.ts` (9 cases, through `runAuthoringRules`): control without the key (both roll-ups warn); key on one column ⇒ that finding `info`, reason quoted, path at the key, the other column still `warning`; every column acknowledged ⇒ no warning left; another set reading the same column still warns; a blank reason on the raw door acknowledges nothing; the row-scoped note is untouched; the aggregated-field and filter-field arms are acknowledged the same way; a quote and a line break in the reason stay inside the quoted literal; a parsed set answers what the raw one does. - `packages/spec/src/security/permission.test.ts`: 5 new cases under `rollupSourceUnreadableReason` (accepts and keeps it; absent key does not materialise; blank and non-string refused; refused beside `readable: false`; rides a permission set's `fields`). - No existing test was changed. ## Acceptance notes - **Same rule id at `info`.** The acknowledged finding keeps `security-rollup-source-unreadable` (only its severity moves), so `--json` consumers filtering by id still see the pair. One consumer filters by id without severity: `packages/qa/scenarios/src/runner/orchestrate.ts#rollupSourceCharges` still charges an acknowledged pair when the card withholds the child from that persona. That is intended: an acknowledgement does not make a withheld total un-leaked, and its message regex still reads the new message (no `$` anchor). Not changed here. - **A stale acknowledgement is not reported.** A reason on an entry whose set and column raise no finding (or on a non-summary field's entry) is silent, and it pre-acknowledges: if the child read is later removed, the finding first appears at `info`. The seat chose not to add that in this PR (contract review N3). - **Console permission matrix (contract review S2) → #34786.** `ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx#updateFieldPerm` clears only `when` on Read off, so an entry carrying a reason turns into the refused `readable: false` + reason shape; `permission-slice.ts#withFieldBits` drops the reason silently. Out of this card's file surface; filed by the seat as #34786 (Blocked-by #34664). - **Skills** are out of this card's file surface (seat ruling, relayed by the area); the skill line and an eval go on #34742. ## Verification <details><summary>Premise on origin/main f6f5b50</summary> - The rule header calls the pair "legal and often meant" and emits `severity: 'warning'`. - `packages/cli/src/commands/lint.ts:1175-1179`: `failing = errors.length + (strict ? warnings.length : 0)`. - No acknowledgement or suppression in `packages/lint/src` or the CLI; the only metadata suppression key is the dashboard widget's `suppressWarnings` (`packages/spec/src/ui/dashboard.zod.ts:1415`); `packages/lint/src/index.ts:1127` states "the CLI has no per-rule suppression". - `node scripts/pm/check-prior-rulings.mjs --card 34664`: ADR-0035/0061/0063/0071/0074/0079 hits; none rules on acknowledging an advisory finding. ADR-0035's roll-up semantics are unchanged. </details> <details><summary>Package tests and typecheck</summary> - `pnpm --filter @objectstack/lint test`: Test Files 216 passed (216), Tests 9124 passed (9124). - `pnpm --filter @objectstack/spec test`: Test Files 848 passed (848), Tests 27174 passed, 1 todo. - `pnpm --filter @objectstack/lint typecheck` and `pnpm --filter @objectstack/spec typecheck` (with `NODE_OPTIONS=--max-old-space-size=4096`): exit 0, test-typecheck debt held. </details> <details><summary>Ablations (both legs restored, `git diff HEAD` empty)</summary> - Lint: `acknowledgedReason` made to return `undefined` (anchor `return nonBlank(reason) ? reason.trim() : undefined;`, 1 → 0, via `scripts/ablation-replace.mjs`) ⇒ the new suite goes red, 4 failed / 3 passed (the four acknowledged cases; the control, blank-reason and row-scoped cases stay green, as expected). - Spec: the `readable: false` refine made vacuous (`(p) => true || …`) ⇒ `refuses a reason beside readable: false` goes red, 1 failed / 4 passed. </details> <details><summary>Derived gates</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`, each command run with `< /dev/null`, exit captured before any pipe; reconciliation `--ran`: **115 derived, 114 run, 1 NOT-MEASURED, 0 UNRUN**, every run family exit 0. After the security.mdx commit (head 7a8180f) the derived set is unchanged; the docs families re-run on it (`check:doc-anchors`, `check:doc-authoring`, `check-affected-docs`, `check-drift-comment`, `check:docs-transcript-drift`, `check:nul-bytes`) exit 0. - First pass red only on generated artefacts (`check:docs`, `check:liveness` counts) and on prerequisites (lint dist not built; a shallow clone for `check-plugin-teardown-shape --self-test`). Regenerated with `gen:schema`, `gen:docs`, `gen:liveness-counts`, built `@objectstack/lint`, unshallowed, and re-ran those families: all exit 0. - `check:generated` (derived after merging origin/main) exit 0 with `NODE_OPTIONS=--max-old-space-size=4096` (without it the test-typecheck step runs out of heap, not a finding). - NOT MEASURED: `pnpm check:dual-build-cjs-loads`, which needs every package's `dist/` (a full `pnpm build`); CI runs it. - Record: `/mnt/project-files/objectstack-seat2/34664-gates-ran.txt` (project file). </details> <details><summary>Rework round (contract review 6945280556: S1, N1, N2, N4, N5)</summary> - Head after the round: b61b6d7 (commit f592705 plus a merge of origin/main). - Lint: the two rule suites + `rule-explanations` tests, 60/60; `@objectstack/lint` typecheck exit 0. Spec: `permission.test.ts` 127/127. - After the merge: `@objectstack/spec` rebuilt; `check:generated` exit 0 (with `NODE_OPTIONS=--max-old-space-size=4096`). Re-run, all exit 0: `check:docs`, `check:authorable-surface`, `check:liveness`, `check:doc-anchors`, `check:doc-authoring`, `check-affected-docs`, `check:docs-transcript-drift`, `check:nul-bytes`, `check:doc-security-posture`. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmQbFKVWVEYrgUsNnfJ --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmQbFKVWVEYrgUsNnfJ)_ <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmQbFKVWVEYrgUsNnfJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c513d62 commit 13057ce

14 files changed

Lines changed: 377 additions & 13 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/lint': minor
4+
---
5+
6+
feat(spec, lint): a permission set can acknowledge a meant roll-up read with `rollupSourceUnreadableReason`
7+
8+
Clause-②: yes (widening) — one new optional authorable key, `rollupSourceUnreadableReason` on `FieldPermissionSchema` (a permission set's `fields` entry); nothing that parsed before is refused
9+
Metadata-protocol: added
10+
Skills-docs: follow-up #34742
11+
12+
`security-rollup-source-unreadable` warns when a permission set reads a roll-up `summary` column over child data it cannot read. The pair is legal and often meant, but `os lint --strict` fails on any warning and there was no way to say so. Now the set's entry for the summary column can carry the reason: `fields: { 'crm_account.invoiced_amount': { readable: true, rollupSourceUnreadableReason: 'Service staff read account totals but not invoice rows' } }`. That one finding (this set, this column) is reported as an `info` note quoting the reason, so `--strict` passes; other sets, other columns and `security-rollup-source-row-scoped` are unchanged. The key is read only at authoring time; the runtime does not read it. A blank reason, and a reason beside `readable: false`, are refused at parse time.

‎content/docs/data-modeling/fields.mdx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,25 @@ If the value should not be visible, set `readable: false` on the summary field i
415415
that set: it hides the field from every holder of the set, and another set they
416416
hold with no entry for the field does not restore it, so declare `readable: true`
417417
on the field in the sets whose holders should keep it.
418+
If the set is meant to read the total without its children (an account total
419+
shown to staff who may not see invoice rows), acknowledge that on the same entry
420+
with the reason, and the warning for that set and column becomes a note quoting
421+
it, so `os lint --strict` passes:
422+
423+
```ts
424+
fields: {
425+
'crm_account.invoiced_amount': {
426+
readable: true,
427+
rollupSourceUnreadableReason: 'Service staff read account totals but not invoice rows',
428+
},
429+
},
430+
```
431+
432+
Only these authoring checks read the key. The entry that carries it is still an
433+
ordinary field permission, though, and votes `readable: true`: on a set that had
434+
no entry for the summary, adding one restores the column for holders whose other
435+
sets mask it. Every other set and column is still reported, and a blank reason,
436+
or one beside `readable: false`, is refused.
418437
419438
A child validation rule can read a parent summary one hop through its
420439
reference, for example "each supplier has at most one primary contact" as a

‎content/docs/deployment/validating-metadata.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ orthogonal to both, and no cell here can carry it; it is written out in
528528
| Row-level-security predicates (#4983) — a permission set's policies, an object's `defaultRowScope`, a membership key's `filter` and a field permission entry's `when` (#25866); at the save door also a membership key nothing owns (#25234) | ✓ | ✓ | ✓ | ✓ᵖᵉᵒ |
529529
| Membership key declarations — `userField` / `valueField` columns, one key on one object, a key the registered resolver also owns (save door only) (#25234) | ✓ | ✓ | ✓ | ✓ᵒ |
530530
| Advisory: retired permission residue — the `allowRestore` / `allowPurge` default the parse strips in silence (`permission-retired-lifecycle-residue`, #17425) | ✓ | ✓ | ✓ | ✓ᵖᵉ |
531-
| Advisory: a roll-up a permission set reads over child data it cannot read — the child object, the aggregated child field or a field the roll-up's `filter` tests unreadable to the set, through its grants, its field entries or a `requiredPermissions` capability it lacks (`security-rollup-source-unreadable`, a warning), or child rows a row-level policy narrows (`security-rollup-source-row-scoped`, a note); a roll-up aggregates the whole child collection and follows only the parent field's own permissions | ✓ | ✓ | ✓ | — |
531+
| Advisory: a roll-up a permission set reads over child data it cannot read — the child object, the aggregated child field or a field the roll-up's `filter` tests unreadable to the set, through its grants, its field entries or a `requiredPermissions` capability it lacks (`security-rollup-source-unreadable`, a warning), or child rows a row-level policy narrows (`security-rollup-source-row-scoped`, a note); a roll-up aggregates the whole child collection and follows only the parent field's own permissions. A set whose entry for the summary column carries `rollupSourceUnreadableReason` gets that warning as a note quoting the reason | ✓ | ✓ | ✓ | — |
532532
| Platform-schedule `create_record` organization (#6285) | — | — | — | ✓ᶠ |
533533
| Public-form anonymous intake on this deployment's tenancy posture — advisory only (#21476) | — | — | — | ✓ᵛ |
534534
| Public-form file fields — a form open to anonymous intake whose sections declare a `file`, `image`, `avatar`, `video` or `audio` field (#25650) | ✓ | ✓ | ✓ | ✓ᵛ |

‎content/docs/protocol/objectql/security.mdx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ rowLevelSecurity:
219219

220220
## 3. Field-Level Security
221221

222-
Field permissions are a map on the permission set keyed by `<object>.<field>`, each with two boolean flags and an optional row condition (`FieldPermissionSchema`):
222+
Field permissions are a map on the permission set keyed by `<object>.<field>`, each with two boolean flags, an optional row condition and, on a roll-up summary column, an optional authoring-time acknowledgement (`FieldPermissionSchema`):
223223

224224
```yaml
225225
# sales_rep.permission.yml (continued)
@@ -259,12 +259,15 @@ fields:
259259
readable: true | false # default true — can see the field
260260
editable: true | false # default false — can modify the field
261261
when: "status == 'approved'" # optional — a row condition on the EDIT vote, in RLS `using`'s CEL
262+
rollupSourceUnreadableReason: "…" # optional — meaningful on a summary column: why this set reads the roll-up without its child data (read by `os lint`, never at runtime)
262263
```
263264
264265
> There is no separate `create` flag for fields. `editable` governs both create-time and update-time writes; read stripping is governed by `readable`.
265266

266267
> `when` narrows **where** the entry votes: on a matching row it votes as declared, on every other row it is absent (as if the set had not declared the field). The write gate judges the stored row before an update and each incoming row of an insert, in process; a row it cannot judge (a predicate update, a stored row the caller cannot read, a condition that does not resolve for the request) applies the entry as its lock. `readable: false` beside a `when` is refused at parse time, and `objectstack validate` judges the condition like an RLS predicate. Readers that hold no row (`/auth/me/permissions`, `os explain`) report the entry as its lock; the record-scoped projection (`GET /data/{object}/{id}/field-access`, the answer a record's edit form reads) judges the stored row exactly as the write gate does. See [Field-level security](/docs/permissions/field-level-security#row-conditioned-edit-locks-when).
267268

269+
> The runtime does not read `rollupSourceUnreadableReason`, but the entry carrying it votes like any declaring entry (`readable: true` by default), so on a set that had no entry for the column, adding one restores the column for holders whose other sets mask it. A set that reads a roll-up `summary` column but not the child data it aggregates draws the `security-rollup-source-unreadable` warning from `os lint`, `os validate` and `os build`; a non-blank reason on the set's entry for that column turns that one warning into a note quoting the reason. A blank reason, or one beside `readable: false`, is refused at parse time. See [Calculation types](/docs/data-modeling/fields#calculation-types).
270+
268271
### Static `readonly` fields on the write path
269272

270273
`readonly: true` on a field definition is a *schema-level* lock, independent of permission

‎content/docs/references/api/protocol.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ One changed key path of the pending draft, and the last write that changed it.
17111711
| :--- | :--- | :--- | :--- |
17121712
| **object** | `string` | ✅ | Object name |
17131713
| **permissions** | `{ allowCreate?: boolean; allowRead?: boolean; allowEdit?: boolean; allowDelete?: boolean; … }` | ✅ | Object-level permissions |
1714-
| **fieldPermissions** | `Record<string, { readable?: boolean; editable?: boolean; when?: string }>` | optional | Field-level permissions keyed by field name |
1714+
| **fieldPermissions** | `Record<string, { readable?: boolean; editable?: boolean; when?: string; rollupSourceUnreadableReason?: string }>` | optional | Field-level permissions keyed by field name |
17151715

17161716
### Nested Shape: `GetObjectPermissionsResponse.permissions`
17171717

@@ -1739,6 +1739,7 @@ One changed key path of the pending draft, and the last write that changed it.
17391739
| **readable** | `boolean` | optional (default: `true`) | Field read access |
17401740
| **editable** | `boolean` | optional (default: `false`) | Field edit access |
17411741
| **when** | `string` | optional | Row condition narrowing where this entry votes, authored in canonical CEL like `rowLevelSecurity[].using` (a field of this object compared with a literal or a `current_user.*` value using `==`, `!=`, `<`, `<=`, `>`, `>=` or `in`, combined with `&&` / `\|\|`; e.g. status in ["approved", "signing", "active"]). Absent, the entry votes on every row. Present, the entry votes as declared on the rows the condition matches and is ABSENT on every other row, so the most-permissive merge across the caller's sets is unchanged: a set that locks a field only from a stage onward does not lock the rows before it, and a co-held set that says nothing about the field still lifts nothing, unless it holds the super-user bypass on the object (its own entry for the object, otherwise its `'*'` wildcard). Such a set votes on every field of the object, on every row, whatever `when` says: `viewAllRecords` votes `readable: true`, and `modifyAllRecords` votes `readable: true` and `editable: true`, so a row-conditioned lock never binds a Modify All holder. View All never grants an edit. Otherwise union without deny is unchanged. The write gate judges the condition on the stored row BEFORE an update (so a lock on `status in [...]` holds on an approved row even when the write changes `status`) and on the incoming row of an insert, as the caller sent it. It reaches the EDIT vote only — reads are judged row-blind — so `readable: false` beside a `when` is refused at parse time: keep `readable: true` (the default) on a row-conditioned entry. Where no row can be judged (a predicate update with no row address, a stored row the caller cannot read, a condition that does not resolve for the request) the entry is judged as its lock: it contributes no edit grant on that write. Validated like an RLS predicate at authoring and publish time: the fields it names must exist on the entry's object and it may not reach across a relation; a condition that cannot be lowered is refused there, never dropped at runtime. Readers that hold no row (`/auth/me/permissions`, the object-wide field projections, the write preview on an update) report a row-conditioned entry as its lock, so a client never advertises an edit the gate refuses. The record-scoped field projection (`GET /data/{object}/{id}/field-access`, the answer a record's edit form reads) holds the row: it judges the condition on the stored row exactly as the write gate does on an update of that row, so a lock that applies only from a stage onward disables the field only on the rows it names. |
1742+
| **rollupSourceUnreadableReason** | `string` | optional | Authoring-time acknowledgement, read only by `os lint` (the runtime does not read it): why holders of this set are meant to read this roll-up `summary` column although the set cannot read the child object, the aggregated child field or a child field the roll-up's `filter` tests (e.g. 'Service staff read account totals but not invoice rows'). Declared on the set's entry for the summary column, it turns that set's `security-rollup-source-unreadable` warning for the column into an `info` note quoting the reason, so `os lint --strict` passes; every other finding is unchanged. The runtime does not read the key, but the entry that carries it is an ordinary declaring entry: it votes `readable: true` in the field merge (only declaring sets vote, and the most permissive vote wins), so on a set that had no entry for the column, adding one to carry the reason restores the column for holders whose other sets mask it. A blank reason is refused, and so is a reason beside `readable: false`, an entry that declares no read to acknowledge. |
17421743

17431744

17441745
---

0 commit comments

Comments
 (0)