diff --git a/.changeset/34664-rollup-source-unreadable-reason.md b/.changeset/34664-rollup-source-unreadable-reason.md new file mode 100644 index 00000000000..ce823c1ad78 --- /dev/null +++ b/.changeset/34664-rollup-source-unreadable-reason.md @@ -0,0 +1,12 @@ +--- +'@objectstack/spec': minor +'@objectstack/lint': minor +--- + +feat(spec, lint): a permission set can acknowledge a meant roll-up read with `rollupSourceUnreadableReason` + +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 + +`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. diff --git a/content/docs/data-modeling/fields.mdx b/content/docs/data-modeling/fields.mdx index fc836fae78b..a583b8ad41a 100644 --- a/content/docs/data-modeling/fields.mdx +++ b/content/docs/data-modeling/fields.mdx @@ -415,6 +415,25 @@ If the value should not be visible, set `readable: false` on the summary field i that set: it hides the field from every holder of the set, and another set they hold with no entry for the field does not restore it, so declare `readable: true` on the field in the sets whose holders should keep it. +If the set is meant to read the total without its children (an account total +shown to staff who may not see invoice rows), acknowledge that on the same entry +with the reason, and the warning for that set and column becomes a note quoting +it, so `os lint --strict` passes: + +```ts +fields: { + 'crm_account.invoiced_amount': { + readable: true, + rollupSourceUnreadableReason: 'Service staff read account totals but not invoice rows', + }, +}, +``` + +Only these authoring checks read the key. The entry that carries it is still an +ordinary field permission, though, and votes `readable: true`: on a set that had +no entry for the summary, adding one restores the column for holders whose other +sets mask it. Every other set and column is still reported, and a blank reason, +or one beside `readable: false`, is refused. A child validation rule can read a parent summary one hop through its reference, for example "each supplier has at most one primary contact" as a diff --git a/content/docs/deployment/validating-metadata.mdx b/content/docs/deployment/validating-metadata.mdx index d0adea624a1..110f929b7db 100644 --- a/content/docs/deployment/validating-metadata.mdx +++ b/content/docs/deployment/validating-metadata.mdx @@ -528,7 +528,7 @@ orthogonal to both, and no cell here can carry it; it is written out in | 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) | ✓ | ✓ | ✓ | ✓ᵖᵉᵒ | | Membership key declarations — `userField` / `valueField` columns, one key on one object, a key the registered resolver also owns (save door only) (#25234) | ✓ | ✓ | ✓ | ✓ᵒ | | Advisory: retired permission residue — the `allowRestore` / `allowPurge` default the parse strips in silence (`permission-retired-lifecycle-residue`, #17425) | ✓ | ✓ | ✓ | ✓ᵖᵉ | -| 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 | ✓ | ✓ | ✓ | — | +| 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 | ✓ | ✓ | ✓ | — | | Platform-schedule `create_record` organization (#6285) | — | — | — | ✓ᶠ | | Public-form anonymous intake on this deployment's tenancy posture — advisory only (#21476) | — | — | — | ✓ᵛ | | Public-form file fields — a form open to anonymous intake whose sections declare a `file`, `image`, `avatar`, `video` or `audio` field (#25650) | ✓ | ✓ | ✓ | ✓ᵛ | diff --git a/content/docs/protocol/objectql/security.mdx b/content/docs/protocol/objectql/security.mdx index 30242213d97..c60d513127f 100644 --- a/content/docs/protocol/objectql/security.mdx +++ b/content/docs/protocol/objectql/security.mdx @@ -219,7 +219,7 @@ rowLevelSecurity: ## 3. Field-Level Security -Field permissions are a map on the permission set keyed by `.`, each with two boolean flags and an optional row condition (`FieldPermissionSchema`): +Field permissions are a map on the permission set keyed by `.`, each with two boolean flags, an optional row condition and, on a roll-up summary column, an optional authoring-time acknowledgement (`FieldPermissionSchema`): ```yaml # sales_rep.permission.yml (continued) @@ -259,12 +259,15 @@ fields: readable: true | false # default true — can see the field editable: true | false # default false — can modify the field when: "status == 'approved'" # optional — a row condition on the EDIT vote, in RLS `using`'s CEL + 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) ``` > There is no separate `create` flag for fields. `editable` governs both create-time and update-time writes; read stripping is governed by `readable`. > `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). +> 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). + ### Static `readonly` fields on the write path `readonly: true` on a field definition is a *schema-level* lock, independent of permission diff --git a/content/docs/references/api/protocol.mdx b/content/docs/references/api/protocol.mdx index 4027b6a360b..d0570c4fd89 100644 --- a/content/docs/references/api/protocol.mdx +++ b/content/docs/references/api/protocol.mdx @@ -1711,7 +1711,7 @@ One changed key path of the pending draft, and the last write that changed it. | :--- | :--- | :--- | :--- | | **object** | `string` | ✅ | Object name | | **permissions** | `{ allowCreate?: boolean; allowRead?: boolean; allowEdit?: boolean; allowDelete?: boolean; … }` | ✅ | Object-level permissions | -| **fieldPermissions** | `Record` | optional | Field-level permissions keyed by field name | +| **fieldPermissions** | `Record` | optional | Field-level permissions keyed by field name | ### Nested Shape: `GetObjectPermissionsResponse.permissions` @@ -1739,6 +1739,7 @@ One changed key path of the pending draft, and the last write that changed it. | **readable** | `boolean` | optional (default: `true`) | Field read access | | **editable** | `boolean` | optional (default: `false`) | Field edit access | | **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. | +| **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. | --- diff --git a/content/docs/references/security/permission.mdx b/content/docs/references/security/permission.mdx index c8e367da4b4..3e61a15a3f8 100644 --- a/content/docs/references/security/permission.mdx +++ b/content/docs/references/security/permission.mdx @@ -72,6 +72,7 @@ const result = AdminScopeSchema.parse(data); | **readable** | `boolean` | optional (default: `true`) | Field read access | | **editable** | `boolean` | optional (default: `false`) | Field edit access | | **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. | +| **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. | --- @@ -126,7 +127,7 @@ const result = AdminScopeSchema.parse(data); | **managedBy** | `never` | optional | [REMOVED] `permission.managedBy` was removed in @objectstack/spec 18 (ADR-0049 enforce-or-remove, ADR-0086 D3) — nothing ever read the authored key: no seeder, package upgrade or lock consulted it, so `package` never made a set upgrade-owned and `platform` or `user` never shielded one from an upgrade. Delete the key; a set's provenance is the package that ships it, decided from that package's artifact and recorded as `packageId`, and a set authored in this system carries neither. Run `os migrate meta --from 17` to list the mechanical edits for existing sources; `--write` applies the ones it can prove, and you apply the rest by hand. | | **isDefault** | `boolean` | optional (default: `false`) | [ADR-0090 D5] App baseline for the everyone position: app-level sets are auto-bound at boot (guarded, idempotent); package-level sets become install-time suggestions an admin confirms | | **objects** | `Record` | ✅ | Entity permissions | -| **fields** | `Record` | optional | Field level security | +| **fields** | `Record` | optional | Field level security | | **systemPermissions** | `string[]` | optional | System level capabilities | | **tabPermissions** | `Record>` | optional | App/tab visibility: visible, hidden, default_on (shown by default), default_off (available but hidden initially) | | **rowLevelSecurity** | `{ name: string; label?: string; description?: string; object: string; … }[]` | optional | Row-level security policies (see rls.zod.ts for full spec) | @@ -166,6 +167,7 @@ const result = AdminScopeSchema.parse(data); | **readable** | `boolean` | optional (default: `true`) | Field read access | | **editable** | `boolean` | optional (default: `false`) | Field edit access | | **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. | +| **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. | ### Nested Shape: `PermissionSet.rowLevelSecurity[number]` diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index ad337d8e42a..fbb0271b6fa 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -1045,6 +1045,14 @@ const SECURITY_ROLLUP_SOURCE_UNREADABLE_EXPLANATION: RuleExplanation = { 'holders, declare `readable: true` on it in the sets they hold. A set that holds Modify All on the ' + 'parent must drop that bit first, because Modify All makes the entry inert. If the set may see ' + 'the child data, grant the read on the child instead.', + 'If the pair is meant, say so on the set: `fields: { \'.\': { readable: true, ' + + 'rollupSourceUnreadableReason: \'\' } }`. That one finding, ' + + 'for this set and this column, is then reported as a note that quotes the reason, so `--strict` passes ' + + 'and a reviewer still sees the pair and why it stands. Another set reading the same column, another ' + + 'column of the same set and the row-scope note are judged as before. The runtime does not read the key, ' + + 'but the entry that carries it is an ordinary declaring entry and votes `readable: true` in the field ' + + 'merge: on a set that had no entry for the column, adding one restores the column for holders whose ' + + 'other sets mask it. A blank reason, or a reason beside `readable: false`, is refused.', ], }; diff --git a/packages/lint/src/validate-rollup-source-visibility-acknowledged-34664.test.ts b/packages/lint/src/validate-rollup-source-visibility-acknowledged-34664.test.ts new file mode 100644 index 00000000000..e4211208da1 --- /dev/null +++ b/packages/lint/src/validate-rollup-source-visibility-acknowledged-34664.test.ts @@ -0,0 +1,164 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// #34664 — `security-rollup-source-unreadable` is advisory ("the pair is legal +// and is often meant"), and a meant pair is acknowledged where the finding +// points: the set's own entry for the summary column carries +// `rollupSourceUnreadableReason`. That one finding (this set × this column) +// is then an `info` note quoting the reason, so `--strict` passes; every other +// finding of the rule is unchanged. Positive legs go through the registry +// runner, as in the rule's main suite. +import { describe, expect, it } from 'vitest'; +import { PermissionSetSchema } from '@objectstack/spec/security'; + +import { runAuthoringRules } from './authoring-rules.js'; + +const UNREADABLE = 'security-rollup-source-unreadable'; +const ROW_SCOPED = 'security-rollup-source-row-scoped'; +const REASON = 'Warehouse staff read invoice totals but not line costs'; + +type Rec = Record; + +const invoice: Rec = { + name: 'invoice', + label: 'Invoice', + sharingModel: 'public_read', + fields: { + name: { type: 'text', label: 'Name' }, + total: { type: 'summary', label: 'Total', summaryOperations: { object: 'invoice_line', field: 'amount', function: 'sum' } }, + line_count: { type: 'summary', label: 'Line Count', summaryOperations: { object: 'invoice_line', function: 'count' } }, + }, +}; + +const invoiceLine: Rec = { + name: 'invoice_line', + label: 'Invoice Line', + sharingModel: 'public_read', + fields: { + name: { type: 'text', label: 'Name' }, + invoice: { type: 'master_detail', label: 'Invoice', reference: 'invoice', required: true, deleteBehavior: 'cascade' }, + amount: { type: 'currency', label: 'Amount' }, + }, +}; + +const READ = { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false }; + +/** A set that reads `invoice` and NOT `invoice_line`: both roll-ups warn. */ +const staff = (fields: Rec = {}, extra: Rec = {}): Rec => ({ + name: 'warehouse_staff', + label: 'Warehouse Staff', + objects: { invoice: READ }, + fields, + ...extra, +}); + +const run = (...permissions: Rec[]) => + runAuthoringRules('lint', { normalized: { objects: [invoice, invoiceLine], permissions } }).filter( + (f) => f.rule === UNREADABLE || f.rule === ROW_SCOPED, + ); + +const W = (set: string, column: string) => `permission set "${set}" · summary field "${column}"`; + +describe('rollupSourceUnreadableReason acknowledges one meant pair (#34664)', () => { + it('the control: without the reason, both roll-ups warn', () => { + const findings = run(staff()); + expect(findings.map((f) => [f.rule, f.where, f.severity])).toEqual([ + [UNREADABLE, W('warehouse_staff', 'invoice.total'), 'warning'], + [UNREADABLE, W('warehouse_staff', 'invoice.line_count'), 'warning'], + ]); + }); + + it('with the reason on the column entry, that finding is info, quotes the reason and points at the key', () => { + const findings = run(staff({ 'invoice.total': { readable: true, rollupSourceUnreadableReason: REASON } })); + expect(findings.map((f) => [f.rule, f.where, f.severity])).toEqual([ + [UNREADABLE, W('warehouse_staff', 'invoice.total'), 'info'], + // Another column of the same set is not acknowledged by it. + [UNREADABLE, W('warehouse_staff', 'invoice.line_count'), 'warning'], + ]); + const [acked] = findings; + expect(acked.message).toContain(`"${REASON}"`); + expect(acked.path).toBe('permissions[0].fields["invoice.total"].rollupSourceUnreadableReason'); + }); + + it('acknowledging every column leaves no warning, so --strict has nothing to fail on', () => { + const findings = run( + staff({ + 'invoice.total': { rollupSourceUnreadableReason: REASON }, + 'invoice.line_count': { rollupSourceUnreadableReason: REASON }, + }), + ); + expect(findings).toHaveLength(2); + expect(findings.every((f) => f.rule === UNREADABLE && f.severity === 'info')).toBe(true); + }); + + it("one set's acknowledgement does not speak for another set reading the same column", () => { + const other = { ...staff(), name: 'field_sales', label: 'Field Sales' }; + const findings = run(staff({ 'invoice.total': { rollupSourceUnreadableReason: REASON } }), other); + expect(findings.filter((f) => f.severity === 'warning').map((f) => f.where)).toEqual([ + W('warehouse_staff', 'invoice.line_count'), + W('field_sales', 'invoice.total'), + W('field_sales', 'invoice.line_count'), + ]); + }); + + it('a blank reason acknowledges nothing (the raw door; the schema refuses it on parse)', () => { + const findings = run(staff({ 'invoice.total': { rollupSourceUnreadableReason: ' ' } })); + expect(findings.every((f) => f.severity === 'warning')).toBe(true); + }); + + it('the row-scoped note is untouched by the key', () => { + const scoped = staff( + { 'invoice.total': { rollupSourceUnreadableReason: REASON } }, + { + objects: { invoice: READ, invoice_line: READ }, + rowLevelSecurity: [{ name: 'own_lines', object: 'invoice_line', operation: 'select', using: 'created_by == current_user.id' }], + }, + ); + const findings = run(scoped); + expect(findings.map((f) => [f.rule, f.severity])).toEqual([ + [ROW_SCOPED, 'info'], + [ROW_SCOPED, 'info'], + ]); + expect(findings[0].message).not.toContain(REASON); + }); + + it('the aggregated-field and filter-field arms are acknowledged the same way', () => { + const readsBoth = { invoice: READ, invoice_line: READ }; + // Aggregated-field arm: the set reads the child but hides `amount`. + const fieldArm = (fields: Rec) => run(staff({ 'invoice_line.amount': { readable: false }, ...fields }, { objects: readsBoth })); + expect(fieldArm({}).map((f) => [f.where, f.severity])).toEqual([[W('warehouse_staff', 'invoice.total'), 'warning']]); + expect(fieldArm({ 'invoice.total': { rollupSourceUnreadableReason: REASON } }).map((f) => [f.where, f.severity])).toEqual([ + [W('warehouse_staff', 'invoice.total'), 'info'], + ]); + // Filter-field arm: a count filtered on a field the set hides. + const banded = { + ...invoice, + fields: { + open_count: { + type: 'summary', + label: 'Open Lines', + summaryOperations: { object: 'invoice_line', function: 'count', filter: { band: 'open' } }, + }, + }, + }; + const line = { ...invoiceLine, fields: { ...(invoiceLine.fields as Rec), band: { type: 'text', label: 'Band' } } }; + const filterArm = (fields: Rec) => + runAuthoringRules('lint', { + normalized: { + objects: [banded, line], + permissions: [staff({ 'invoice_line.band': { readable: false }, ...fields }, { objects: readsBoth })], + }, + }).filter((f) => f.rule === UNREADABLE); + expect(filterArm({}).map((f) => f.severity)).toEqual(['warning']); + expect(filterArm({ 'invoice.open_count': { rollupSourceUnreadableReason: REASON } }).map((f) => f.severity)).toEqual(['info']); + }); + + it('the reason is quoted as a string literal, so a quote or a line break in it stays inside the quotes', () => { + const [f] = run(staff({ 'invoice.total': { rollupSourceUnreadableReason: 'Totals are "public"\nby design' } })); + expect(f.message.endsWith('Acknowledged on the set: "Totals are \\"public\\"\\nby design"')).toBe(true); + }); + + it('a parsed permission set answers what the raw one does', () => { + const parsed = PermissionSetSchema.parse(staff({ 'invoice.total': { rollupSourceUnreadableReason: REASON } })) as Rec; + expect(run(parsed).map((f) => f.severity)).toEqual(['info', 'warning']); + }); +}); diff --git a/packages/lint/src/validate-rollup-source-visibility.ts b/packages/lint/src/validate-rollup-source-visibility.ts index f68bab4a644..ec1ef56571f 100644 --- a/packages/lint/src/validate-rollup-source-visibility.ts +++ b/packages/lint/src/validate-rollup-source-visibility.ts @@ -7,6 +7,7 @@ * | Rule | Severity | Arm | * |----------------------------------------------|----------|---------------------------------------| * | security-rollup-source-unreadable | warning | the set cannot read the child object, the aggregated child field, or a child field the roll-up's `filter` tests | + * | security-rollup-source-unreadable | info | the same, acknowledged by the set's `rollupSourceUnreadableReason` on its entry for the summary column | * | security-rollup-source-row-scoped | info | the set reads all of those, but a row-level policy narrows WHICH child rows it reads | * * ## The rule it tells the author about @@ -32,6 +33,21 @@ * vote, so that entry hides the column from every holder of the set, and a * co-held set with no entry for it casts no vote that would restore it. * + * ## Acknowledging a meant pair (#34664) + * + * When the pair IS meant, the set says so where the finding points: its entry + * for the summary column carries `rollupSourceUnreadableReason`, a non-blank + * reason (`fields["invoice.total"]: { readable: true, + * rollupSourceUnreadableReason: '…' }`). That one finding — this set, this + * column — is then reported at `info`, under the same id, with the reason + * quoted, so `--strict` (which promotes warnings, never an `info`) passes and a + * reviewer still reads the pair and why it stands. Nothing else moves: another + * set reading the same column, another column of the same set, and the + * `row-scoped` note are judged as before. The key is the spec's + * (`FieldPermissionSchema`), which refuses a blank reason and a reason beside + * `readable: false`; the runtime does not read it, but the entry carrying it + * votes `readable: true` in the field merge like any declaring entry. + * * ## "Can read", as the runtime decides it * * Three gates decide whether a set reads an object or a field, and the rule @@ -368,6 +384,19 @@ function rollupPhrase(d: SummaryDescriptor, opts: { everyRow?: boolean; filtered return opts.everyRow ? `${column} counts every "${child}" row` : `${column} counts "${child}" records${filtered}`; } +/** + * [#34664] The reason the set's own entry for `column` declares for reading it + * over unreadable child data, or `undefined`. Read from the set's entry only: a + * co-held set's acknowledgement does not speak for this one. + */ +function acknowledgedReason(set: AnyRec, column: string): string | undefined { + const fields = isRec(set.fields) ? set.fields : undefined; + const entry = fields?.[column]; + if (!isRec(entry)) return undefined; + const reason = entry.rollupSourceUnreadableReason; + return nonBlank(reason) ? reason.trim() : undefined; +} + /** * The remedy, with its reach: in the field merge only DECLARING sets vote, so * `readable: false` on this set hides the column from every holder of the set, @@ -404,14 +433,27 @@ export function validateRollupSourceVisibility(stack: AnyRec): RollupSourceVisib if (objectUnreadable(set, d.parent) || fieldUnreadable(set, d.parent, d.field)) continue; const column = `${d.parent.name}.${d.field}`; - const unreadable = (message: string): RollupSourceVisibilityFinding => ({ - severity: 'warning', - rule: SECURITY_ROLLUP_SOURCE_UNREADABLE, - where: `permission set "${setName}" · summary field "${column}"`, - path: `permissions[${i}].fields["${column}"]`, - message: `${message}; ${ROLLUP_SEMANTICS}`, - hint: hintFor(set, d), - }); + const acknowledged = acknowledgedReason(set, column); + const unreadable = (message: string): RollupSourceVisibilityFinding => + acknowledged === undefined + ? { + severity: 'warning', + rule: SECURITY_ROLLUP_SOURCE_UNREADABLE, + where: `permission set "${setName}" · summary field "${column}"`, + path: `permissions[${i}].fields["${column}"]`, + message: `${message}; ${ROLLUP_SEMANTICS}`, + hint: hintFor(set, d), + } + : { + severity: 'info', + rule: SECURITY_ROLLUP_SOURCE_UNREADABLE, + where: `permission set "${setName}" · summary field "${column}"`, + path: `permissions[${i}].fields["${column}"].rollupSourceUnreadableReason`, + message: `${message}; ${ROLLUP_SEMANTICS}. Acknowledged on the set: ${JSON.stringify(acknowledged)}`, + hint: + `Nothing to change while the reason holds. If holders of permission set "${setName}" should no ` + + `longer read "${column}", remove rollupSourceUnreadableReason and the warning returns with its remedy`, + }; const objectGate = objectUnreadable(set, d.child); if (objectGate) { diff --git a/packages/spec/authorable-surface/security.json b/packages/spec/authorable-surface/security.json index 0ad5eb08778..f8ea48489fe 100644 --- a/packages/spec/authorable-surface/security.json +++ b/packages/spec/authorable-surface/security.json @@ -106,6 +106,7 @@ "security/ExplainRequest:userId", "security/FieldPermission:editable", "security/FieldPermission:readable", + "security/FieldPermission:rollupSourceUnreadableReason", "security/FieldPermission:when", "security/MembershipKey:description", "security/MembershipKey:filter", diff --git a/packages/spec/liveness/permission.json b/packages/spec/liveness/permission.json index e7e7cc824c7..21525576ad3 100644 --- a/packages/spec/liveness/permission.json +++ b/packages/spec/liveness/permission.json @@ -163,6 +163,13 @@ "evidenceScope": "in-repo", "evidence": "packages/plugins/plugin-security/src/permission-evaluator.ts#getFieldPermissions (the per-entry vote: `fieldPermissionVote(perm, when === undefined ? 'matched' : judge ? judge(when) : 'unjudged')` — a conditioned entry votes as declared on a matched row, is absent on an unmatched one, and is its lock when no row can be judged); packages/plugins/plugin-security/src/security-plugin-object-inputs.ts#computeForbiddenFieldWrites (the write gate's row judge: each distinct `when` compiled once by `RLSCompiler.compileRowPredicate` and judged in process by `storedFormCheckJudge` on each incoming row of an insert or the caller-read stored row of a by-id update); packages/plugins/plugin-security/src/rls-compiler.ts#compileRowPredicate (the compile: the same `current_user` context, field guard and comparand faces an RLS `check` clause takes); packages/core/src/security/effective-object-permissions.ts#fieldPermissionVote (the one vote the row-blind `/auth/me/permissions` merge shares); packages/plugins/plugin-security/src/explain-engine.ts#explainAccess (the `fls` layer names each row-conditioned entry as such); packages/lint/src/validate-rls-predicate-enforceability.ts#validateRlsPredicateEnforceability (the authoring judge: `permissions[].fields[].when` walked by the passes `using` / `check` take)", "note": "[#25866, ruling of record 6408558941] A row condition on the EDIT vote only, in RLS `using`'s CEL; `readable: false` beside it is refused at parse (`FieldPermissionSchema`'s object refine). ADR-0066 ⑧ note of 2026-10-26: the condition narrows where an entry votes and does not change the union-without-deny posture. Classified live on landing with the readers above; no dogfood proof bound yet (the plugin-security middleware battery in `security-plugin.test.ts` pins insert-on-payload, update-on-stored-row, predicate-update-as-lock and unresolvable-condition-as-lock)." + }, + "rollupSourceUnreadableReason": { + "status": "live", + "verifiedAt": "2026-11-17", + "evidenceScope": "in-repo", + "evidence": "packages/lint/src/validate-rollup-source-visibility.ts#acknowledgedReason (read on the set's own entry for a summary column; a non-blank reason turns that set's `security-rollup-source-unreadable` finding for the column from `warning` into `info`, quoting the reason, inside validateRollupSourceVisibility)", + "note": "[#34664] Build-time only, and that IS its contract: the key acknowledges a meant roll-up read over child data the set cannot read, so the lint reading it is the whole feature (the same posture as dashboard `widgets.suppressWarnings`). The runtime reads no part of it; `FieldPermissionSchema` refuses a blank reason and a reason beside `readable: false`. Pinned by packages/lint/src/validate-rollup-source-visibility-acknowledged-34664.test.ts." } } }, diff --git a/packages/spec/liveness/state-counts/permission.md b/packages/spec/liveness/state-counts/permission.md index 5bb935b4ee3..d27cb69f9d5 100644 --- a/packages/spec/liveness/state-counts/permission.md +++ b/packages/spec/liveness/state-counts/permission.md @@ -12,4 +12,4 @@ committed anywhere: `check:liveness` sums the shards when it reads them. | Type | live | exp | elsewhere | dead | planned | classified | |---|---|---|---|---|---|---| -| `permission` | 40 | 0 | 0 | 4 | 0 | 44 | +| `permission` | 41 | 0 | 0 | 4 | 0 | 45 | diff --git a/packages/spec/src/security/permission.test.ts b/packages/spec/src/security/permission.test.ts index 395ec5ebbd6..4f758bba5d7 100644 --- a/packages/spec/src/security/permission.test.ts +++ b/packages/spec/src/security/permission.test.ts @@ -896,6 +896,53 @@ describe('FieldPermissionSchema', () => { } }); }); + + // [#34664] The authoring-time acknowledgement `os lint` reads on a summary column's entry. + describe('`rollupSourceUnreadableReason` — a meant roll-up read, acknowledged', () => { + const REASON = 'Service staff read account totals but not invoice rows'; + + it('accepts a reason beside the default `readable`, and keeps it on the parsed entry', () => { + expect(FieldPermissionSchema.parse({ rollupSourceUnreadableReason: REASON })).toEqual({ + readable: true, + editable: false, + rollupSourceUnreadableReason: REASON, + }); + expect(FieldPermissionSchema.safeParse({ readable: true, rollupSourceUnreadableReason: REASON }).success).toBe(true); + }); + + it('an entry without it parses exactly as before (no key materialises)', () => { + expect(FieldPermissionSchema.parse({})).not.toHaveProperty('rollupSourceUnreadableReason'); + }); + + it('refuses a blank reason, and a non-string', () => { + for (const rollupSourceUnreadableReason of ['', ' ', '\n']) { + const result = FieldPermissionSchema.safeParse({ rollupSourceUnreadableReason }); + expect(result.success).toBe(false); + expect(result.error!.issues[0]!.message).toContain('A blank `rollupSourceUnreadableReason` acknowledges nothing'); + } + expect(FieldPermissionSchema.safeParse({ rollupSourceUnreadableReason: true }).success).toBe(false); + }); + + it('refuses a reason beside `readable: false` — the column is hidden, there is no read to acknowledge', () => { + const result = FieldPermissionSchema.safeParse({ readable: false, rollupSourceUnreadableReason: REASON }); + expect(result.success).toBe(false); + const issue = result.error!.issues.find((i) => i.path.join('.') === 'rollupSourceUnreadableReason'); + expect(issue?.message).toContain('refused beside `readable: false`'); + }); + + it('rides on a permission set under the summary column key', () => { + const ps = PermissionSetSchema.parse({ + name: 'service_staff', + objects: { crm_account: { allowRead: true } }, + fields: { 'crm_account.invoiced_amount': { readable: true, rollupSourceUnreadableReason: REASON } }, + }); + expect(ps.fields!['crm_account.invoiced_amount']).toEqual({ + readable: true, + editable: false, + rollupSourceUnreadableReason: REASON, + }); + }); + }); }); describe('PermissionSetSchema', () => { diff --git a/packages/spec/src/security/permission.zod.ts b/packages/spec/src/security/permission.zod.ts index e964c4ec19a..a0be23ecd1f 100644 --- a/packages/spec/src/security/permission.zod.ts +++ b/packages/spec/src/security/permission.zod.ts @@ -1031,6 +1031,21 @@ const FIELD_PERMISSION_WHEN_ON_READABLE = + 'row, or on none). Keep `readable: true` (the default) on a row-conditioned entry; to hide the field ' + 'on every row, declare `readable: false` on an entry without `when`.'; +/** + * [#34664] The two sentences an acknowledged roll-up read is refused with. + * Module-private for the reason {@link ADMIN_SCOPE_BUSINESS_UNIT_BLANK} gives. + */ +const FIELD_PERMISSION_ROLLUP_REASON_BLANK = + 'A blank `rollupSourceUnreadableReason` acknowledges nothing: write why holders of this set may read the ' + + 'roll-up summary although they cannot read the child data it aggregates, or remove the key so `os lint` ' + + 'keeps reporting the `security-rollup-source-unreadable` warning.'; + +const FIELD_PERMISSION_ROLLUP_REASON_ON_HIDDEN = + 'A `rollupSourceUnreadableReason` acknowledges that holders of this set READ a roll-up summary over child data ' + + 'they cannot read, so it is refused beside `readable: false`: that entry declares no read of the column, so there ' + + 'is nothing to acknowledge. Keep `readable: true` (the default) to acknowledge the read, or remove the reason to keep the ' + + 'column hidden.'; + /** * Field Level Security (FLS) * @@ -1055,6 +1070,20 @@ const FIELD_PERMISSION_WHEN_ON_READABLE = * at parse time — a per-row read lock the runtime would not deliver. The * cross-key rule is a refinement, declared as a dropped-refinement site; the * published JSON Schema states it in `when`'s description. + * + * [#34664] `rollupSourceUnreadableReason` is read at AUTHORING time only, by + * `os lint`'s `security-rollup-source-unreadable` rule: on the set's entry for + * a `summary` column it acknowledges a meant pair — this set reads the roll-up + * although it cannot read the child data the roll-up aggregates — and turns + * that one finding (this set × this column) into an `info` note quoting the + * reason. The runtime reads no part of the KEY, and the server never sends it + * on the permission responses that reuse this shape. The ENTRY that carries it + * is an ordinary declaring entry, though: it votes `readable: true` (its + * default) in the field merge, where 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, and a reason beside `readable: false` (the entry declares + * no read, so there is nothing to acknowledge), are refused at parse time. */ export const FieldPermissionSchema = lazySchema(() => strictObject( { @@ -1117,6 +1146,29 @@ export const FieldPermissionSchema = lazySchema(() => strictObject( + '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.', ), + /** + * [#34664] Why this set is MEANT to read a roll-up summary over child data it + * cannot read. Authoring-time only: `os lint` reads it on the set's entry for + * a `summary` column and reports `security-rollup-source-unreadable` for that + * set and column as an `info` note quoting the reason, instead of a warning + * `--strict` fails on. The runtime does not read the key; the entry carrying + * it votes `readable: true` in the field merge like any declaring entry. + */ + rollupSourceUnreadableReason: z.string() + .refine(NON_BLANK_STRING, { message: FIELD_PERMISSION_ROLLUP_REASON_BLANK }) + .optional() + .describe( + '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.', + ), }).refine( // The cross-key rule: a condition reaches the edit vote only, so an entry // that conditions a read lock is refused rather than enforced row-blind @@ -1127,6 +1179,12 @@ export const FieldPermissionSchema = lazySchema(() => strictObject( // dropped-refinements ledger. (p) => p.when === undefined || p.readable !== false, { message: FIELD_PERMISSION_WHEN_ON_READABLE, path: ['when'] }, +).refine( + // [#34664] The acknowledgement names a READ of the roll-up; beside a mask + // there is no read, so the declaration would promise nothing. Refused + // rather than ignored, the same shape as the `when` rule above. + (p) => p.rollupSourceUnreadableReason === undefined || p.readable !== false, + { message: FIELD_PERMISSION_ROLLUP_REASON_ON_HIDDEN, path: ['rollupSourceUnreadableReason'] }, )); /**