From 6da0b9560950e25db6919ed76bded1033bdbd010 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 14:23:46 +0000 Subject: [PATCH 1/4] fix(core, plugin-security, lint)!: a permission set's own field-mask row binds its own holders over that set's View All vote ADR-0066 D2 (8) is amended by the maintainer's ruling: an explicit `readable: false` field-permission row on a permission set wins over that same set's View All field vote. Both field merges ask one function for the per-field vote, so every reader answers the same. Another set's View All or Modify All still votes, and Modify All is unchanged. The lint rule that reports a mask its own set unbinds now reports only beside Modify All; its user text and rule explanation follow. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- ...-own-field-mask-binds-over-own-view-all.md | 23 +++ content/docs/permissions/authorization.mdx | 18 ++- .../docs/permissions/permissions-matrix.mdx | 2 +- docs/adr/0066-unified-authorization-model.md | 2 + .../effective-object-permissions.test.ts | 83 +++++++++++ .../security/effective-object-permissions.ts | 54 +++++-- packages/lint/src/finding-user-text.test.ts | 50 ++++--- packages/lint/src/rule-explanations.ts | 51 ++++--- .../validate-rollup-source-visibility.test.ts | 61 ++++++-- .../src/validate-rollup-source-visibility.ts | 21 +-- .../src/validate-security-posture.test.ts | 111 +++++++++----- .../lint/src/validate-security-posture.ts | 61 ++++---- .../validate-security-posture.user-text.ts | 71 ++++----- .../src/explain-principal-person.test.ts | 8 +- .../src/fls-superuser-vote.test.ts | 137 ++++++++++++++++-- .../src/permission-evaluator.ts | 22 ++- packages/spec/src/security/permission.zod.ts | 6 +- 17 files changed, 571 insertions(+), 210 deletions(-) create mode 100644 .changeset/33828-own-field-mask-binds-over-own-view-all.md diff --git a/.changeset/33828-own-field-mask-binds-over-own-view-all.md b/.changeset/33828-own-field-mask-binds-over-own-view-all.md new file mode 100644 index 00000000000..7428dcd3b2d --- /dev/null +++ b/.changeset/33828-own-field-mask-binds-over-own-view-all.md @@ -0,0 +1,23 @@ +--- +'@objectstack/core': patch +'@objectstack/plugin-security': patch +'@objectstack/lint': patch +'@objectstack/spec': patch +--- + +fix(core, plugin-security, lint)!: a permission set's own field-mask row binds its own holders over that set's View All vote + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +**BREAKING** for the holders of a permission set that grants View All (`viewAllRecords`) on an object and declares `readable: false` on a field of that object in its own `fields`. Per ADR-0066 D2 ⑧ as amended on 2026-11-15 (the maintainer's ruling on the card), that row wins over the same set's View All field vote: the set casts no read vote on the field, so a caller whom no other set serves the field to does not read it. Every reader of the field merge answers the same: the data doors, through `PermissionEvaluator.getFieldPermissions`, and the `fields` slot of `/auth/me/permissions`. Until this release the set's own View All voted the field readable, so the row bound none of the set's holders (the ADR's note of 2026-11-02). + +**Not moved.** Another set's View All or Modify All on the object still makes the field readable (and, under Modify All, editable) for a caller who holds both sets. A View All set still votes on every field it does not mask itself. An omitted `readable` parses to `true` and is not a mask. View All never granted an edit, so an edit lock beside it binds as before. Modify All is unchanged: a set holding `modifyAllRecords` on the object votes `readable: true` and `editable: true` on every field of it, its own rows included. The row-level bypass is untouched. + +**Who moves:** an administrator whose set pairs View All on an object with its own `readable: false` row for a field of that object, and whose holders are expected to keep reading the field. The row now hides the field from them, as it reads. Where the field is meant to be read, the row is the thing to delete. No default permission set the platform ships carries the pair. + +`@objectstack/lint`: `security-superuser-field-mask-inert` reports only a row that its own set's Modify All unbinds (a `readable: false`, an edit lock, or both). A `readable: false` beside the set's own View All is no longer reported, because it binds. The finding's `userTextParams` no longer carry `bypass` (Modify All is the only bypass the rule reports), and its message, hint and user sentence name Modify All. `security-controlled-by-parent-master-reference-hidden` is skipped only beside Modify All and is reported beside View All, and the roll-up source visibility rule reads a View All set's own mask as hiding the field. The rule ids are unchanged. + +`@objectstack/spec`: the doc comment above `FieldPermissionSchema` states the exception. No schema, description or generated artifact changes. diff --git a/content/docs/permissions/authorization.mdx b/content/docs/permissions/authorization.mdx index cd011053f67..04c0e645ff4 100644 --- a/content/docs/permissions/authorization.mdx +++ b/content/docs/permissions/authorization.mdx @@ -156,14 +156,18 @@ an **undeclared** field is visible by default, and field grants union (one set's `readable: true` out-votes another's `false`). A set that holds View All (`viewAllRecords`) on an object also votes `readable: true` on every field of that object, and a set that holds Modify All (`modifyAllRecords`) votes -`readable: true` and `editable: true`; View All never grants an edit. So no -set's `readable: false` hides a field from a caller who holds a View All or -Modify All set on its object; a field's `requiredPermissions` capability gate -still applies to every caller. Otherwise union without deny is unchanged. +`readable: true` and `editable: true`; View All never grants an edit. So +another set's `readable: false` never hides a field from a caller who also +holds a View All or Modify All set on its object; a field's +`requiredPermissions` capability gate still applies to every caller. One +exception: a View All set casts no read vote on a field its **own** +`readable: false` entry hides, so that entry binds the set's holders (unless +another set they hold reads the field). A Modify All set still votes on every +field, its own entries included. Otherwise union without deny is unchanged. Until the muting layer lands, protect sensitive fields by granting them only -in the sets that need them, grant the object without those two bits to a set -that must withhold a field from its own holders, and treat "sensitive field on -a public object" as a review smell. +in the sets that need them, grant the object without Modify All to a set that +must withhold a field from its own holders, and treat "sensitive field on a +public object" as a review smell. ## Package provenance & composition (ADR-0086) diff --git a/content/docs/permissions/permissions-matrix.mdx b/content/docs/permissions/permissions-matrix.mdx index c3f30ad4101..8da9870677c 100644 --- a/content/docs/permissions/permissions-matrix.mdx +++ b/content/docs/permissions/permissions-matrix.mdx @@ -143,7 +143,7 @@ Field-level security controls visibility and editability of individual fields pe | `opportunity.amount` | Visible, Editable | Visible, Editable | Visible, Editable | Visible | Visible | | `opportunity.margin` | Visible, Editable | Visible, Editable | Hidden | Hidden | Hidden | -**View All / Modify All reach every field.** The Sales Manager column follows from section 2: `sales_manager_access` holds `viewAllRecords` on `contact` and `modifyAllRecords` on `opportunity`, and a set holding View All on an object reads every field of it, while Modify All also edits every field (ADR-0066 D2 ⑧ as amended). Field rules in other sets cannot hide `contact.ssn` from that manager. To keep a field from someone, grant them the object without View All / Modify All and withhold the field there. +**View All / Modify All reach every field.** The Sales Manager column follows from section 2: `sales_manager_access` holds `viewAllRecords` on `contact` and `modifyAllRecords` on `opportunity`, and a set holding View All on an object reads every field of it that its own field rules do not hide, while Modify All reads and edits every field (ADR-0066 D2 ⑧ as amended). Field rules in other sets cannot hide `contact.ssn` from that manager. To keep a field from someone, withhold it in a set that grants the object without Modify All, and give them no other set that reads the field. ### FLS States diff --git a/docs/adr/0066-unified-authorization-model.md b/docs/adr/0066-unified-authorization-model.md index a93d4e49526..bac7e584296 100644 --- a/docs/adr/0066-unified-authorization-model.md +++ b/docs/adr/0066-unified-authorization-model.md @@ -140,6 +140,8 @@ Captured for the record; **out of scope for Phases 1–4 above**. Each is anchor > **Note (2026-10-28) — a third reader of `when` holds the row: the record-scoped field projection (#26594, ruling of record 6457467702, letter B).** `GET /api/v1/data/:object/:id/field-access` (`SecurityPlugin.getRecordFieldAccess`, the answer a record's edit form reads) judges each field permission's `when` against the **stored** row with the write gate's own function, `computeForbiddenFieldWrites`, asked as an update by id of that row naming every field over the same sets, posture and delegator intersection the gate takes — so its `editable` list is the gate's field-level verdict for that row, a conditioned lock disables a field only on the rows its condition names, and no second evaluator of `when` exists for it to drift from. The row-blind readers (`/auth/me/permissions`, the object-level field projections, `os explain`) are unchanged and still apply a conditioned entry as its lock, and `readable` stays row-blind. The record is read first exactly as `GET /api/v1/data/:object/:id` reads it, so an absent or unreadable row answers that read's refusal, and no reading is wider than the gate's. > **Note (2026-11-02) — a super-user set votes on every field of its object (#29106, ruling of record 6573563853, letter A).** In the field-permission merge, a permission set that holds the super-user bypass on an object now votes on **every** field of that object: `viewAllRecords` votes `readable: true`, and `modifyAllRecords` votes `readable: true` and `editable: true`. View All never grants an edit. Who holds the bypass is the row-level answer: the set's own entry for the object if it has one, otherwise its `'*'` wildcard. One function answers it, `holdsSuperuserBypass` (`packages/core/src/security/effective-object-permissions.ts`). `PermissionEvaluator.superuserBypassSets` reads it directly, and both field merges, `getFieldPermissions` and the row-blind `/auth/me/permissions` merge (`buildEffectiveFieldPermissions`), read it through `superuserFieldVote`. So every reader of the merge answers the same: the list projection, record read, the sort and filter gate, the field-level write gate, `/auth/me/permissions` and `os explain`. Before this, a set that granted the object through its super-user bits but declared no field entry cast no vote, so an app set's `readable: false` hid the field from a platform admin who also held the app set. Union without deny is otherwise unchanged. A caller who holds no super-user set on the object is still narrowed by a declared mask, and a field's `requiredPermissions` capability gate still applies to everyone. One consequence: a set can no longer withhold a field from its own View All / Modify All holders. To withhold a field, grant the object without those bits. Taking a field away from a super-user remains the job of the muting/deny layer ⑦ still owes. + + > **Note (2026-11-15) — a set's own `readable: false` row wins over that set's own View All vote (#33828, maintainer ruling on the card, letter A).** The ruling, as the card states it: "A, platform. An explicit `readable: false` field-permission row on a permission set must win over that same set's View All (`viewAllRecords`) field vote. This amends ADR-0066 D2 ⑧ as amended by ruling of record 6573563853." In the field-permission merge, a set that holds View All on an object (its own entry for the object if it has one, otherwise its `'*'` wildcard) and does not hold Modify All on it casts **no read vote on a field its own `fields` row declares `readable: false`**. That row is the set's whole say on the field, so a set can grant View All on an object and still hide a field of it from its holders. "Explicit" is literal: an omitted `readable` parses to `true` and is never a mask. The rest of the 2026-11-02 note stands. **Another** set's View All or Modify All on the object still makes the field readable (and, under Modify All, editable) for a caller who holds both sets, which is the platform-admin case ruling 6573563853 fixed. The same set's View All still votes on every field it does not mask itself. View All never granted an edit, so an edit lock beside it binds as before. **Modify All is unchanged, pending a ruling:** a set that holds `modifyAllRecords` on the object still votes `readable: true` and `editable: true` on every field of it, its own rows included, so its own `readable: false` or edit lock binds none of its holders. This note replaces, **for View All only**, the 2026-11-02 note's sentence "a set can no longer withhold a field from its own View All / Modify All holders"; for Modify All that sentence still holds, and a field is withheld from a Modify All set's holders by granting the object without that bit. One function answers the per-field vote, `superuserFieldVote` (`packages/core/src/security/effective-object-permissions.ts`), asked with the field's name by both field merges, `getFieldPermissions` and the row-blind `/auth/me/permissions` merge (`buildEffectiveFieldPermissions`), so every reader of the merge answers the same. The lint rule `security-superuser-field-mask-inert` reports only a row its own set's Modify All unbinds; a `readable: false` beside the set's own View All is no longer reported. Taking a field away from a caller whom another set serves it to remains the job of the muting/deny layer ⑦ still owes. - **⑨ Authoring-time validation for capability references** *(recorded 2026-07 pre-launch architecture assessment)*. `systemPermissions` / `requiredPermissions` are free strings today; a typo (`mange_users`) fails closed at runtime — the safe direction — but is undiscoverable: nothing reports that the referenced capability exists nowhere. When D1 lands the `sys_permission` registry, add the authoring/publish-gate lint alongside it: referencing an unregistered capability warns at author time (consistent with ADR-0049 honesty and the contract-first Prime Directive — reject at the producer, don't tolerate at the consumer). **Landed (2026-07):** `validateCapabilityReferences` in `@objectstack/lint` warns (never errors — cross-package capabilities and the fail-closed runtime make a hard gate wrong) when a `requiredPermissions` reference resolves against neither the built-in set (`@objectstack/spec` `PLATFORM_CAPABILITY_NAMES`), nor a capability the stack grants via a permission set's `systemPermissions`, nor a `sys_capability` seed row. Wired into `os validate` and `os lint`. `systemPermissions` (the declaration side) is deliberately not flagged. > **Note (2026-10-14) — ⑨'s seed-row source is gone.** With `sys_capability` retired by #15204 diff --git a/packages/core/src/security/effective-object-permissions.test.ts b/packages/core/src/security/effective-object-permissions.test.ts index 4d79b28a5cf..057118becf3 100644 --- a/packages/core/src/security/effective-object-permissions.test.ts +++ b/packages/core/src/security/effective-object-permissions.test.ts @@ -23,6 +23,7 @@ import { holdsSuperuserBypass, registryObjectPackageDisabled, servedObjectPermissions, + superuserFieldVote, } from './effective-object-permissions.js'; describe('buildEffectiveObjectPermissions', () => { @@ -909,6 +910,88 @@ describe('buildEffectiveFieldPermissions (#25866)', () => { }); }); + // [ADR-0066 D2 ⑧ note of 2026-11-15] A set's own explicit `readable: false` + // row is that set's vote on the field: its own View All casts no read vote + // there. Another set's bypass still votes (ruling of record 6573563853's + // admin case), and a Modify All set still votes on every field. + describe('a set\'s own readable: false row and that set\'s own super-user vote', () => { + const viewAll = (fields: Record, objects: Record = { deal: { allowRead: true, viewAllRecords: true } }) => + ({ objects, fields }); + const mask = { 'deal.amount': { readable: false, editable: false } }; + + it('View All beside the set\'s own readable: false row: the row binds, by the object entry and by the wildcard', () => { + expect(buildEffectiveFieldPermissions([viewAll(mask)])).toEqual({ 'deal.amount': { readable: false, editable: false } }); + expect(buildEffectiveFieldPermissions([viewAll(mask, { '*': { viewAllRecords: true } })])).toEqual({ + 'deal.amount': { readable: false, editable: false }, + }); + // Two holders of the pair, each masking the field itself: nobody votes it readable. + expect(buildEffectiveFieldPermissions([viewAll(mask), viewAll(mask)])).toEqual({ + 'deal.amount': { readable: false, editable: false }, + }); + }); + + it('the same set\'s View All still votes on the fields it does not mask itself', () => { + // `deal.stage` is masked by ANOTHER set; this set's View All reads it as before. + expect(buildEffectiveFieldPermissions([ + viewAll(mask), + { objects: { deal: { allowRead: true } }, fields: { 'deal.stage': { readable: false, editable: false } } }, + ])).toEqual({ + 'deal.amount': { readable: false, editable: false }, + 'deal.stage': { readable: true, editable: false }, + }); + }); + + it('reverse pin: another set\'s View All or Modify All on the object still reads the masked field', () => { + expect(buildEffectiveFieldPermissions([viewAll(mask), { objects: { deal: { viewAllRecords: true } } }])).toEqual({ + 'deal.amount': { readable: true, editable: false }, + }); + expect(buildEffectiveFieldPermissions([viewAll(mask), { objects: { '*': { viewAllRecords: true } } }])).toEqual({ + 'deal.amount': { readable: true, editable: false }, + }); + expect(buildEffectiveFieldPermissions([viewAll(mask), { objects: { deal: { modifyAllRecords: true } } }])).toEqual({ + 'deal.amount': { readable: true, editable: true }, + }); + // Another set's declared `readable: true` still out-votes the mask: union without deny. + expect(buildEffectiveFieldPermissions([viewAll(mask), { fields: { 'deal.amount': { readable: true, editable: false } } }])) + .toEqual({ 'deal.amount': { readable: true, editable: false } }); + }); + + it('Modify All is unchanged: it votes on every field, the set\'s own rows included', () => { + const modifyAll = { deal: { allowRead: true, allowEdit: true, modifyAllRecords: true } }; + expect(buildEffectiveFieldPermissions([{ objects: modifyAll, fields: mask }])).toEqual({ + 'deal.amount': { readable: true, editable: true }, + }); + expect(buildEffectiveFieldPermissions([{ objects: modifyAll, fields: { 'deal.amount': { readable: true, editable: false } } }])) + .toEqual({ 'deal.amount': { readable: true, editable: true } }); + // Both bits on one entry: the Modify All vote is the one that counts. + expect(buildEffectiveFieldPermissions([ + { objects: { deal: { viewAllRecords: true, modifyAllRecords: true } }, fields: mask }, + ])).toEqual({ 'deal.amount': { readable: true, editable: true } }); + }); + + it('an edit lock beside View All binds as it always did, and only an explicit false is a mask', () => { + expect(buildEffectiveFieldPermissions([viewAll({ 'deal.amount': { readable: true, editable: false } })])).toEqual({ + 'deal.amount': { readable: true, editable: false }, + }); + // An unparsed row that omits `readable` is not an explicit mask: the vote stands. + expect(buildEffectiveFieldPermissions([viewAll({ 'deal.amount': { editable: false } })])).toEqual({ + 'deal.amount': { readable: true, editable: false }, + }); + }); + + it('superuserFieldVote: per field with a field name, object-wide without one', () => { + const sets = [viewAll(mask)]; + expect(superuserFieldVote(sets, 'deal', 'amount')).toBeNull(); + expect(superuserFieldVote(sets, 'deal', 'stage')).toEqual({ readable: true, editable: false }); + expect(superuserFieldVote(sets, 'deal')).toEqual({ readable: true, editable: false }); + expect(superuserFieldVote([{ objects: { deal: { modifyAllRecords: true } }, fields: mask }], 'deal', 'amount')) + .toEqual({ readable: true, editable: true }); + // The mask is read on the set that declares it, never on a sibling. + expect(superuserFieldVote([{ objects: { deal: { viewAllRecords: true } } }, { fields: mask }], 'deal', 'amount')) + .toEqual({ readable: true, editable: false }); + }); + }); + it('holdsSuperuserBypass: explicit entry first, then the wildcard; modify implies view, view never implies modify', () => { expect(holdsSuperuserBypass({ objects: { '*': { viewAllRecords: true } } }, 'deal', 'view')).toBe(true); expect(holdsSuperuserBypass({ objects: { '*': { viewAllRecords: true } } }, 'deal', 'modify')).toBe(false); diff --git a/packages/core/src/security/effective-object-permissions.ts b/packages/core/src/security/effective-object-permissions.ts index 805315dec61..5b14742f188 100644 --- a/packages/core/src/security/effective-object-permissions.ts +++ b/packages/core/src/security/effective-object-permissions.ts @@ -1038,22 +1038,56 @@ export function holdsSuperuserBypass( * narrowed by a declared mask as before. Applied to the fields the merge * already holds an entry for; an absent field is unrestricted anyway. * - * Both merges apply it after their declared-entry votes — + * [ADR-0066 D2 ⑧ note of 2026-11-15] With `fieldName`, the vote is the one cast + * on that field: a set that holds View All on the object WITHOUT Modify All + * casts no read vote on a field its OWN row declares `readable: false` + * ({@link declaresOwnReadMask}), so a set can grant View All on an object and + * still hide a field of it from its holders. Every other vote stands: + * another set's View All or Modify All still reads the field (the admin case + * above), and a set holding Modify All votes on every field as before, its + * own rows included. View All never granted an edit, so an edit lock beside + * it binds as it always did. Without `fieldName` the answer is the object-wide + * one, for a reader that asks only whether an edit vote exists. + * + * Both merges apply it per field after their declared-entry votes — * `PermissionEvaluator.getFieldPermissions` per object and * {@link buildEffectiveFieldPermissions} for every object. */ export function superuserFieldVote( - sets: ReadonlyArray<{ objects?: Record | null } | null | undefined>, + sets: ReadonlyArray< + { objects?: Record | null; fields?: Record | null } | null | undefined + >, objectName: string, + fieldName?: string, ): { readable: true; editable: boolean } | null { let read = false; for (const ps of sets) { if (holdsSuperuserBypass(ps, objectName, 'modify')) return { readable: true, editable: true }; - if (!read && holdsSuperuserBypass(ps, objectName, 'view')) read = true; + if (read || !holdsSuperuserBypass(ps, objectName, 'view')) continue; + if (fieldName !== undefined && declaresOwnReadMask(ps, objectName, fieldName)) continue; + read = true; } return read ? { readable: true, editable: false } : null; } +/** + * [ADR-0066 D2 ⑧ note of 2026-11-15] Does `set`'s own field-permission row on + * `.` spell `readable: false`? Explicit only: an + * omitted `readable` parses to `true`, so the default is never a mask. Read + * row-blind, as the read bit is everywhere (the spec refuses `readable: false` + * beside a `when`). + */ +function declaresOwnReadMask( + set: { fields?: Record | null } | null | undefined, + objectName: string, + fieldName: string, +): boolean { + const fields = set?.fields; + if (!fields || typeof fields !== 'object') return false; + const entry = fields[`${objectName}.${fieldName}`] as FieldPermissionEntryLike | null | undefined; + return !!entry && typeof entry === 'object' && entry.readable === false; +} + /** A resolved permission set, as far as the field merge reads it. */ export interface EffectiveFieldPermissionsInputSet { fields?: Record | null; @@ -1072,7 +1106,9 @@ export interface EffectiveFieldPermissionsInputSet { * admits on the rows the condition does not name. * * A set holding the super-user bypass on an object then votes on every field - * of it ({@link superuserFieldVote}, ruling of record 6573563853). + * of it ({@link superuserFieldVote}, ruling of record 6573563853), except + * that a View All set casts no read vote on a field its own row declares + * `readable: false` (ADR-0066 D2 ⑧ note of 2026-11-15). * * Every entry is a FRESH object, as {@link buildEffectiveObjectPermissions}'s are. */ @@ -1092,15 +1128,13 @@ export function buildEffectiveFieldPermissions( fields[key] = acc; } } - // [Ruling of record 6573563853] The super-user vote, per object the map - // names — the same function `getFieldPermissions` applies per object. - const votes = new Map>(); + // [Ruling of record 6573563853; ADR-0066 D2 ⑧ note of 2026-11-15] The + // super-user vote, per field the map names — the same function + // `getFieldPermissions` applies per field of its object. for (const [key, acc] of Object.entries(fields)) { const dot = key.indexOf('.'); if (dot <= 0) continue; - const objectName = key.slice(0, dot); - if (!votes.has(objectName)) votes.set(objectName, superuserFieldVote(sets, objectName)); - const vote = votes.get(objectName); + const vote = superuserFieldVote(sets, key.slice(0, dot), key.slice(dot + 1)); if (!vote) continue; acc.readable = true; if (vote.editable) acc.editable = true; diff --git a/packages/lint/src/finding-user-text.test.ts b/packages/lint/src/finding-user-text.test.ts index f1a00552570..177a3ce4940 100644 --- a/packages/lint/src/finding-user-text.test.ts +++ b/packages/lint/src/finding-user-text.test.ts @@ -216,7 +216,7 @@ const CASES: ReadonlyArray<{ label: string; rule: string; stack: Record { /** The params that are NAMES the sentence must show (not the variant selectors). */ const namesOf = (params: Record): string[] => Object.entries(params) - .filter(([key, value]) => key !== 'bypass' && key !== 'remedy' && key !== 'inert' && value !== '') + .filter(([key, value]) => key !== 'remedy' && key !== 'inert' && value !== '') .map(([, value]) => value); describe('security-posture user text · the catalog', () => { @@ -389,24 +389,26 @@ describe('security-posture user text · rendered from the rule\'s real findings' expect(addOwner).toContain('Give "omd_obligation" a record owner (owner_id)'); }); - it('names the bypass the set actually holds', () => { - const [modifyLock, modifyBoth, view] = CASES.filter((c) => c.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT) + it('names the one bypass the rule reports, Modify All, and never View All', () => { + const sentences = CASES.filter((c) => c.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT) .map((c) => findingUserMessage(findingOf(c), ['en'])!); - for (const modify of [modifyLock!, modifyBoth!]) expect(modify).toContain('Modify All Records'); - expect(view).toContain('View All Records'); - expect(view).not.toContain('Modify All Records'); + expect(sentences).toHaveLength(3); + for (const sentence of sentences) { + expect(sentence).toContain('Modify All Records'); + expect(sentence).not.toContain('View All Records'); + } }); - it('calls ineffective only the half of the field restriction the bypass unbinds, as the rule\'s message does', () => { - const [modifyLock, modifyBoth, view] = CASES.filter((c) => c.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT) + it('calls ineffective only the half of the field restriction Modify All unbinds, as the rule\'s message does', () => { + const [modifyLock, modifyBoth, modifyMask] = CASES.filter((c) => c.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT) .map((c) => findingUserMessage(findingOf(c), ['en'])!); - // View All beside a read mask and an edit lock: only the mask is inert. - // The lock still binds, so the sentence neither calls the restriction - // ineffective as a whole nor prescribes deleting it. - expect(view).toContain('hiding field "sys_user.email" has no effect'); - expect(view).not.toContain('read-only'); - expect(view).not.toContain('delete the field restriction'); - expect(view).toContain('let the set read the field'); + // Modify All beside a read mask on an editable row: only the mask is + // inert, so the sentence neither names a read-only half nor prescribes + // deleting the restriction. + expect(modifyMask).toContain('hiding field "sys_user.email" has no effect'); + expect(modifyMask).not.toContain('read-only'); + expect(modifyMask).not.toContain('delete the field restriction'); + expect(modifyMask).toContain('let the set read the field'); // Modify All beside an edit lock alone: the lock is inert. expect(modifyLock).toContain('making field "deal.restricted_note" read-only has no effect'); expect(modifyLock).not.toContain('hiding'); @@ -417,11 +419,11 @@ describe('security-posture user text · rendered from the rule\'s real findings' }); it('renders the three field-restriction sentences apart in every platform locale', () => { - // Same names and the same bypass, so only `inert` tells the three apart. + // Same names, so only `inert` tells the three apart. const findings = CASES.filter((c) => c.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT).map(findingOf); for (const tag of PLATFORM_LOCALE_TAGS) { - const [lock, both, view] = findings.map((f) => findingUserMessage({ ...f, userTextParams: { ...f.userTextParams!, permissionSet: 'p', field: 'f', object: 'o', bypass: 'modify' } }, [tag])!); - expect(new Set([lock, both, view]).size, tag).toBe(3); + const [lock, both, mask] = findings.map((f) => findingUserMessage({ ...f, userTextParams: { ...f.userTextParams!, permissionSet: 'p', field: 'f', object: 'o' } }, [tag])!); + expect(new Set([lock, both, mask]).size, tag).toBe(3); } }); }); diff --git a/packages/lint/src/rule-explanations.ts b/packages/lint/src/rule-explanations.ts index 6ad0ac34bc1..8863b5f91fa 100644 --- a/packages/lint/src/rule-explanations.ts +++ b/packages/lint/src/rule-explanations.ts @@ -797,8 +797,9 @@ const SECURITY_CBP_MASTER_REFERENCE_HIDDEN_EXPLANATION: RuleExplanation = { 'writer has no way to tell from the refusal which record to ask for access to.', 'Reported for each permission set whose own entry for the master reference reads `readable: false` (an ' + 'omitted `readable` is `true`), on a detail this stack declares with one master. Not reported when the ' + - 'same set holds View All or Modify All on the detail, because that bit makes the entry inert ' + - '(`security-superuser-field-mask-inert`).', + 'same set holds Modify All on the detail, because that bit makes the entry inert ' + + '(`security-superuser-field-mask-inert`). Reported beside View All alone, where the set\'s own ' + + '`readable: false` binds.', 'This is a warning, not an error: hiding the reference is legal and no door refuses it. To fix it, make ' + 'the reference readable (`readable: true`, or delete the entry) when the set\'s holders should see why ' + 'a write is refused. Keep it hidden when a generic refusal is what is meant.', @@ -959,25 +960,29 @@ const SECURITY_MODIFY_ALL_DELETE_WITHHELD_EXPLANATION: RuleExplanation = { const SECURITY_SUPERUSER_FIELD_MASK_INERT_EXPLANATION: RuleExplanation = { rule: 'security-superuser-field-mask-inert', - covers: 'why a field mask beside View All or Modify All hides nothing', - paragraphs: [ - '`viewAllRecords` (View All) and `modifyAllRecords` (Modify All) are the super-user bypass on an object. ' + - 'A set that holds one votes on every field of that object when the field permissions are merged: View ' + - 'All votes `readable: true`, Modify All votes `readable: true` and `editable: true` (ADR-0066 D2 as ' + - 'amended). The merge is a union, so a `readable: false` the same set declares on that object hides the ' + - 'field from none of the set\'s holders, and under Modify All its edit lock (`editable: false`, or ' + - '`editable` omitted, which parses to false) holds none of them back either. The stored set still reads ' + - 'as masked, which is why an author or a reviewer takes the field to be protected.', + covers: 'why a field mask beside Modify All restricts nothing', + paragraphs: [ + '`modifyAllRecords` (Modify All) is the super-user write bypass on an object. A set that holds it votes ' + + 'on every field of that object when the field permissions are merged: `readable: true` and ' + + '`editable: true`, on its own field entries too (ADR-0066 D2 as amended). The merge is a union, so a ' + + '`readable: false` the same set declares on that object hides the field from none of the set\'s ' + + 'holders, and its edit lock (`editable: false`, or `editable` omitted, which parses to false) holds ' + + 'none of them back either. The stored set still reads as masked, which is why an author or a reviewer ' + + 'takes the field to be protected.', + '`viewAllRecords` (View All) alone is not reported. It votes only `readable: true`, and it casts no ' + + 'vote on a field the same set declares `readable: false`, so a set can grant View All on an object ' + + 'and still hide a field of it from its holders. View All never widens a write, so an edit lock beside ' + + 'it binds as well.', 'The set\'s bypass is read the way the runtime reads it: its own entry for the object when it has one, ' + - 'otherwise its `\'*\'` entry, as a lookup and never a merge. View All beside an edit lock is not ' + - 'reported, because View All never widens a write, so that lock still binds. Only the set that declares ' + - 'the entry is judged: a holder of two sets is unmasked by the other set\'s bypass too, but no author ' + - 'wrote an inert entry there.', + 'otherwise its `\'*\'` entry, as a lookup and never a merge. Only the set that declares the entry is ' + + 'judged: a holder of two sets is unmasked by the other set\'s View All or Modify All too, but no ' + + 'author wrote an inert entry there.', 'This is a warning, not an error: the pair is legal and no door refuses it. To fix it, decide which half ' + - 'is meant. If the field must stay hidden or read-only, remove the bypass bit from the object entry and ' + - 'reach every row another way, with `readScope: \'org\'` / `writeScope: \'org\'` on the entry or a ' + - '`rowLevelSecurity` policy whose condition every row satisfies; the mask then binds. If the bypass is ' + - 'meant, delete the field entry, which never took effect.', + 'is meant. If the field must stay hidden or read-only, remove `modifyAllRecords` from the object entry ' + + 'and reach every row another way, with `readScope: \'org\'` / `writeScope: \'org\'` on the entry or a ' + + '`rowLevelSecurity` policy whose condition every row satisfies; the mask then binds. `viewAllRecords` ' + + 'may stay, since the set\'s own `readable: false` binds beside it. If the bypass is meant, delete the ' + + 'field entry, which never took effect.', ], }; @@ -1019,8 +1024,8 @@ const SECURITY_ROLLUP_SOURCE_UNREADABLE_EXPLANATION: RuleExplanation = { 'minimum, maximum or count of child values it cannot read one by one.', '"Can read" is judged as the runtime decides it, through three gates. The object grant: the set\'s own ' + 'entry for the object, otherwise its `\'*\'` entry, which covers a private object only with View All ' + - 'or Modify All. The field entry: `readable: false` hides the field, unless the set holds View All or ' + - 'Modify All on the object; a set with no entry for a field reads it. The capability gate: an object\'s ' + + 'or Modify All. The field entry: `readable: false` hides the field, unless the set holds Modify All ' + + 'on the object; a set with no entry for a field reads it. The capability gate: an object\'s ' + '`requiredPermissions` (the list, or the `read` bucket of the per-operation map) and a field\'s ' + '`requiredPermissions` refuse the read unless the set\'s `systemPermissions` hold every listed ' + 'capability. View All and Modify All do not lift the capability gate, so a set holding them on the ' + @@ -1037,8 +1042,8 @@ const SECURITY_ROLLUP_SOURCE_UNREADABLE_EXPLANATION: RuleExplanation = { 'column from every holder of the set, and a co-held set with no entry for the column does not restore ' + 'it, because only sets that declare an entry vote in the field merge (View All or Modify All on the ' + 'parent in a co-held set does restore it); to keep the column for some ' + - 'holders, declare `readable: true` on it in the sets they hold. A set that holds View All or Modify All ' + - 'on the parent must drop that bit first, because the bypass makes the entry inert. If the set may see ' + + '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.', ], }; diff --git a/packages/lint/src/validate-rollup-source-visibility.test.ts b/packages/lint/src/validate-rollup-source-visibility.test.ts index a167c41db86..4b329afc273 100644 --- a/packages/lint/src/validate-rollup-source-visibility.test.ts +++ b/packages/lint/src/validate-rollup-source-visibility.test.ts @@ -265,17 +265,17 @@ describe('silent where the set cannot see the roll-up, or can see its source', ( expect(viaRegistry(stackOf(set({ objects: {} })))).toEqual([]); }); - it('View All or Modify All on the child makes a hidden child field readable', () => { - for (const bit of ['viewAllRecords', 'modifyAllRecords']) { + it('Modify All on the child makes a hidden child field readable', () => { + for (const bits of [{ modifyAllRecords: true }, { viewAllRecords: true, modifyAllRecords: true }]) { const findings = viaRegistry( stackOf( set({ - objects: { invoice: READ, invoice_line: { ...READ, [bit]: true } }, + objects: { invoice: READ, invoice_line: { ...READ, ...bits } }, fields: { 'invoice_line.amount': { readable: false } }, }), ), ); - expect(findings, bit).toEqual([]); + expect(findings, JSON.stringify(bits)).toEqual([]); } }); @@ -504,20 +504,55 @@ describe('the fields a roll-up filter tests are judged like the aggregated field }); }); -describe('a View All parent makes the summary mask inert', () => { - it('is still reported, and the hint says the bypass must go first', () => { +describe('a Modify All parent makes the summary mask inert', () => { + it('is still reported, and the hint says Modify All must go first', () => { const findings = viaRegistry( stackOf( set({ - objects: { invoice: { ...READ, viewAllRecords: true } }, + objects: { invoice: { ...READ, modifyAllRecords: true } }, fields: { 'invoice.total': { readable: false } }, }), ), ); expect(findings.map((f) => f.where)).toContain(W_TOTAL); const f = findings.find((x) => x.where === W_TOTAL)!; - expect(f.hint).toContain('first remove View All and Modify All on "invoice" from it'); - expect(f.hint).toContain('does not hide a field from a set holding either'); + expect(f.hint).toContain('first remove Modify All on "invoice" from it'); + expect(f.hint).toContain('does not hide a field from a set holding it'); + }); +}); + +// ADR-0066 D2 ⑧ note of 2026-11-15: a set's own `readable: false` binds beside +// its own View All, on the parent and on the child alike. +describe('a View All set\'s own mask binds', () => { + it('on the parent: the masked summary column is not judged, and the unmasked one still is', () => { + const findings = viaRegistry( + stackOf( + set({ + objects: { invoice: { ...READ, viewAllRecords: true } }, + fields: { 'invoice.total': { readable: false } }, + }), + ), + ); + // The set reads no child object here, so the column it can still see is reported. + expect(pairs(findings)).toEqual([[UNREADABLE, W_COUNT]]); + }); + + it('on the child: the hidden aggregated field is unreadable, so the sum over it is reported', () => { + const findings = viaRegistry( + stackOf( + set({ + objects: { invoice: READ, invoice_line: { ...READ, viewAllRecords: true } }, + fields: { 'invoice_line.amount': { readable: false } }, + }), + ), + ); + expect(pairs(findings)).toEqual([[UNREADABLE, W_TOTAL]]); + }); + + it('a View All parent with no mask gets the plain remedy: the mask it names will bind', () => { + const [f] = viaRegistry(stackOf(set({ objects: { invoice: { ...READ, viewAllRecords: true } } }))); + expect(f.hint).not.toContain('first remove'); + expect(f.hint).toContain('set fields["invoice.total"]: { readable: false } on it'); }); }); @@ -565,11 +600,11 @@ describe('the verdict text (the rule the author is told)', () => { ] `); - const viewAllParent = validateRollupSourceVisibility( - stackOf(set({ objects: { invoice: { ...READ, viewAllRecords: true } } })), + const modifyAllParent = validateRollupSourceVisibility( + stackOf(set({ objects: { invoice: { ...READ, modifyAllRecords: true } } })), ); - expect(viewAllParent.map((f) => f.hint)[0]).toMatchInlineSnapshot( - `"If its value should not be visible to this set, first remove View All and Modify All on "invoice" from it, since fields["invoice.total"]: { readable: false } does not hide a field from a set holding either, then set fields["invoice.total"]: { readable: false } on it. That hides "invoice.total" from every holder of the set, and a co-held set with no entry for it does not restore it (View All or Modify All on "invoice" does); to keep it for some holders, declare fields["invoice.total"]: { readable: true } in the sets they hold"`, + expect(modifyAllParent.map((f) => f.hint)[0]).toMatchInlineSnapshot( + `"If its value should not be visible to this set, first remove Modify All on "invoice" from it, since fields["invoice.total"]: { readable: false } does not hide a field from a set holding it, then set fields["invoice.total"]: { readable: false } on it. That hides "invoice.total" from every holder of the set, and a co-held set with no entry for it does not restore it (View All or Modify All on "invoice" does); to keep it for some holders, declare fields["invoice.total"]: { readable: true } in the sets they hold"`, ); const scoped = validateRollupSourceVisibility( diff --git a/packages/lint/src/validate-rollup-source-visibility.ts b/packages/lint/src/validate-rollup-source-visibility.ts index f5a9fc04d6d..f68bab4a644 100644 --- a/packages/lint/src/validate-rollup-source-visibility.ts +++ b/packages/lint/src/validate-rollup-source-visibility.ts @@ -41,9 +41,10 @@ * entry, which covers a `private` object only when it carries View All / * Modify All ({@link grantFor}, `resolveObjectPermission`); * - the field entry: `readable: false` hides the field, unless the set's - * View All / Modify All on the object votes every field readable - * (ADR-0066 D2 ⑧ as amended). No entry ⇒ readable, as the merge does with an - * absent key ({@link fieldHidden}); + * Modify All on the object votes every field readable (ADR-0066 D2 ⑧ as + * amended). Beside View All alone the set's own entry binds (note of + * 2026-11-15). No entry ⇒ readable, as the merge does with an absent key + * ({@link fieldHidden}); * - the capability gate (ADR-0066 D3): an object's `requiredPermissions` — * the `string[]` form, or the `read` bucket of the per-operation map * (`requiredCapsForOperation(…, 'find')`) — refuses the read @@ -207,14 +208,16 @@ function grantFor(set: AnyRec, objectName: string, isPrivate: boolean): Effectiv /** * Does the set's own field entry hide `objectName.fieldName`? `readable: false` - * hides it unless the set's super-user bypass on the object votes every field - * readable (ADR-0066 D2 ⑧ as amended). No entry ⇒ not hidden. + * hides it unless the set's Modify All on the object votes every field + * readable (ADR-0066 D2 ⑧ as amended). The set's View All alone casts no vote + * on a field its own entry hides (note of 2026-11-15), so the entry binds + * there. No entry ⇒ not hidden. */ function fieldHidden(set: AnyRec, objectName: string, fieldName: string): boolean { const fields = isRec(set.fields) ? set.fields : undefined; const entry = fields?.[`${objectName}.${fieldName}`]; if (!isRec(entry) || entry.readable !== false) return false; - return !holdsSuperuserBypass(set as { objects?: Record }, objectName, 'view'); + return !holdsSuperuserBypass(set as { objects?: Record }, objectName, 'modify'); } /** @@ -378,10 +381,10 @@ function hintFor(set: AnyRec, d: SummaryDescriptor): string { `That hides "${column}" from every holder of the set, and a co-held set with no entry for it does not ` + `restore it (View All or Modify All on "${d.parent.name}" does); to keep it for some holders, declare ` + `fields["${column}"]: { readable: true } in the sets they hold`; - if (holdsSuperuserBypass(set as { objects?: Record }, d.parent.name, 'view')) { + if (holdsSuperuserBypass(set as { objects?: Record }, d.parent.name, 'modify')) { return ( - `If its value should not be visible to this set, first remove View All and Modify All on ` + - `"${d.parent.name}" from it, since ${entry} does not hide a field from a set holding either, then set ` + + `If its value should not be visible to this set, first remove Modify All on ` + + `"${d.parent.name}" from it, since ${entry} does not hide a field from a set holding it, then set ` + `${entry} on it. ${reach}` ); } diff --git a/packages/lint/src/validate-security-posture.test.ts b/packages/lint/src/validate-security-posture.test.ts index bb1e7c195a0..d8a9664600a 100644 --- a/packages/lint/src/validate-security-posture.test.ts +++ b/packages/lint/src/validate-security-posture.test.ts @@ -1720,14 +1720,15 @@ describe('validateSecurityPosture · book audience (ADR-0046 §6.7 / ADR-0090)', /** * ── Rule: security-superuser-field-mask-inert (ADR-0066 D2 ⑧ as amended) ──── * - * Ruling of record 6573563853, letter A: a set holding View All / Modify All - * on an object votes on every field of it, so the same set's `readable: false` - * (View All or Modify All) or edit lock (Modify All) binds none of its holders. - * The pair is legal, so the finding is a warning. Each case below is a set - * PARSED by `PermissionSetSchema`, the normalized set the runtime reads, unless - * it says otherwise. + * Ruling of record 6573563853, letter A: a set holding Modify All on an + * object votes on every field of it, so the same set's `readable: false` or + * edit lock binds none of its holders. ADR-0066 D2 ⑧ note of 2026-11-15: a + * set's own `readable: false` binds beside its own View All, so that pair is + * not reported. The pair is legal, so the finding is a warning. Each case + * below is a set PARSED by `PermissionSetSchema`, the normalized set the + * runtime reads, unless it says otherwise. */ -describe('validateSecurityPosture · a field mask its own set\'s View All / Modify All makes inert', () => { +describe('validateSecurityPosture · a field mask its own set\'s Modify All makes inert', () => { const inert = (stack: Record) => validateSecurityPosture(stack) .filter((f) => f.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT) @@ -1747,23 +1748,26 @@ describe('validateSecurityPosture · a field mask its own set\'s View All / Modi }))).toEqual([['warning', 'permission set "deal_manager"', 'permissions[0].fields["deal.restricted_note"]']]); }); - it('the explain-principal-person fixture before its repair: View All beside a read mask', () => { - // `qa_pp_directory_masked` in plugin-security's `explain-principal-person.test.ts` - // reached every user through View All until the ruling made its email - // mask inert; it now reaches them through a row policy. + it('View All beside the set\'s own read mask is not reported: the mask binds', () => { + // `qa_pp_directory_masked` as plugin-security's `explain-principal-person.test.ts` + // first wrote it: every user through View All, the email withheld. expect(inert(parsed({ name: 'qa_pp_directory_masked', objects: { sys_user: { allowRead: true, viewAllRecords: true }, qa_pp_board: { allowRead: true } }, fields: { 'sys_user.email': { readable: false, editable: false } }, systemPermissions: ['manage_users'], - }))).toEqual([['warning', 'permission set "qa_pp_directory_masked"', 'permissions[0].fields["sys_user.email"]']]); + }))).toEqual([]); + // The same pair through the set's wildcard, on a raw set. + expect(inert({ + permissions: [{ name: 'ps', objects: { '*': { viewAllRecords: true } }, fields: { 'deal.amount': { readable: false } } }], + })).toEqual([]); }); - it('the composed sets of admin-ledger-decision-metadata.dogfood.test.ts: only the read mask is inert', () => { + it('the composed sets of admin-ledger-decision-metadata.dogfood.test.ts: View All unbinds none of their rows', () => { // Spelled as that file composes them, from shared consts, which is why a // structural grep for the pair finds nothing there. View All on the user - // object leaves the two `editable: false` grants binding; it unbinds the - // `readable: false` on `email`, in both sets that carry it. + // object leaves the `editable: false` grants binding, and the + // `readable: false` on `email` binds in both sets that carry it. const read = { allowRead: true, allowCreate: false, allowEdit: false, allowDelete: false }; const grants = { sys_user: { ...read, viewAllRecords: true }, sys_audit_log: read }; const withheldField = { 'sys_user.email': { readable: false, editable: false } }; @@ -1775,17 +1779,19 @@ describe('validateSecurityPosture · a field mask its own set\'s View All / Modi { name: 'ald_unmask_set', label: 'ALD unmask', objects: grants, fields: classFieldsReadable }, { name: 'ald_withhold_set', label: 'ALD withhold', objects: grants, fields: { ...classFieldsReadable, ...withheldField } }, { name: 'ald_withhold_only_set', label: 'ALD withhold only', objects: { sys_user: { allowRead: true, viewAllRecords: true } }, fields: withheldField }, - ))).toEqual([ - ['warning', 'permission set "ald_withhold_set"', 'permissions[1].fields["sys_user.email"]'], - ['warning', 'permission set "ald_withhold_only_set"', 'permissions[2].fields["sys_user.email"]'], - ]); + ))).toEqual([]); }); - it('Modify All unbinds a read mask too; View All never unbinds an edit lock', () => { + it('Modify All unbinds a read mask too, with or without View All beside it; View All never unbinds an edit lock', () => { expect(inert(parsed({ name: 'ps', objects: { deal: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, fields: { 'deal.amount': { readable: false } }, }))).toEqual([['warning', 'permission set "ps"', 'permissions[0].fields["deal.amount"]']]); + // Both bits on one entry: the Modify All vote is the one that counts. + expect(inert(parsed({ + name: 'ps', objects: { deal: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true } }, + fields: { 'deal.amount': { readable: false } }, + }))).toEqual([['warning', 'permission set "ps"', 'permissions[0].fields["deal.amount"]']]); expect(inert(parsed({ name: 'ps', objects: { deal: { allowRead: true, viewAllRecords: true } }, fields: { 'deal.amount': { readable: true, editable: false } }, @@ -1805,6 +1811,14 @@ describe('validateSecurityPosture · a field mask its own set\'s View All / Modi fields: { 'deal.amount': { readable: false } }, }], })).toEqual([]); + // A wildcard Modify All shadowed by an explicit View All entry: View All alone, not reported. + expect(inert({ + permissions: [{ + name: 'ps', + objects: { '*': { modifyAllRecords: true }, deal: { allowRead: true, viewAllRecords: true } }, + fields: { 'deal.amount': { readable: false } }, + }], + })).toEqual([]); }); it('an unparsed entry votes what it spells: an omitted edit bit is a lock under Modify All', () => { @@ -1817,7 +1831,7 @@ describe('validateSecurityPosture · a field mask its own set\'s View All / Modi it('controls: a row policy or org depth beside a mask, and another set\'s bypass, get nothing', () => { expect(inert(parsed({ - // `qa_pp_directory_masked` as repaired: every row through a row policy. + // `qa_pp_directory_masked` as it stands: every row through a row policy. name: 'qa_pp_directory_masked', objects: { sys_user: { allowRead: true }, qa_pp_board: { allowRead: true } }, fields: { 'sys_user.email': { readable: false, editable: false } }, @@ -1838,19 +1852,34 @@ describe('validateSecurityPosture · a field mask its own set\'s View All / Modi ))).toEqual([]); }); - it('says which bit unbinds which mask, in one line, and the id is explained', () => { - const [read] = validateSecurityPosture(parsed({ - name: 'ps', objects: { sys_user: { allowRead: true, viewAllRecords: true } }, - fields: { 'sys_user.email': { readable: false } }, - })).filter((f) => f.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT); - const [write] = validateSecurityPosture({ + it('says which half Modify All unbinds, in one line, and the id is explained', () => { + const only = (stack: Record) => + validateSecurityPosture(stack).filter((f) => f.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT); + const [read] = only(parsed({ + name: 'ps', objects: { sys_user: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { 'sys_user.email': { readable: false, editable: true } }, + })); + const [lock] = only(parsed({ + name: 'ps', objects: { sys_user: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { 'sys_user.email': { readable: true, editable: false } }, + })); + const [both] = only({ permissions: [{ name: 'ps', objects: { '*': { modifyAllRecords: true } }, fields: { 'deal.note': { readable: false, editable: false } } }], - }).filter((f) => f.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT); - expect(read.message).toContain('viewAllRecords'); + }); + expect(read.message).toContain('modifyAllRecords on objects.sys_user'); expect(read.message).toContain('readable: false'); - expect(write.message).toContain("objects['*']"); - expect(write.message).toContain('modifyAllRecords'); - for (const f of [read, write]) { + expect(read.message).not.toContain('the edit lock'); + expect(lock.message).toContain('the edit lock'); + expect(lock.message).not.toContain('readable: false'); + expect(both.message).toContain("objects['*']"); + expect(both.message).toContain('readable: false and the edit lock'); + expect([read, lock, both].map((f) => f.userTextParams)).toEqual([ + { permissionSet: 'ps', field: 'sys_user.email', object: 'sys_user', inert: 'read' }, + { permissionSet: 'ps', field: 'sys_user.email', object: 'sys_user', inert: 'edit' }, + { permissionSet: 'ps', field: 'deal.note', object: 'deal', inert: 'both' }, + ]); + for (const f of [read, lock, both]) { + expect(f.message, f.message).not.toContain('viewAllRecords'); expect(f.message, f.message).not.toContain('\n'); expect(f.message.length, f.message).toBeLessThanOrEqual(200); expect(f.hint, f.hint).not.toContain('\n'); @@ -2060,15 +2089,25 @@ describe('validateSecurityPosture · a hidden master reference still decides a c }))).toEqual([]); }); - it('control: the set\'s own View All on the detail makes the mask inert, so the inert rule speaks instead', () => { + it('control: the set\'s own Modify All on the detail makes the mask inert, so the inert rule speaks instead', () => { const stack = withSets([MASTER, DETAIL], { - name: 'auditor', objects: { line_item: { allowRead: true, viewAllRecords: true } }, + name: 'operator', objects: { line_item: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, fields: { 'line_item.invoice': { readable: false, editable: false } }, }); expect(hidden(stack)).toEqual([]); expect(validateSecurityPosture(stack).map((f) => f.rule)).toContain(SECURITY_SUPERUSER_FIELD_MASK_INERT); }); + it('the set\'s own View All on the detail leaves the mask binding, so this rule speaks and the inert rule does not', () => { + // ADR-0066 D2 ⑧ note of 2026-11-15: View All casts no vote on a field the set's own row hides. + const stack = withSets([MASTER, DETAIL], { + name: 'auditor', objects: { line_item: { allowRead: true, viewAllRecords: true } }, + fields: { 'line_item.invoice': { readable: false, editable: false } }, + }); + expect(hidden(stack)).toHaveLength(1); + expect(validateSecurityPosture(stack).map((f) => f.rule)).not.toContain(SECURITY_SUPERUSER_FIELD_MASK_INERT); + }); + it('states the rule and its consequence in one line, and the id is explained', () => { const [f] = validateSecurityPosture(withSets([MASTER, DETAIL], { name: 'clerk', objects: {}, fields: { 'line_item.invoice': { readable: false, editable: true } }, @@ -2636,7 +2675,7 @@ const REACHABILITY_CORPUS: Array<{ label: string; stack: Record stack: { permissions: [{ name: 'ps', label: 'PS', - objects: { deal: { allowRead: true, viewAllRecords: true } }, + objects: { deal: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, fields: { 'deal.amount': { readable: false, editable: false } }, }], }, @@ -2799,7 +2838,7 @@ describe('validateSecurityPosture — every branch is reachable without an undec // 17 since #25575: allowDelete: false beside modifyAllRecords: true. // 18 since #25760: an owner-keyed update policy on a controlled_by_parent detail that has not opted in. // 19 since #26591: the same rule id, for a policy keyed only on a column the opt-in does not admit. - // 20 since #29544: a field mask its own set's View All / Modify All makes inert. + // 20 since #29544: a field mask its own set's Modify All makes inert. // 21: a caller-keyed update policy that declares no check (ADR-0058 D4, info). // 22: a set's readable: false on a controlled_by_parent detail's master reference. expect(pushedRuleIds()).toHaveLength(22); diff --git a/packages/lint/src/validate-security-posture.ts b/packages/lint/src/validate-security-posture.ts index 90eb31f30c0..14b5b31624c 100644 --- a/packages/lint/src/validate-security-posture.ts +++ b/packages/lint/src/validate-security-posture.ts @@ -22,7 +22,7 @@ * | security-cbp-ambiguous-relation(error) | #14747 order-dependent master; runtime refusal since #23100 | * | security-modify-all-delete-withheld(error) | #25575 Modify All includes delete — UNPARSED intakes only, see the arm | * | security-controlled-by-parent-owner-policy-without-opt-in (warning) | ADR-0055 §3 amendment (ruling 6398566164): a caller-keyed update policy on a detail admits nobody the master gate refuses — unless it keys `owner_id` and the detail opted in (#26591: the opt-in is prescribed only there) | - * | security-superuser-field-mask-inert (warning) | ADR-0066 D2 ⑧ as amended (ruling 6573563853, letter A): a set's View All / Modify All on an object votes on every field of it, so its own `readable: false` (or, under Modify All, its edit lock) on that object binds none of its holders | + * | security-superuser-field-mask-inert (warning) | ADR-0066 D2 ⑧ as amended (ruling 6573563853, letter A; note of 2026-11-15): a set's Modify All on an object votes on every field of it, so its own `readable: false` or edit lock on that object binds none of its holders. Beside View All alone the set's own `readable: false` binds, and is not reported | * | security-controlled-by-parent-master-reference-hidden (warning) | ADR-0055 §3: a write of a detail needs edit access to the master its stored reference names, so a set's `readable: false` on that reference hides a field that still decides its holders' writes, and a holder refused there gets a refusal that names no master | * | security-update-policy-no-check (info) | ADR-0058 D4 write-check composition: a USING-only `update` / `all` policy keyed on a caller column other than `created_by` lets the ownership floor admit a row's new image too; info tier, so neither `os lint --strict` nor `os validate --strict` fails on it | * @@ -1119,8 +1119,10 @@ export function validateSecurityPosture(stack: AnyRec, opts?: { nowMs?: number } // field still decides the holder's write, and a holder refused there is // told only the rule, with no master named. Read as the field merges // read the entry (an omitted `readable` is `true`), and not reported - // beside the set's own View All or Modify All on the detail, which - // makes the mask inert (`security-superuser-field-mask-inert`). + // beside the set's own Modify All on the detail, which makes the mask + // inert (`security-superuser-field-mask-inert`). Beside View All alone + // the set's own mask binds (ADR-0066 D2 ⑧ note of 2026-11-15), so the + // reference is hidden and this rule speaks. // `warning`: hiding the reference is legal, and no door refuses it. const flsEntries = ps.fields && typeof ps.fields === 'object' ? (ps.fields as AnyRec) : {}; for (const [flsKey, flsEntry] of Object.entries(flsEntries)) { @@ -1130,7 +1132,7 @@ export function validateSecurityPosture(stack: AnyRec, opts?: { nowMs?: number } const detailName = flsKey.slice(0, dot); const detail = cbpDetails.get(detailName); if (!detail || flsKey.slice(dot + 1) !== detail.masterField) continue; - if (holdsSuperuserBypass(ps, detailName, 'view')) continue; + if (holdsSuperuserBypass(ps, detailName, 'modify')) continue; pushCbpMasterReferenceHidden(findings, psName, `permissions[${i}].fields["${flsKey}"]`, flsKey); } const policies = recordsOf(ps.rowLevelSecurity); @@ -1399,41 +1401,40 @@ export function validateSecurityPosture(stack: AnyRec, opts?: { nowMs?: number } }); } - // [ADR-0066 D2 ⑧ as amended — ruling of record 6573563853, letter A] A - // field mask this set's OWN super-user bit unbinds. A set holding View All - // or Modify All on an object votes on every field of it in both field - // merges (`superuserFieldVote`, `@objectstack/core`): View All votes - // `readable: true`, Modify All votes `readable: true` and `editable: true`. - // So beside View All a `readable: false` hides nothing from the set's - // holders, and beside Modify All neither does it nor an edit lock; View - // All beside an edit lock is NOT reported, because View All never widens a - // write and the lock still binds. + // [ADR-0066 D2 ⑧ as amended — ruling of record 6573563853, letter A; note + // of 2026-11-15] A field mask this set's OWN Modify All unbinds. A set + // holding Modify All on an object votes `readable: true` and + // `editable: true` on every field of it in both field merges + // (`superuserFieldVote`, `@objectstack/core`), its own rows included. So + // beside Modify All neither a `readable: false` nor an edit lock binds + // the set's holders. // - // `warning`, never `error`: the ruling made the pair legal, it only does - // not do what it reads as. The bypass is read by `holdsSuperuserBypass` - // below, the runtime's one reading copied verbatim (this package depends - // on spec alone); `packages/cli/test/superuser-bypass-mirror-parity.test.ts` + // View All alone is NOT reported. It votes only `readable: true`, and it + // casts no vote on a field the set's own row declares `readable: false`, + // so that mask binds; it never widened a write, so an edit lock beside it + // binds as well. + // + // `warning`, never `error`: the pair is legal, it only does not do what + // it reads as. The bypass is read by `holdsSuperuserBypass` below, the + // runtime's one reading copied verbatim (this package depends on spec + // alone); `packages/cli/test/superuser-bypass-mirror-parity.test.ts` // holds the copy equal to core's. The entry's bits are read as parsing // writes them (an omitted `readable` is `true`, an omitted `editable` is // `false`), which is what both merges then read, so a raw set and its - // parse answer the same. One set at a - // time: another set's bypass unmasks a holder of both, but no author wrote - // an inert entry there. + // parse answer the same. One set at a time: another set's bypass unmasks + // a holder of both, but no author wrote an inert entry there. for (const [flsKey, flsEntry] of Object.entries(flsMap)) { if (!flsEntry || typeof flsEntry !== 'object') continue; const dot = flsKey.indexOf('.'); if (dot <= 0) continue; // unqualified, judged above; both merges skip it too const flsObject = flsKey.slice(0, dot); + if (!holdsSuperuserBypass(ps, flsObject, 'modify')) continue; const mask = flsEntry as AnyRec; const readMasked = mask.readable === false; const editLocked = mask.editable !== true; - const modifyAll = holdsSuperuserBypass(ps, flsObject, 'modify'); - const viewAll = modifyAll || holdsSuperuserBypass(ps, flsObject, 'view'); - const inertBits = [readMasked && viewAll ? 'readable: false' : '', editLocked && modifyAll ? 'the edit lock' : ''] - .filter(Boolean); + const inertBits = [readMasked ? 'readable: false' : '', editLocked ? 'the edit lock' : ''].filter(Boolean); if (inertBits.length === 0) continue; const binds = inertBits.length > 1 ? 'bind' : 'binds'; - const bit = modifyAll ? 'modifyAllRecords' : 'viewAllRecords'; const via = objectsMap[flsObject] ? `objects.${flsObject}` : `objects['*']`; findings.push({ severity: 'warning', @@ -1441,19 +1442,17 @@ export function validateSecurityPosture(stack: AnyRec, opts?: { nowMs?: number } where: `permission set "${psName}"`, path: `${psPath}.fields["${flsKey}"]`, message: - `${bit} on ${via} votes on every field of "${flsObject}", so ${inertBits.join(' and ')} ` + + `modifyAllRecords on ${via} votes on every field of "${flsObject}", so ${inertBits.join(' and ')} ` + `on '${flsKey}' ${binds} none of this set's holders`, hint: - `Remove ${bit} from ${via} and reach the rows with readScope/writeScope or a row-level policy, ` + + `Remove modifyAllRecords from ${via} and reach the rows with readScope/writeScope or a row-level policy, ` + `or delete the entry if the bypass is meant`, - // `inert` names the half the user sentence may call ineffective: beside - // View All only the read mask is, and the edit lock still binds. + // `inert` names the half the user sentence may call ineffective. userTextParams: { permissionSet: psName, field: flsKey, object: flsObject, - bypass: modifyAll ? 'modify' : 'view', - inert: inertBits.length > 1 ? 'both' : readMasked && viewAll ? 'read' : 'edit', + inert: inertBits.length > 1 ? 'both' : readMasked ? 'read' : 'edit', }, }); } diff --git a/packages/lint/src/validate-security-posture.user-text.ts b/packages/lint/src/validate-security-posture.user-text.ts index 77f272caca3..306cf3b1f82 100644 --- a/packages/lint/src/validate-security-posture.user-text.ts +++ b/packages/lint/src/validate-security-posture.user-text.ts @@ -23,7 +23,7 @@ * | `security-private-no-readscope` | `permissionSet`, `object` | * | `security-master-detail-ungranted` | `object`, `master` (`''` when the runtime's parent names none) | * | `security-book-audience-unknown-set` | `book`, `permissionSet` | - * | `security-superuser-field-mask-inert` | `permissionSet`, `field`, `object`, `bypass` (`view` · `modify`), `inert` (`read` · `edit` · `both`) | + * | `security-superuser-field-mask-inert` | `permissionSet`, `field`, `object`, `inert` (`read` · `edit` · `both`) | * | `security-controlled-by-parent-master-reference-hidden` | `permissionSet`, `field` | * | `security-update-policy-no-check` | `permissionSet`, `policy` | * | `security-controlled-by-parent-owner-policy-without-opt-in` | `permissionSet`, `policy`, `object`, `remedy` (`allow-owner-edit` · `key-owner-id` · `add-owner-id`) | @@ -49,23 +49,26 @@ import { SECURITY_UPDATE_POLICY_NO_CHECK, } from './validate-security-posture.js'; -/** `bypass` → the console's own label for that permission, per locale. */ -const BYPASS_LABEL = { - en: { view: 'View All Records', modify: 'Modify All Records' }, - 'zh-Hans': { view: '查看所有记录', modify: '修改所有记录' }, - 'zh-Hant': { view: '查看所有記錄', modify: '修改所有記錄' }, - es: { view: 'View All Records', modify: 'Modify All Records' }, - ar: { view: 'View All Records', modify: 'Modify All Records' }, - fr: { view: 'View All Records', modify: 'Modify All Records' }, - 'pt-BR': { view: 'View All Records', modify: 'Modify All Records' }, - ru: { view: 'View All Records', modify: 'Modify All Records' }, - de: { view: 'View All Records', modify: 'Modify All Records' }, - ja: { view: 'View All Records', modify: 'Modify All Records' }, - ko: { view: 'View All Records', modify: 'Modify All Records' }, +/** + * The console's own label for Modify All, per locale. The one bypass + * `security-superuser-field-mask-inert` reports: beside View All alone the + * set's own `readable: false` binds (ADR-0066 D2 ⑧ note of 2026-11-15). + */ +const MODIFY_ALL_LABEL = { + en: 'Modify All Records', + 'zh-Hans': '修改所有记录', + 'zh-Hant': '修改所有記錄', + es: 'Modify All Records', + ar: 'Modify All Records', + fr: 'Modify All Records', + 'pt-BR': 'Modify All Records', + ru: 'Modify All Records', + de: 'Modify All Records', + ja: 'Modify All Records', + ko: 'Modify All Records', } as const; -const bypassLabel = (locale: keyof typeof BYPASS_LABEL, p: UserTextParams): string => - BYPASS_LABEL[locale][p.bypass === 'modify' ? 'modify' : 'view']; +const modifyAllLabel = (locale: keyof typeof MODIFY_ALL_LABEL): string => MODIFY_ALL_LABEL[locale]; export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ [SECURITY_PRIVATE_NO_READSCOPE]: { @@ -234,7 +237,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }, [SECURITY_SUPERUSER_FIELD_MASK_INERT]: { en: (p) => { - const b = bypassLabel('en', p); + const b = modifyAllLabel('en'); return fieldMaskSentence(p, { read: `In permission set "${p.permissionSet}", hiding field "${p.field}" has no effect: the set's ${b} on ` + @@ -252,7 +255,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, 'zh-Hans': (p) => { - const b = bypassLabel('zh-Hans', p); + const b = modifyAllLabel('zh-Hans'); return fieldMaskSentence(p, { read: `在权限集“${p.permissionSet}”中,隐藏字段“${p.field}”不起作用:该权限集对“${p.object}”拥有“${b}”,` + @@ -269,7 +272,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, 'zh-Hant': (p) => { - const b = bypassLabel('zh-Hant', p); + const b = modifyAllLabel('zh-Hant'); return fieldMaskSentence(p, { read: `在權限集「${p.permissionSet}」中,隱藏欄位「${p.field}」不起作用:該權限集對「${p.object}」擁有「${b}」,` + @@ -286,7 +289,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, es: (p) => { - const b = bypassLabel('es', p); + const b = modifyAllLabel('es'); return fieldMaskSentence(p, { read: `En el conjunto de permisos "${p.permissionSet}", ocultar el campo "${p.field}" no tiene efecto: el ` + @@ -306,7 +309,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, ar: (p) => { - const b = bypassLabel('ar', p); + const b = modifyAllLabel('ar'); return fieldMaskSentence(p, { read: `في مجموعة الأذونات "${p.permissionSet}"، لا يكون لإخفاء الحقل "${p.field}" أي أثر: إذن "${b}" الذي ` + @@ -323,7 +326,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, fr: (p) => { - const b = bypassLabel('fr', p); + const b = modifyAllLabel('fr'); return fieldMaskSentence(p, { read: `Dans l’ensemble d’autorisations « ${p.permissionSet} », masquer le champ « ${p.field} » n’a aucun effet : ` + @@ -344,7 +347,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, 'pt-BR': (p) => { - const b = bypassLabel('pt-BR', p); + const b = modifyAllLabel('pt-BR'); return fieldMaskSentence(p, { read: `No conjunto de permissões "${p.permissionSet}", ocultar o campo "${p.field}" não tem efeito: a permissão ` + @@ -364,7 +367,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, ru: (p) => { - const b = bypassLabel('ru', p); + const b = modifyAllLabel('ru'); return fieldMaskSentence(p, { read: `В наборе разрешений «${p.permissionSet}» скрытие поля «${p.field}» не действует: право «${b}» этого ` + @@ -384,7 +387,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, de: (p) => { - const b = bypassLabel('de', p); + const b = modifyAllLabel('de'); return fieldMaskSentence(p, { read: `Im Berechtigungssatz „${p.permissionSet}“ ist das Ausblenden des Felds „${p.field}“ wirkungslos: Die ` + @@ -405,7 +408,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, ja: (p) => { - const b = bypassLabel('ja', p); + const b = modifyAllLabel('ja'); return fieldMaskSentence(p, { read: `権限セット「${p.permissionSet}」では、項目「${p.field}」を非表示にする設定が効いていません。この権限セットは` + @@ -425,7 +428,7 @@ export const SECURITY_POSTURE_USER_TEXT: UserTextCatalog = Object.freeze({ }); }, ko: (p) => { - const b = bypassLabel('ko', p); + const b = modifyAllLabel('ko'); return fieldMaskSentence(p, { read: `권한 세트 "${p.permissionSet}"에서 필드 "${p.field}"을(를) 숨기는 설정은 효과가 없습니다. 이 권한 세트는 ` + @@ -684,16 +687,16 @@ function ownerPolicyRemedy(p: UserTextParams, sentences: Readonly>): string { if (p.inert === 'read' || p.inert === 'edit' || p.inert === 'both') return sentences[p.inert]; - return p.bypass === 'modify' ? sentences.both : sentences.read; + return sentences.both; } diff --git a/packages/plugins/plugin-security/src/explain-principal-person.test.ts b/packages/plugins/plugin-security/src/explain-principal-person.test.ts index baa9254b050..28320775cf2 100644 --- a/packages/plugins/plugin-security/src/explain-principal-person.test.ts +++ b/packages/plugins/plugin-security/src/explain-principal-person.test.ts @@ -52,10 +52,10 @@ const DIRECTORY_SET = PermissionSetSchema.parse({ }); /** * The same directory with the email column withheld by field-level security. - * Every user row is reached by a row policy rather than `viewAllRecords`: a - * set holding View All on an object votes `readable: true` on every field of - * it (ADR-0066 D2 ⑧ as amended, ruling of record 6573563853), so its own mask - * could not withhold the email. + * Every user row is reached by a row policy rather than `viewAllRecords`. The + * shape predates the ADR-0066 D2 ⑧ note of 2026-11-15, under which a View All + * set's own `readable: false` row binds that set's holders; it is kept because + * it withholds the email whichever way the set reaches the rows. */ const MASKED_DIRECTORY_SET = PermissionSetSchema.parse({ name: 'qa_pp_directory_masked', diff --git a/packages/plugins/plugin-security/src/fls-superuser-vote.test.ts b/packages/plugins/plugin-security/src/fls-superuser-vote.test.ts index d98ef98e72e..0cd8f47aca2 100644 --- a/packages/plugins/plugin-security/src/fls-superuser-vote.test.ts +++ b/packages/plugins/plugin-security/src/fls-superuser-vote.test.ts @@ -24,7 +24,10 @@ // disagree about who is a super-user on an object; // 4. ROW-BLIND PARITY — `/auth/me/permissions`' merge // (`buildEffectiveFieldPermissions`, `@objectstack/core`) answers the same -// bits as `getFieldPermissions` for the same sets. +// bits as `getFieldPermissions` for the same sets; +// 5. THE SET'S OWN ROW (ADR-0066 D2 ⑧ note of 2026-11-15) — a View All set's +// own `readable: false` row binds its holders in both merges; another +// set's bypass still reads the field, and Modify All votes as before. // // The HTTP doors (list, sort, record read, `/auth/me/permissions`, explain) are // pinned on a real boot in @@ -74,8 +77,36 @@ const SHADOWED_WILDCARD = set({ objects: { '*': { allowRead: true, viewAllRecords: true, modifyAllRecords: true }, [OBJ]: { allowRead: true } }, }); +/** The field rows of {@link APP_MASK}, for a set that also holds a bypass bit on the object. */ +const OWN_MASK = Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: false, editable: false }])); +/** View All on the object, and the set's own rows hiding fields of it. */ +const VIEW_ALL_OWN_MASK = set({ + name: 'auditor_masked', + objects: { [OBJ]: { allowRead: true, viewAllRecords: true } }, + fields: OWN_MASK, +}); +/** The same pair through the set's `'*'` wildcard. */ +const WILDCARD_VIEW_ALL_OWN_MASK = set({ + name: 'wildcard_auditor_masked', + objects: { '*': { allowRead: true, viewAllRecords: true } }, + fields: OWN_MASK, +}); +/** Modify All on the object beside the set's own rows. */ +const MODIFY_ALL_OWN_MASK = set({ + name: 'operator_masked', + objects: { [OBJ]: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: OWN_MASK, +}); + const evaluator = new PermissionEvaluator(); const merge = (sets: PermissionSet[]) => evaluator.getFieldPermissions(OBJ, sets); +/** The `fields` slot `/auth/me/permissions` serves for `sets`, projected to this object's fields. */ +const rowBlind = (sets: PermissionSet[]) => + Object.fromEntries( + Object.entries(buildEffectiveFieldPermissions(sets)) + .filter(([k]) => k.startsWith(`${OBJ}.`)) + .map(([k, v]) => [k.slice(OBJ.length + 1), v]), + ); describe('[ADR-0066 ⑧, ruling 6573563853] a super-user set votes on every field of its object', () => { it('the shipped admin_full_access reaches the object through its wildcard super-user bits (premise guard)', () => { @@ -178,16 +209,104 @@ describe('[ruling 6573563853] the row-blind /auth/me/permissions merge agrees wi ['modifyAll + read-only', [MODIFY_ALL, APP_READ_ONLY]], ['shadowed wildcard + mask', [SHADOWED_WILDCARD, APP_MASK]], ['member_default + mask', [shipped('member_default'), APP_MASK]], + ['viewAll with its own mask', [VIEW_ALL_OWN_MASK]], + ['viewAll with its own mask + viewAll', [VIEW_ALL_OWN_MASK, VIEW_ALL]], + ['viewAll with its own mask + modifyAll', [VIEW_ALL_OWN_MASK, MODIFY_ALL]], + ['viewAll with its own mask + admin_full_access', [VIEW_ALL_OWN_MASK, shipped(ADMIN_FULL_ACCESS)]], + ['modifyAll with its own mask', [MODIFY_ALL_OWN_MASK]], ]; it.each(combos)('%s', (_label, sets) => { - const perObject = merge(sets); - const rowBlind = buildEffectiveFieldPermissions(sets); - const projected = Object.fromEntries( - Object.entries(rowBlind) - .filter(([k]) => k.startsWith(`${OBJ}.`)) - .map(([k, v]) => [k.slice(OBJ.length + 1), v]), - ); - expect(projected).toEqual(perObject); + expect(rowBlind(sets)).toEqual(merge(sets)); + }); +}); + +/** + * The two merges every reading below is taken from: `getFieldPermissions`, + * which every data door reads, and the `fields` slot `/auth/me/permissions` + * serves. One `describe` per merge, so each is red or green on its own. + */ +const MERGES: Array<[string, (sets: PermissionSet[]) => Record]> = [ + ['getFieldPermissions', merge], + ['/auth/me/permissions', rowBlind], +]; + +describe.each(MERGES)('[ADR-0066 ⑧ note of 2026-11-15] a set\'s own readable: false row wins over its own View All vote · %s', (_merge, read) => { + it('a holder of the set alone is not served the fields the set hides', () => { + const fp = read([VIEW_ALL_OWN_MASK]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: false, editable: false }); + }); + + it('the same holds when the set holds View All through its wildcard', () => { + const fp = read([WILDCARD_VIEW_ALL_OWN_MASK]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: false, editable: false }); + }); + + it('a plain co-held set changes nothing: only a vote reads a field', () => { + const plain = set({ name: 'plain', objects: { [OBJ]: { allowRead: true, allowEdit: true } } }); + const fp = read([VIEW_ALL_OWN_MASK, plain]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: false, editable: false }); + }); + + it('the set\'s View All still reads a field ANOTHER set hides', () => { + const partial = set({ + name: 'auditor_partial', + objects: { [OBJ]: { allowRead: true, viewAllRecords: true } }, + fields: { [`${OBJ}.code`]: { readable: false, editable: false } }, + }); + const fp = read([partial, APP_MASK]); + expect(fp.code, 'code').toEqual({ readable: false, editable: false }); + for (const f of MASKED.filter((m) => m !== 'code')) expect(fp[f], f).toEqual({ readable: true, editable: false }); + }); + + it('[reverse pin, ruling 6573563853] a second set holding View All on the object still reads every field', () => { + const fp = read([VIEW_ALL_OWN_MASK, VIEW_ALL]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: true, editable: false }); + }); + + it('[reverse pin, ruling 6573563853] a second set holding Modify All on the object still reads and edits every field', () => { + for (const second of [MODIFY_ALL, shipped(ADMIN_FULL_ACCESS)]) { + const fp = read([VIEW_ALL_OWN_MASK, second]); + for (const f of MASKED) expect(fp[f], `${second.name} ${f}`).toEqual({ readable: true, editable: true }); + // Resolution order does not matter. + expect(read([second, VIEW_ALL_OWN_MASK])).toEqual(fp); + } + }); + + it('[unchanged] Modify All votes on every field, the set\'s own rows included', () => { + const own = read([MODIFY_ALL_OWN_MASK]); + for (const f of MASKED) expect(own[f], f).toEqual({ readable: true, editable: true }); + const readOnlyRows = set({ + name: 'operator_read_only_rows', + objects: { [OBJ]: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: true, editable: false }])), + }); + const locked = read([readOnlyRows]); + for (const f of MASKED) expect(locked[f], f).toEqual({ readable: true, editable: true }); + // Both bits on one entry: the Modify All vote is the one that counts. + const both = set({ + name: 'both_bits_masked', + objects: { [OBJ]: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true } }, + fields: OWN_MASK, + }); + const bothBits = read([both]); + for (const f of MASKED) expect(bothBits[f], f).toEqual({ readable: true, editable: true }); + }); + + it('[unchanged] an edit lock beside the set\'s own View All binds: View All never granted an edit', () => { + const lock = set({ + name: 'auditor_read_only_rows', + objects: { [OBJ]: { allowRead: true, allowEdit: true, viewAllRecords: true } }, + fields: Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: true, editable: false }])), + }); + const fp = read([lock]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: true, editable: false }); + }); +}); + +describe('[ADR-0066 ⑧ note of 2026-11-15] the row-level bypass is untouched', () => { + it('a View All set that hides a field of the object still holds View All on it', () => { + expect(evaluator.superuserBypassSets(OBJ, [VIEW_ALL_OWN_MASK], { bit: 'view' })).toEqual(['auditor_masked']); + expect(evaluator.superuserBypassSets(OBJ, [VIEW_ALL_OWN_MASK], { bit: 'modify' })).toEqual([]); }); }); diff --git a/packages/plugins/plugin-security/src/permission-evaluator.ts b/packages/plugins/plugin-security/src/permission-evaluator.ts index 22b26532099..6c90a40c291 100644 --- a/packages/plugins/plugin-security/src/permission-evaluator.ts +++ b/packages/plugins/plugin-security/src/permission-evaluator.ts @@ -540,6 +540,12 @@ export class PermissionEvaluator { * super-user bits but named no field cast no vote, so an app set's * `readable: false` hid the field from a platform admin who also held it. * Union without deny is otherwise unchanged. + * + * [ADR-0066 D2 ⑧ note of 2026-11-15] The vote is asked per field: a set + * holding View All without Modify All casts no read vote on a field its OWN + * row declares `readable: false`, so that row binds the set's holders. + * Another set's View All or Modify All still reads the field, and a Modify + * All set votes on every field as before, its own rows included. */ getFieldPermissions( objectName: string, @@ -570,14 +576,14 @@ export class PermissionEvaluator { } } - // [Ruling of record 6573563853] The super-user vote — the same function the - // row-blind `/auth/me/permissions` merge applies. - const superVote = superuserFieldVote(permissionSets, objectName); - if (superVote) { - for (const perm of Object.values(result)) { - perm.readable = true; - if (superVote.editable) perm.editable = true; - } + // [Ruling of record 6573563853; ADR-0066 D2 ⑧ note of 2026-11-15] The + // super-user vote, per field — the same function the row-blind + // `/auth/me/permissions` merge applies. + for (const [fieldName, perm] of Object.entries(result)) { + const superVote = superuserFieldVote(permissionSets, objectName, fieldName); + if (!superVote) continue; + perm.readable = true; + if (superVote.editable) perm.editable = true; } return result; diff --git a/packages/spec/src/security/permission.zod.ts b/packages/spec/src/security/permission.zod.ts index b006193853c..e964c4ec19a 100644 --- a/packages/spec/src/security/permission.zod.ts +++ b/packages/spec/src/security/permission.zod.ts @@ -1044,7 +1044,11 @@ const FIELD_PERMISSION_WHEN_ON_READABLE = * every field of it, on every row (ADR-0066 ⑧ note of 2026-11-02, ruling of * record 6573563853): `viewAllRecords` votes `readable: true`, * `modifyAllRecords` votes `readable: true` and `editable: true`; View All - * never grants an edit. Otherwise union without deny is unchanged. The write gate + * never grants an edit. One exception (ADR-0066 ⑧ note of 2026-11-15): a set + * holding View All without Modify All casts no read vote on a field its OWN + * entry declares `readable: false`, so that row binds the set's own holders; + * another set's vote, and the Modify All vote, are as before. Otherwise union + * without deny is unchanged. The write gate * judges it on the stored row before an update and on the incoming row of an * insert. It reaches the EDIT vote only: reads are row-blind (per-row masking * waits for a measured need), so `readable: false` beside a `when` is refused From a25046eb7e045b8a8a72a9443e632fb79469473d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 15:04:58 +0000 Subject: [PATCH 2/4] test(core, plugin-security, lint): the own field-mask pins live in their own files The pins this change adds move out of the shared test files into files of their own; the shared files keep only the existing pins the amended rule flips, edited in place. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- .../effective-object-permissions.test.ts | 83 -------- .../superuser-field-vote-33828.test.ts | 97 +++++++++ ...ce-visibility-own-field-mask-33828.test.ts | 116 +++++++++++ .../validate-rollup-source-visibility.test.ts | 41 +--- ...urity-posture-own-field-mask-33828.test.ts | 124 ++++++++++++ .../src/validate-security-posture.test.ts | 62 +----- .../src/fls-own-field-mask-33828.test.ts | 188 ++++++++++++++++++ .../src/fls-superuser-vote.test.ts | 137 +------------ 8 files changed, 547 insertions(+), 301 deletions(-) create mode 100644 packages/core/src/security/superuser-field-vote-33828.test.ts create mode 100644 packages/lint/src/validate-rollup-source-visibility-own-field-mask-33828.test.ts create mode 100644 packages/lint/src/validate-security-posture-own-field-mask-33828.test.ts create mode 100644 packages/plugins/plugin-security/src/fls-own-field-mask-33828.test.ts diff --git a/packages/core/src/security/effective-object-permissions.test.ts b/packages/core/src/security/effective-object-permissions.test.ts index 057118becf3..4d79b28a5cf 100644 --- a/packages/core/src/security/effective-object-permissions.test.ts +++ b/packages/core/src/security/effective-object-permissions.test.ts @@ -23,7 +23,6 @@ import { holdsSuperuserBypass, registryObjectPackageDisabled, servedObjectPermissions, - superuserFieldVote, } from './effective-object-permissions.js'; describe('buildEffectiveObjectPermissions', () => { @@ -910,88 +909,6 @@ describe('buildEffectiveFieldPermissions (#25866)', () => { }); }); - // [ADR-0066 D2 ⑧ note of 2026-11-15] A set's own explicit `readable: false` - // row is that set's vote on the field: its own View All casts no read vote - // there. Another set's bypass still votes (ruling of record 6573563853's - // admin case), and a Modify All set still votes on every field. - describe('a set\'s own readable: false row and that set\'s own super-user vote', () => { - const viewAll = (fields: Record, objects: Record = { deal: { allowRead: true, viewAllRecords: true } }) => - ({ objects, fields }); - const mask = { 'deal.amount': { readable: false, editable: false } }; - - it('View All beside the set\'s own readable: false row: the row binds, by the object entry and by the wildcard', () => { - expect(buildEffectiveFieldPermissions([viewAll(mask)])).toEqual({ 'deal.amount': { readable: false, editable: false } }); - expect(buildEffectiveFieldPermissions([viewAll(mask, { '*': { viewAllRecords: true } })])).toEqual({ - 'deal.amount': { readable: false, editable: false }, - }); - // Two holders of the pair, each masking the field itself: nobody votes it readable. - expect(buildEffectiveFieldPermissions([viewAll(mask), viewAll(mask)])).toEqual({ - 'deal.amount': { readable: false, editable: false }, - }); - }); - - it('the same set\'s View All still votes on the fields it does not mask itself', () => { - // `deal.stage` is masked by ANOTHER set; this set's View All reads it as before. - expect(buildEffectiveFieldPermissions([ - viewAll(mask), - { objects: { deal: { allowRead: true } }, fields: { 'deal.stage': { readable: false, editable: false } } }, - ])).toEqual({ - 'deal.amount': { readable: false, editable: false }, - 'deal.stage': { readable: true, editable: false }, - }); - }); - - it('reverse pin: another set\'s View All or Modify All on the object still reads the masked field', () => { - expect(buildEffectiveFieldPermissions([viewAll(mask), { objects: { deal: { viewAllRecords: true } } }])).toEqual({ - 'deal.amount': { readable: true, editable: false }, - }); - expect(buildEffectiveFieldPermissions([viewAll(mask), { objects: { '*': { viewAllRecords: true } } }])).toEqual({ - 'deal.amount': { readable: true, editable: false }, - }); - expect(buildEffectiveFieldPermissions([viewAll(mask), { objects: { deal: { modifyAllRecords: true } } }])).toEqual({ - 'deal.amount': { readable: true, editable: true }, - }); - // Another set's declared `readable: true` still out-votes the mask: union without deny. - expect(buildEffectiveFieldPermissions([viewAll(mask), { fields: { 'deal.amount': { readable: true, editable: false } } }])) - .toEqual({ 'deal.amount': { readable: true, editable: false } }); - }); - - it('Modify All is unchanged: it votes on every field, the set\'s own rows included', () => { - const modifyAll = { deal: { allowRead: true, allowEdit: true, modifyAllRecords: true } }; - expect(buildEffectiveFieldPermissions([{ objects: modifyAll, fields: mask }])).toEqual({ - 'deal.amount': { readable: true, editable: true }, - }); - expect(buildEffectiveFieldPermissions([{ objects: modifyAll, fields: { 'deal.amount': { readable: true, editable: false } } }])) - .toEqual({ 'deal.amount': { readable: true, editable: true } }); - // Both bits on one entry: the Modify All vote is the one that counts. - expect(buildEffectiveFieldPermissions([ - { objects: { deal: { viewAllRecords: true, modifyAllRecords: true } }, fields: mask }, - ])).toEqual({ 'deal.amount': { readable: true, editable: true } }); - }); - - it('an edit lock beside View All binds as it always did, and only an explicit false is a mask', () => { - expect(buildEffectiveFieldPermissions([viewAll({ 'deal.amount': { readable: true, editable: false } })])).toEqual({ - 'deal.amount': { readable: true, editable: false }, - }); - // An unparsed row that omits `readable` is not an explicit mask: the vote stands. - expect(buildEffectiveFieldPermissions([viewAll({ 'deal.amount': { editable: false } })])).toEqual({ - 'deal.amount': { readable: true, editable: false }, - }); - }); - - it('superuserFieldVote: per field with a field name, object-wide without one', () => { - const sets = [viewAll(mask)]; - expect(superuserFieldVote(sets, 'deal', 'amount')).toBeNull(); - expect(superuserFieldVote(sets, 'deal', 'stage')).toEqual({ readable: true, editable: false }); - expect(superuserFieldVote(sets, 'deal')).toEqual({ readable: true, editable: false }); - expect(superuserFieldVote([{ objects: { deal: { modifyAllRecords: true } }, fields: mask }], 'deal', 'amount')) - .toEqual({ readable: true, editable: true }); - // The mask is read on the set that declares it, never on a sibling. - expect(superuserFieldVote([{ objects: { deal: { viewAllRecords: true } } }, { fields: mask }], 'deal', 'amount')) - .toEqual({ readable: true, editable: false }); - }); - }); - it('holdsSuperuserBypass: explicit entry first, then the wildcard; modify implies view, view never implies modify', () => { expect(holdsSuperuserBypass({ objects: { '*': { viewAllRecords: true } } }, 'deal', 'view')).toBe(true); expect(holdsSuperuserBypass({ objects: { '*': { viewAllRecords: true } } }, 'deal', 'modify')).toBe(false); diff --git a/packages/core/src/security/superuser-field-vote-33828.test.ts b/packages/core/src/security/superuser-field-vote-33828.test.ts new file mode 100644 index 00000000000..91fffea33f2 --- /dev/null +++ b/packages/core/src/security/superuser-field-vote-33828.test.ts @@ -0,0 +1,97 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [ADR-0066 D2 ⑧ note of 2026-11-15] A set's own explicit `readable: false` + * row is that set's vote on the field: its own View All casts no read vote + * there. Another set's bypass still votes (the admin case of ruling of record + * 6573563853), and a Modify All set still votes on every field, its own rows + * included. + * + * Pinned on the row-blind merge (`buildEffectiveFieldPermissions`, the `fields` + * slot of `/auth/me/permissions`) and on the one function both field merges + * ask, `superuserFieldVote`. The evaluator's merge is pinned beside it in + * plugin-security's `fls-own-field-mask-33828.test.ts`. + */ + +import { describe, it, expect } from 'vitest'; +import { buildEffectiveFieldPermissions, superuserFieldVote } from './effective-object-permissions.js'; + +describe('a set\'s own readable: false row and that set\'s own super-user vote', () => { + const viewAll = ( + fields: Record, + objects: Record = { deal: { allowRead: true, viewAllRecords: true } }, + ) => ({ objects, fields }); + const mask = { 'deal.amount': { readable: false, editable: false } }; + + it('View All beside the set\'s own readable: false row: the row binds, by the object entry and by the wildcard', () => { + expect(buildEffectiveFieldPermissions([viewAll(mask)])).toEqual({ 'deal.amount': { readable: false, editable: false } }); + expect(buildEffectiveFieldPermissions([viewAll(mask, { '*': { viewAllRecords: true } })])).toEqual({ + 'deal.amount': { readable: false, editable: false }, + }); + // Two holders of the pair, each masking the field itself: nobody votes it readable. + expect(buildEffectiveFieldPermissions([viewAll(mask), viewAll(mask)])).toEqual({ + 'deal.amount': { readable: false, editable: false }, + }); + }); + + it('the same set\'s View All still votes on the fields it does not mask itself', () => { + // `deal.stage` is masked by ANOTHER set; this set's View All reads it as before. + expect(buildEffectiveFieldPermissions([ + viewAll(mask), + { objects: { deal: { allowRead: true } }, fields: { 'deal.stage': { readable: false, editable: false } } }, + ])).toEqual({ + 'deal.amount': { readable: false, editable: false }, + 'deal.stage': { readable: true, editable: false }, + }); + }); + + it('reverse pin: another set\'s View All or Modify All on the object still reads the masked field', () => { + expect(buildEffectiveFieldPermissions([viewAll(mask), { objects: { deal: { viewAllRecords: true } } }])).toEqual({ + 'deal.amount': { readable: true, editable: false }, + }); + expect(buildEffectiveFieldPermissions([viewAll(mask), { objects: { '*': { viewAllRecords: true } } }])).toEqual({ + 'deal.amount': { readable: true, editable: false }, + }); + expect(buildEffectiveFieldPermissions([viewAll(mask), { objects: { deal: { modifyAllRecords: true } } }])).toEqual({ + 'deal.amount': { readable: true, editable: true }, + }); + // Another set's declared `readable: true` still out-votes the mask: union without deny. + expect(buildEffectiveFieldPermissions([viewAll(mask), { fields: { 'deal.amount': { readable: true, editable: false } } }])) + .toEqual({ 'deal.amount': { readable: true, editable: false } }); + }); + + it('Modify All is unchanged: it votes on every field, the set\'s own rows included', () => { + const modifyAll = { deal: { allowRead: true, allowEdit: true, modifyAllRecords: true } }; + expect(buildEffectiveFieldPermissions([{ objects: modifyAll, fields: mask }])).toEqual({ + 'deal.amount': { readable: true, editable: true }, + }); + expect(buildEffectiveFieldPermissions([{ objects: modifyAll, fields: { 'deal.amount': { readable: true, editable: false } } }])) + .toEqual({ 'deal.amount': { readable: true, editable: true } }); + // Both bits on one entry: the Modify All vote is the one that counts. + expect(buildEffectiveFieldPermissions([ + { objects: { deal: { viewAllRecords: true, modifyAllRecords: true } }, fields: mask }, + ])).toEqual({ 'deal.amount': { readable: true, editable: true } }); + }); + + it('an edit lock beside View All binds as it always did, and only an explicit false is a mask', () => { + expect(buildEffectiveFieldPermissions([viewAll({ 'deal.amount': { readable: true, editable: false } })])).toEqual({ + 'deal.amount': { readable: true, editable: false }, + }); + // An unparsed row that omits `readable` is not an explicit mask: the vote stands. + expect(buildEffectiveFieldPermissions([viewAll({ 'deal.amount': { editable: false } })])).toEqual({ + 'deal.amount': { readable: true, editable: false }, + }); + }); + + it('superuserFieldVote: per field with a field name, object-wide without one', () => { + const sets = [viewAll(mask)]; + expect(superuserFieldVote(sets, 'deal', 'amount')).toBeNull(); + expect(superuserFieldVote(sets, 'deal', 'stage')).toEqual({ readable: true, editable: false }); + expect(superuserFieldVote(sets, 'deal')).toEqual({ readable: true, editable: false }); + expect(superuserFieldVote([{ objects: { deal: { modifyAllRecords: true } }, fields: mask }], 'deal', 'amount')) + .toEqual({ readable: true, editable: true }); + // The mask is read on the set that declares it, never on a sibling. + expect(superuserFieldVote([{ objects: { deal: { viewAllRecords: true } } }, { fields: mask }], 'deal', 'amount')) + .toEqual({ readable: true, editable: false }); + }); +}); diff --git a/packages/lint/src/validate-rollup-source-visibility-own-field-mask-33828.test.ts b/packages/lint/src/validate-rollup-source-visibility-own-field-mask-33828.test.ts new file mode 100644 index 00000000000..b88168b8c25 --- /dev/null +++ b/packages/lint/src/validate-rollup-source-visibility-own-field-mask-33828.test.ts @@ -0,0 +1,116 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// [ADR-0066 D2 ⑧ note of 2026-11-15] A permission set's own `readable: false` +// binds beside the set's own View All, so the roll-up source rules read that +// mask as hiding the field, on the parent and on the child alike. Modify All +// still votes on every field, so a mask beside it hides nothing. +// +// The pins the note flips stay in `validate-rollup-source-visibility.test.ts`; +// the cases below are the ones it adds. Every case goes through the registry +// runner, for the reason that file gives. +import { describe, expect, it } from 'vitest'; + +import { runAuthoringRules } from './authoring-rules.js'; + +const UNREADABLE = 'security-rollup-source-unreadable'; +const ROW_SCOPED = 'security-rollup-source-row-scoped'; + +type Rec = Record; + +/** `invoice` rolls up `sum(invoice_line.amount)` and `count(invoice_line)`. */ +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', field: 'amount', 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 reading both objects, with `extra` merged over it. */ +const set = (extra: Rec = {}): Rec => ({ + name: 'warehouse_staff', + label: 'Warehouse Staff', + objects: { invoice: READ, invoice_line: READ }, + ...extra, +}); + +const stackOf = (permission: Rec): Rec => ({ objects: [invoice, invoiceLine], permissions: [permission] }); + +const viaRegistry = (stack: Rec) => + runAuthoringRules('lint', { normalized: stack }).filter((f) => f.rule === UNREADABLE || f.rule === ROW_SCOPED); + +const pairs = (findings: readonly { rule: string; where: string }[]) => findings.map((f) => [f.rule, f.where]); + +const W_TOTAL = 'permission set "warehouse_staff" · summary field "invoice.total"'; +const W_COUNT = 'permission set "warehouse_staff" · summary field "invoice.line_count"'; + +describe('a View All set\'s own mask binds', () => { + it('on the parent: the masked summary column is not judged, and the unmasked one still is', () => { + const findings = viaRegistry( + stackOf( + set({ + objects: { invoice: { ...READ, viewAllRecords: true } }, + fields: { 'invoice.total': { readable: false } }, + }), + ), + ); + // The set reads no child object here, so the column it can still see is reported. + expect(pairs(findings)).toEqual([[UNREADABLE, W_COUNT]]); + }); + + it('on the child: the hidden aggregated field is unreadable, so the sum over it is reported', () => { + const findings = viaRegistry( + stackOf( + set({ + objects: { invoice: READ, invoice_line: { ...READ, viewAllRecords: true } }, + fields: { 'invoice_line.amount': { readable: false } }, + }), + ), + ); + expect(pairs(findings)).toEqual([[UNREADABLE, W_TOTAL]]); + }); + + it('a View All parent with no mask gets the plain remedy: the mask it names will bind', () => { + const [f] = viaRegistry(stackOf(set({ objects: { invoice: { ...READ, viewAllRecords: true } } }))); + expect(f.hint).not.toContain('first remove'); + expect(f.hint).toContain('set fields["invoice.total"]: { readable: false } on it'); + }); +}); + +describe('Modify All still votes on every field', () => { + it('both bits on the child entry: the hidden child field is readable, so nothing is reported', () => { + const findings = viaRegistry( + stackOf( + set({ + objects: { invoice: READ, invoice_line: { ...READ, viewAllRecords: true, modifyAllRecords: true } }, + fields: { 'invoice_line.amount': { readable: false } }, + }), + ), + ); + expect(findings).toEqual([]); + }); +}); diff --git a/packages/lint/src/validate-rollup-source-visibility.test.ts b/packages/lint/src/validate-rollup-source-visibility.test.ts index 4b329afc273..aae91a54c0b 100644 --- a/packages/lint/src/validate-rollup-source-visibility.test.ts +++ b/packages/lint/src/validate-rollup-source-visibility.test.ts @@ -266,16 +266,16 @@ describe('silent where the set cannot see the roll-up, or can see its source', ( }); it('Modify All on the child makes a hidden child field readable', () => { - for (const bits of [{ modifyAllRecords: true }, { viewAllRecords: true, modifyAllRecords: true }]) { + for (const bit of ['modifyAllRecords']) { const findings = viaRegistry( stackOf( set({ - objects: { invoice: READ, invoice_line: { ...READ, ...bits } }, + objects: { invoice: READ, invoice_line: { ...READ, [bit]: true } }, fields: { 'invoice_line.amount': { readable: false } }, }), ), ); - expect(findings, JSON.stringify(bits)).toEqual([]); + expect(findings, bit).toEqual([]); } }); @@ -521,41 +521,6 @@ describe('a Modify All parent makes the summary mask inert', () => { }); }); -// ADR-0066 D2 ⑧ note of 2026-11-15: a set's own `readable: false` binds beside -// its own View All, on the parent and on the child alike. -describe('a View All set\'s own mask binds', () => { - it('on the parent: the masked summary column is not judged, and the unmasked one still is', () => { - const findings = viaRegistry( - stackOf( - set({ - objects: { invoice: { ...READ, viewAllRecords: true } }, - fields: { 'invoice.total': { readable: false } }, - }), - ), - ); - // The set reads no child object here, so the column it can still see is reported. - expect(pairs(findings)).toEqual([[UNREADABLE, W_COUNT]]); - }); - - it('on the child: the hidden aggregated field is unreadable, so the sum over it is reported', () => { - const findings = viaRegistry( - stackOf( - set({ - objects: { invoice: READ, invoice_line: { ...READ, viewAllRecords: true } }, - fields: { 'invoice_line.amount': { readable: false } }, - }), - ), - ); - expect(pairs(findings)).toEqual([[UNREADABLE, W_TOTAL]]); - }); - - it('a View All parent with no mask gets the plain remedy: the mask it names will bind', () => { - const [f] = viaRegistry(stackOf(set({ objects: { invoice: { ...READ, viewAllRecords: true } } }))); - expect(f.hint).not.toContain('first remove'); - expect(f.hint).toContain('set fields["invoice.total"]: { readable: false } on it'); - }); -}); - describe('the verdict text (the rule the author is told)', () => { it('states the rule for each arm', () => { const hidden = validateRollupSourceVisibility( diff --git a/packages/lint/src/validate-security-posture-own-field-mask-33828.test.ts b/packages/lint/src/validate-security-posture-own-field-mask-33828.test.ts new file mode 100644 index 00000000000..c82feaa7bcc --- /dev/null +++ b/packages/lint/src/validate-security-posture-own-field-mask-33828.test.ts @@ -0,0 +1,124 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * [ADR-0066 D2 ⑧ note of 2026-11-15] A permission set's own `readable: false` + * row binds its holders beside the set's own View All, so the author-time + * rules stop treating that pair as a mask the set unbinds: + * + * - `security-superuser-field-mask-inert` reports only a row its own set's + * Modify All unbinds, and names Modify All alone; + * - `security-controlled-by-parent-master-reference-hidden` is skipped only + * beside Modify All, so it speaks beside View All. + * + * The pins the note flips stay where they were, in + * `validate-security-posture.test.ts`; the cases below are the ones it adds. + */ + +import { describe, it, expect } from 'vitest'; +import { PermissionSetSchema } from '@objectstack/spec/security'; +import { + SECURITY_CBP_MASTER_REFERENCE_HIDDEN, + SECURITY_SUPERUSER_FIELD_MASK_INERT, + validateSecurityPosture, +} from './validate-security-posture.js'; + +const parsed = (...sets: Array>) => ({ + permissions: sets.map((s) => PermissionSetSchema.parse(s)), +}); + +describe('security-superuser-field-mask-inert · a read mask beside the set\'s own View All binds, so it is not reported', () => { + const only = (stack: Record) => + validateSecurityPosture(stack).filter((f) => f.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT); + const inert = (stack: Record) => only(stack).map((f) => [f.severity, f.where, f.path]); + + it('View All on the object, or through the wildcard, beside the set\'s own readable: false', () => { + expect(inert(parsed({ + name: 'ps', objects: { deal: { allowRead: true, viewAllRecords: true } }, + fields: { 'deal.amount': { readable: false, editable: false } }, + }))).toEqual([]); + // The same pair through the set's wildcard, on a raw set. + expect(inert({ + permissions: [{ name: 'ps', objects: { '*': { viewAllRecords: true } }, fields: { 'deal.amount': { readable: false } } }], + })).toEqual([]); + }); + + it('a wildcard Modify All shadowed by an explicit View All entry is View All alone', () => { + expect(inert({ + permissions: [{ + name: 'ps', + objects: { '*': { modifyAllRecords: true }, deal: { allowRead: true, viewAllRecords: true } }, + fields: { 'deal.amount': { readable: false } }, + }], + })).toEqual([]); + }); + + it('both bits on one entry: the Modify All vote is the one that counts, so the mask is reported', () => { + expect(inert(parsed({ + name: 'ps', objects: { deal: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true } }, + fields: { 'deal.amount': { readable: false } }, + }))).toEqual([['warning', 'permission set "ps"', 'permissions[0].fields["deal.amount"]']]); + }); + + it('the finding names Modify All alone and says which half it unbinds', () => { + const [read] = only(parsed({ + name: 'ps', objects: { sys_user: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { 'sys_user.email': { readable: false, editable: true } }, + })); + const [lock] = only(parsed({ + name: 'ps', objects: { sys_user: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: { 'sys_user.email': { readable: true, editable: false } }, + })); + const [both] = only({ + permissions: [{ name: 'ps', objects: { '*': { modifyAllRecords: true } }, fields: { 'deal.note': { readable: false, editable: false } } }], + }); + expect(read.message).toContain('readable: false'); + expect(read.message).not.toContain('the edit lock'); + expect(lock.message).toContain('the edit lock'); + expect(lock.message).not.toContain('readable: false'); + expect(both.message).toContain('readable: false and the edit lock'); + // The names the user sentence interpolates: no `bypass`, since one bypass is reported. + expect([read, lock, both].map((f) => f.userTextParams)).toEqual([ + { permissionSet: 'ps', field: 'sys_user.email', object: 'sys_user', inert: 'read' }, + { permissionSet: 'ps', field: 'sys_user.email', object: 'sys_user', inert: 'edit' }, + { permissionSet: 'ps', field: 'deal.note', object: 'deal', inert: 'both' }, + ]); + for (const f of [read, lock, both]) { + expect(f.message, f.message).toContain('modifyAllRecords'); + expect(f.message, f.message).not.toContain('viewAllRecords'); + expect(f.hint, f.hint).not.toContain('viewAllRecords'); + } + }); +}); + +describe('security-controlled-by-parent-master-reference-hidden · the set\'s own View All leaves its mask binding', () => { + const TEXT_FIELD = { name: { type: 'text', label: 'Name' } }; + const objectFixture = (extra: Record) => ({ label: 'X', fields: TEXT_FIELD, ...extra }); + const DETAIL = objectFixture({ + name: 'line_item', sharingModel: 'controlled_by_parent', + fields: { + invoice: { type: 'master_detail', label: 'Invoice', reference: 'invoice', required: true }, + note: { type: 'text', label: 'Note' }, + }, + }); + const MASTER = objectFixture({ name: 'invoice', sharingModel: 'private' }); + const rulesOf = (bits: Record) => + validateSecurityPosture({ + objects: [MASTER, DETAIL], + ...parsed({ + name: 'auditor', objects: { line_item: { allowRead: true, ...bits } }, + fields: { 'line_item.invoice': { readable: false, editable: false } }, + }), + }).map((f) => f.rule); + + it('View All on the detail: the hidden master reference is reported, and the inert rule is silent', () => { + const rules = rulesOf({ viewAllRecords: true }); + expect(rules.filter((r) => r === SECURITY_CBP_MASTER_REFERENCE_HIDDEN)).toHaveLength(1); + expect(rules).not.toContain(SECURITY_SUPERUSER_FIELD_MASK_INERT); + }); + + it('control: Modify All on the detail unbinds the mask, so the inert rule speaks instead', () => { + const rules = rulesOf({ allowEdit: true, modifyAllRecords: true }); + expect(rules).not.toContain(SECURITY_CBP_MASTER_REFERENCE_HIDDEN); + expect(rules).toContain(SECURITY_SUPERUSER_FIELD_MASK_INERT); + }); +}); diff --git a/packages/lint/src/validate-security-posture.test.ts b/packages/lint/src/validate-security-posture.test.ts index d8a9664600a..083f0db7afa 100644 --- a/packages/lint/src/validate-security-posture.test.ts +++ b/packages/lint/src/validate-security-posture.test.ts @@ -1757,10 +1757,6 @@ describe('validateSecurityPosture · a field mask its own set\'s Modify All make fields: { 'sys_user.email': { readable: false, editable: false } }, systemPermissions: ['manage_users'], }))).toEqual([]); - // The same pair through the set's wildcard, on a raw set. - expect(inert({ - permissions: [{ name: 'ps', objects: { '*': { viewAllRecords: true } }, fields: { 'deal.amount': { readable: false } } }], - })).toEqual([]); }); it('the composed sets of admin-ledger-decision-metadata.dogfood.test.ts: View All unbinds none of their rows', () => { @@ -1782,16 +1778,11 @@ describe('validateSecurityPosture · a field mask its own set\'s Modify All make ))).toEqual([]); }); - it('Modify All unbinds a read mask too, with or without View All beside it; View All never unbinds an edit lock', () => { + it('Modify All unbinds a read mask too; View All never unbinds an edit lock', () => { expect(inert(parsed({ name: 'ps', objects: { deal: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, fields: { 'deal.amount': { readable: false } }, }))).toEqual([['warning', 'permission set "ps"', 'permissions[0].fields["deal.amount"]']]); - // Both bits on one entry: the Modify All vote is the one that counts. - expect(inert(parsed({ - name: 'ps', objects: { deal: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true } }, - fields: { 'deal.amount': { readable: false } }, - }))).toEqual([['warning', 'permission set "ps"', 'permissions[0].fields["deal.amount"]']]); expect(inert(parsed({ name: 'ps', objects: { deal: { allowRead: true, viewAllRecords: true } }, fields: { 'deal.amount': { readable: true, editable: false } }, @@ -1811,14 +1802,6 @@ describe('validateSecurityPosture · a field mask its own set\'s Modify All make fields: { 'deal.amount': { readable: false } }, }], })).toEqual([]); - // A wildcard Modify All shadowed by an explicit View All entry: View All alone, not reported. - expect(inert({ - permissions: [{ - name: 'ps', - objects: { '*': { modifyAllRecords: true }, deal: { allowRead: true, viewAllRecords: true } }, - fields: { 'deal.amount': { readable: false } }, - }], - })).toEqual([]); }); it('an unparsed entry votes what it spells: an omitted edit bit is a lock under Modify All', () => { @@ -1831,7 +1814,7 @@ describe('validateSecurityPosture · a field mask its own set\'s Modify All make it('controls: a row policy or org depth beside a mask, and another set\'s bypass, get nothing', () => { expect(inert(parsed({ - // `qa_pp_directory_masked` as it stands: every row through a row policy. + // `qa_pp_directory_masked` as repaired: every row through a row policy. name: 'qa_pp_directory_masked', objects: { sys_user: { allowRead: true }, qa_pp_board: { allowRead: true } }, fields: { 'sys_user.email': { readable: false, editable: false } }, @@ -1852,34 +1835,19 @@ describe('validateSecurityPosture · a field mask its own set\'s Modify All make ))).toEqual([]); }); - it('says which half Modify All unbinds, in one line, and the id is explained', () => { - const only = (stack: Record) => - validateSecurityPosture(stack).filter((f) => f.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT); - const [read] = only(parsed({ + it('says which mask Modify All unbinds, in one line, and the id is explained', () => { + const [read] = validateSecurityPosture(parsed({ name: 'ps', objects: { sys_user: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, fields: { 'sys_user.email': { readable: false, editable: true } }, - })); - const [lock] = only(parsed({ - name: 'ps', objects: { sys_user: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, - fields: { 'sys_user.email': { readable: true, editable: false } }, - })); - const [both] = only({ + })).filter((f) => f.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT); + const [write] = validateSecurityPosture({ permissions: [{ name: 'ps', objects: { '*': { modifyAllRecords: true } }, fields: { 'deal.note': { readable: false, editable: false } } }], - }); + }).filter((f) => f.rule === SECURITY_SUPERUSER_FIELD_MASK_INERT); expect(read.message).toContain('modifyAllRecords on objects.sys_user'); expect(read.message).toContain('readable: false'); - expect(read.message).not.toContain('the edit lock'); - expect(lock.message).toContain('the edit lock'); - expect(lock.message).not.toContain('readable: false'); - expect(both.message).toContain("objects['*']"); - expect(both.message).toContain('readable: false and the edit lock'); - expect([read, lock, both].map((f) => f.userTextParams)).toEqual([ - { permissionSet: 'ps', field: 'sys_user.email', object: 'sys_user', inert: 'read' }, - { permissionSet: 'ps', field: 'sys_user.email', object: 'sys_user', inert: 'edit' }, - { permissionSet: 'ps', field: 'deal.note', object: 'deal', inert: 'both' }, - ]); - for (const f of [read, lock, both]) { - expect(f.message, f.message).not.toContain('viewAllRecords'); + expect(write.message).toContain("objects['*']"); + expect(write.message).toContain('modifyAllRecords'); + for (const f of [read, write]) { expect(f.message, f.message).not.toContain('\n'); expect(f.message.length, f.message).toBeLessThanOrEqual(200); expect(f.hint, f.hint).not.toContain('\n'); @@ -2098,16 +2066,6 @@ describe('validateSecurityPosture · a hidden master reference still decides a c expect(validateSecurityPosture(stack).map((f) => f.rule)).toContain(SECURITY_SUPERUSER_FIELD_MASK_INERT); }); - it('the set\'s own View All on the detail leaves the mask binding, so this rule speaks and the inert rule does not', () => { - // ADR-0066 D2 ⑧ note of 2026-11-15: View All casts no vote on a field the set's own row hides. - const stack = withSets([MASTER, DETAIL], { - name: 'auditor', objects: { line_item: { allowRead: true, viewAllRecords: true } }, - fields: { 'line_item.invoice': { readable: false, editable: false } }, - }); - expect(hidden(stack)).toHaveLength(1); - expect(validateSecurityPosture(stack).map((f) => f.rule)).not.toContain(SECURITY_SUPERUSER_FIELD_MASK_INERT); - }); - it('states the rule and its consequence in one line, and the id is explained', () => { const [f] = validateSecurityPosture(withSets([MASTER, DETAIL], { name: 'clerk', objects: {}, fields: { 'line_item.invoice': { readable: false, editable: true } }, diff --git a/packages/plugins/plugin-security/src/fls-own-field-mask-33828.test.ts b/packages/plugins/plugin-security/src/fls-own-field-mask-33828.test.ts new file mode 100644 index 00000000000..e555e023b72 --- /dev/null +++ b/packages/plugins/plugin-security/src/fls-own-field-mask-33828.test.ts @@ -0,0 +1,188 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// [ADR-0066 D2 ⑧ note of 2026-11-15] A permission set's own explicit +// `readable: false` row on a field binds that set's holders over the set's own +// View All vote: the set casts no read vote on the field. Everything else of +// the 2026-11-02 note (ruling of record 6573563853) stands, and is pinned here +// from the other side: +// +// 1. THE SET'S OWN ROW — a holder of the set alone is not served the field, +// in both field merges; +// 2. REVERSE PINS — another set's View All or Modify All on the object still +// reads the field, the shipped `admin_full_access` included; +// 3. UNCHANGED — Modify All votes on every field, the set's own rows +// included, and an edit lock beside View All binds as it always did; +// 4. ROW-BLIND PARITY — `/auth/me/permissions`' merge answers what +// `getFieldPermissions` answers on every pair above; +// 5. THE ROW-LEVEL BYPASS — the set still holds View All on the object. +// +// The fixtures follow `fls-superuser-vote.test.ts`, which keeps the pins of +// the ruling this note amends. + +import { describe, it, expect } from 'vitest'; +import type { PermissionSet } from '@objectstack/spec/security'; +import { PermissionSetSchema } from '@objectstack/spec/security'; +import { ADMIN_FULL_ACCESS } from '@objectstack/spec'; +import { buildEffectiveFieldPermissions } from '@objectstack/core'; +import { PermissionEvaluator } from './permission-evaluator.js'; +import { defaultPermissionSets } from './objects/default-permission-sets.js'; + +const OBJ = 'sys_business_unit'; +const MASKED = ['code', 'kind', 'manager_user_id', 'active'] as const; + +const shipped = (name: string): PermissionSet => { + const found = defaultPermissionSets.find((s) => s.name === name); + if (!found) throw new Error(`shipped set ${name} not found`); + return found; +}; + +const set = (raw: Record): PermissionSet => PermissionSetSchema.parse(raw); + +/** The rows hiding every listed field, for a set that also holds a bypass bit on the object. */ +const OWN_MASK = Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: false, editable: false }])); + +/** An app set with plain object read and the same rows: no bypass of its own. */ +const APP_MASK = set({ name: 'app_member', objects: { [OBJ]: { allowRead: true } }, fields: OWN_MASK }); + +const VIEW_ALL = set({ name: 'auditor', objects: { [OBJ]: { allowRead: true, viewAllRecords: true } } }); +const MODIFY_ALL = set({ + name: 'operator', + objects: { [OBJ]: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, +}); + +/** View All on the object, and the set's own rows hiding fields of it. */ +const VIEW_ALL_OWN_MASK = set({ + name: 'auditor_masked', + objects: { [OBJ]: { allowRead: true, viewAllRecords: true } }, + fields: OWN_MASK, +}); +/** The same pair through the set's `'*'` wildcard. */ +const WILDCARD_VIEW_ALL_OWN_MASK = set({ + name: 'wildcard_auditor_masked', + objects: { '*': { allowRead: true, viewAllRecords: true } }, + fields: OWN_MASK, +}); +/** Modify All on the object beside the set's own rows. */ +const MODIFY_ALL_OWN_MASK = set({ + name: 'operator_masked', + objects: { [OBJ]: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: OWN_MASK, +}); + +const evaluator = new PermissionEvaluator(); +const merge = (sets: PermissionSet[]) => evaluator.getFieldPermissions(OBJ, sets); +/** The `fields` slot `/auth/me/permissions` serves for `sets`, projected to this object's fields. */ +const rowBlind = (sets: PermissionSet[]) => + Object.fromEntries( + Object.entries(buildEffectiveFieldPermissions(sets)) + .filter(([k]) => k.startsWith(`${OBJ}.`)) + .map(([k, v]) => [k.slice(OBJ.length + 1), v]), + ); + +/** + * The two merges every reading below is taken from: `getFieldPermissions`, + * which every data door reads, and the `fields` slot `/auth/me/permissions` + * serves. One `describe` per merge, so each is red or green on its own. + */ +const MERGES: Array<[string, (sets: PermissionSet[]) => Record]> = [ + ['getFieldPermissions', merge], + ['/auth/me/permissions', rowBlind], +]; + +describe.each(MERGES)('[ADR-0066 ⑧ note of 2026-11-15] a set\'s own readable: false row wins over its own View All vote · %s', (_merge, read) => { + it('a holder of the set alone is not served the fields the set hides', () => { + const fp = read([VIEW_ALL_OWN_MASK]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: false, editable: false }); + }); + + it('the same holds when the set holds View All through its wildcard', () => { + const fp = read([WILDCARD_VIEW_ALL_OWN_MASK]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: false, editable: false }); + }); + + it('a plain co-held set changes nothing: only a vote reads a field', () => { + const plain = set({ name: 'plain', objects: { [OBJ]: { allowRead: true, allowEdit: true } } }); + const fp = read([VIEW_ALL_OWN_MASK, plain]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: false, editable: false }); + }); + + it('the set\'s View All still reads a field ANOTHER set hides', () => { + const partial = set({ + name: 'auditor_partial', + objects: { [OBJ]: { allowRead: true, viewAllRecords: true } }, + fields: { [`${OBJ}.code`]: { readable: false, editable: false } }, + }); + const fp = read([partial, APP_MASK]); + expect(fp.code, 'code').toEqual({ readable: false, editable: false }); + for (const f of MASKED.filter((m) => m !== 'code')) expect(fp[f], f).toEqual({ readable: true, editable: false }); + }); + + it('[reverse pin, ruling 6573563853] a second set holding View All on the object still reads every field', () => { + const fp = read([VIEW_ALL_OWN_MASK, VIEW_ALL]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: true, editable: false }); + // Resolution order does not matter. + expect(read([VIEW_ALL, VIEW_ALL_OWN_MASK])).toEqual(fp); + }); + + it('[reverse pin, ruling 6573563853] a second set holding Modify All on the object still reads and edits every field', () => { + for (const second of [MODIFY_ALL, shipped(ADMIN_FULL_ACCESS)]) { + const fp = read([VIEW_ALL_OWN_MASK, second]); + for (const f of MASKED) expect(fp[f], `${second.name} ${f}`).toEqual({ readable: true, editable: true }); + // Resolution order does not matter. + expect(read([second, VIEW_ALL_OWN_MASK])).toEqual(fp); + } + }); + + it('[unchanged] Modify All votes on every field, the set\'s own rows included', () => { + const own = read([MODIFY_ALL_OWN_MASK]); + for (const f of MASKED) expect(own[f], f).toEqual({ readable: true, editable: true }); + const readOnlyRows = set({ + name: 'operator_read_only_rows', + objects: { [OBJ]: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, + fields: Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: true, editable: false }])), + }); + const locked = read([readOnlyRows]); + for (const f of MASKED) expect(locked[f], f).toEqual({ readable: true, editable: true }); + // Both bits on one entry: the Modify All vote is the one that counts. + const both = set({ + name: 'both_bits_masked', + objects: { [OBJ]: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true } }, + fields: OWN_MASK, + }); + const bothBits = read([both]); + for (const f of MASKED) expect(bothBits[f], f).toEqual({ readable: true, editable: true }); + }); + + it('[unchanged] an edit lock beside the set\'s own View All binds: View All never granted an edit', () => { + const lock = set({ + name: 'auditor_read_only_rows', + objects: { [OBJ]: { allowRead: true, allowEdit: true, viewAllRecords: true } }, + fields: Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: true, editable: false }])), + }); + const fp = read([lock]); + for (const f of MASKED) expect(fp[f], f).toEqual({ readable: true, editable: false }); + }); +}); + +describe('[ADR-0066 ⑧ note of 2026-11-15] the row-blind /auth/me/permissions merge agrees with getFieldPermissions', () => { + const combos: Array<[string, PermissionSet[]]> = [ + ['viewAll with its own mask', [VIEW_ALL_OWN_MASK]], + ['wildcard viewAll with its own mask', [WILDCARD_VIEW_ALL_OWN_MASK]], + ['viewAll with its own mask + viewAll', [VIEW_ALL_OWN_MASK, VIEW_ALL]], + ['viewAll with its own mask + modifyAll', [VIEW_ALL_OWN_MASK, MODIFY_ALL]], + ['viewAll with its own mask + admin_full_access', [VIEW_ALL_OWN_MASK, shipped(ADMIN_FULL_ACCESS)]], + ['viewAll with its own mask + the app mask', [VIEW_ALL_OWN_MASK, APP_MASK]], + ['modifyAll with its own mask', [MODIFY_ALL_OWN_MASK]], + ]; + + it.each(combos)('%s', (_label, sets) => { + expect(rowBlind(sets)).toEqual(merge(sets)); + }); +}); + +describe('[ADR-0066 ⑧ note of 2026-11-15] the row-level bypass is untouched', () => { + it('a View All set that hides a field of the object still holds View All on it', () => { + expect(evaluator.superuserBypassSets(OBJ, [VIEW_ALL_OWN_MASK], { bit: 'view' })).toEqual(['auditor_masked']); + expect(evaluator.superuserBypassSets(OBJ, [VIEW_ALL_OWN_MASK], { bit: 'modify' })).toEqual([]); + }); +}); diff --git a/packages/plugins/plugin-security/src/fls-superuser-vote.test.ts b/packages/plugins/plugin-security/src/fls-superuser-vote.test.ts index 0cd8f47aca2..d98ef98e72e 100644 --- a/packages/plugins/plugin-security/src/fls-superuser-vote.test.ts +++ b/packages/plugins/plugin-security/src/fls-superuser-vote.test.ts @@ -24,10 +24,7 @@ // disagree about who is a super-user on an object; // 4. ROW-BLIND PARITY — `/auth/me/permissions`' merge // (`buildEffectiveFieldPermissions`, `@objectstack/core`) answers the same -// bits as `getFieldPermissions` for the same sets; -// 5. THE SET'S OWN ROW (ADR-0066 D2 ⑧ note of 2026-11-15) — a View All set's -// own `readable: false` row binds its holders in both merges; another -// set's bypass still reads the field, and Modify All votes as before. +// bits as `getFieldPermissions` for the same sets. // // The HTTP doors (list, sort, record read, `/auth/me/permissions`, explain) are // pinned on a real boot in @@ -77,36 +74,8 @@ const SHADOWED_WILDCARD = set({ objects: { '*': { allowRead: true, viewAllRecords: true, modifyAllRecords: true }, [OBJ]: { allowRead: true } }, }); -/** The field rows of {@link APP_MASK}, for a set that also holds a bypass bit on the object. */ -const OWN_MASK = Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: false, editable: false }])); -/** View All on the object, and the set's own rows hiding fields of it. */ -const VIEW_ALL_OWN_MASK = set({ - name: 'auditor_masked', - objects: { [OBJ]: { allowRead: true, viewAllRecords: true } }, - fields: OWN_MASK, -}); -/** The same pair through the set's `'*'` wildcard. */ -const WILDCARD_VIEW_ALL_OWN_MASK = set({ - name: 'wildcard_auditor_masked', - objects: { '*': { allowRead: true, viewAllRecords: true } }, - fields: OWN_MASK, -}); -/** Modify All on the object beside the set's own rows. */ -const MODIFY_ALL_OWN_MASK = set({ - name: 'operator_masked', - objects: { [OBJ]: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, - fields: OWN_MASK, -}); - const evaluator = new PermissionEvaluator(); const merge = (sets: PermissionSet[]) => evaluator.getFieldPermissions(OBJ, sets); -/** The `fields` slot `/auth/me/permissions` serves for `sets`, projected to this object's fields. */ -const rowBlind = (sets: PermissionSet[]) => - Object.fromEntries( - Object.entries(buildEffectiveFieldPermissions(sets)) - .filter(([k]) => k.startsWith(`${OBJ}.`)) - .map(([k, v]) => [k.slice(OBJ.length + 1), v]), - ); describe('[ADR-0066 ⑧, ruling 6573563853] a super-user set votes on every field of its object', () => { it('the shipped admin_full_access reaches the object through its wildcard super-user bits (premise guard)', () => { @@ -209,104 +178,16 @@ describe('[ruling 6573563853] the row-blind /auth/me/permissions merge agrees wi ['modifyAll + read-only', [MODIFY_ALL, APP_READ_ONLY]], ['shadowed wildcard + mask', [SHADOWED_WILDCARD, APP_MASK]], ['member_default + mask', [shipped('member_default'), APP_MASK]], - ['viewAll with its own mask', [VIEW_ALL_OWN_MASK]], - ['viewAll with its own mask + viewAll', [VIEW_ALL_OWN_MASK, VIEW_ALL]], - ['viewAll with its own mask + modifyAll', [VIEW_ALL_OWN_MASK, MODIFY_ALL]], - ['viewAll with its own mask + admin_full_access', [VIEW_ALL_OWN_MASK, shipped(ADMIN_FULL_ACCESS)]], - ['modifyAll with its own mask', [MODIFY_ALL_OWN_MASK]], ]; it.each(combos)('%s', (_label, sets) => { - expect(rowBlind(sets)).toEqual(merge(sets)); - }); -}); - -/** - * The two merges every reading below is taken from: `getFieldPermissions`, - * which every data door reads, and the `fields` slot `/auth/me/permissions` - * serves. One `describe` per merge, so each is red or green on its own. - */ -const MERGES: Array<[string, (sets: PermissionSet[]) => Record]> = [ - ['getFieldPermissions', merge], - ['/auth/me/permissions', rowBlind], -]; - -describe.each(MERGES)('[ADR-0066 ⑧ note of 2026-11-15] a set\'s own readable: false row wins over its own View All vote · %s', (_merge, read) => { - it('a holder of the set alone is not served the fields the set hides', () => { - const fp = read([VIEW_ALL_OWN_MASK]); - for (const f of MASKED) expect(fp[f], f).toEqual({ readable: false, editable: false }); - }); - - it('the same holds when the set holds View All through its wildcard', () => { - const fp = read([WILDCARD_VIEW_ALL_OWN_MASK]); - for (const f of MASKED) expect(fp[f], f).toEqual({ readable: false, editable: false }); - }); - - it('a plain co-held set changes nothing: only a vote reads a field', () => { - const plain = set({ name: 'plain', objects: { [OBJ]: { allowRead: true, allowEdit: true } } }); - const fp = read([VIEW_ALL_OWN_MASK, plain]); - for (const f of MASKED) expect(fp[f], f).toEqual({ readable: false, editable: false }); - }); - - it('the set\'s View All still reads a field ANOTHER set hides', () => { - const partial = set({ - name: 'auditor_partial', - objects: { [OBJ]: { allowRead: true, viewAllRecords: true } }, - fields: { [`${OBJ}.code`]: { readable: false, editable: false } }, - }); - const fp = read([partial, APP_MASK]); - expect(fp.code, 'code').toEqual({ readable: false, editable: false }); - for (const f of MASKED.filter((m) => m !== 'code')) expect(fp[f], f).toEqual({ readable: true, editable: false }); - }); - - it('[reverse pin, ruling 6573563853] a second set holding View All on the object still reads every field', () => { - const fp = read([VIEW_ALL_OWN_MASK, VIEW_ALL]); - for (const f of MASKED) expect(fp[f], f).toEqual({ readable: true, editable: false }); - }); - - it('[reverse pin, ruling 6573563853] a second set holding Modify All on the object still reads and edits every field', () => { - for (const second of [MODIFY_ALL, shipped(ADMIN_FULL_ACCESS)]) { - const fp = read([VIEW_ALL_OWN_MASK, second]); - for (const f of MASKED) expect(fp[f], `${second.name} ${f}`).toEqual({ readable: true, editable: true }); - // Resolution order does not matter. - expect(read([second, VIEW_ALL_OWN_MASK])).toEqual(fp); - } - }); - - it('[unchanged] Modify All votes on every field, the set\'s own rows included', () => { - const own = read([MODIFY_ALL_OWN_MASK]); - for (const f of MASKED) expect(own[f], f).toEqual({ readable: true, editable: true }); - const readOnlyRows = set({ - name: 'operator_read_only_rows', - objects: { [OBJ]: { allowRead: true, allowEdit: true, modifyAllRecords: true } }, - fields: Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: true, editable: false }])), - }); - const locked = read([readOnlyRows]); - for (const f of MASKED) expect(locked[f], f).toEqual({ readable: true, editable: true }); - // Both bits on one entry: the Modify All vote is the one that counts. - const both = set({ - name: 'both_bits_masked', - objects: { [OBJ]: { allowRead: true, allowEdit: true, viewAllRecords: true, modifyAllRecords: true } }, - fields: OWN_MASK, - }); - const bothBits = read([both]); - for (const f of MASKED) expect(bothBits[f], f).toEqual({ readable: true, editable: true }); - }); - - it('[unchanged] an edit lock beside the set\'s own View All binds: View All never granted an edit', () => { - const lock = set({ - name: 'auditor_read_only_rows', - objects: { [OBJ]: { allowRead: true, allowEdit: true, viewAllRecords: true } }, - fields: Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: true, editable: false }])), - }); - const fp = read([lock]); - for (const f of MASKED) expect(fp[f], f).toEqual({ readable: true, editable: false }); - }); -}); - -describe('[ADR-0066 ⑧ note of 2026-11-15] the row-level bypass is untouched', () => { - it('a View All set that hides a field of the object still holds View All on it', () => { - expect(evaluator.superuserBypassSets(OBJ, [VIEW_ALL_OWN_MASK], { bit: 'view' })).toEqual(['auditor_masked']); - expect(evaluator.superuserBypassSets(OBJ, [VIEW_ALL_OWN_MASK], { bit: 'modify' })).toEqual([]); + const perObject = merge(sets); + const rowBlind = buildEffectiveFieldPermissions(sets); + const projected = Object.fromEntries( + Object.entries(rowBlind) + .filter(([k]) => k.startsWith(`${OBJ}.`)) + .map(([k, v]) => [k.slice(OBJ.length + 1), v]), + ); + expect(projected).toEqual(perObject); }); }); From 25dcfa863613d10673918f081c89e6d0b09b558d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 22:10:03 +0000 Subject: [PATCH 3/4] fix(core, plugin-security, lint)!: the own field-mask rule is declared semantic, registered for the upgrade guide and pinned at two doors The changeset declares the kind semantic and grades core and plugin-security minor: the meaning of a set's own `readable: false` row beside that set's View All changes for the set's holders. Its ADR-0087 disposition is now a registered semantic entry, which tells an administrator how to find the pair and what to decide. The exported `superuserFieldVote` is named as the one widening. A door-level pin boots the showcase and asks `/auth/me/permissions` and the list door for a holder of the pair, with a second View All set as the control. The changeset and the authorization page say what "another set reads the field" means: a read vote, never a co-held set that says nothing about it. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv --- ...-own-field-mask-binds-over-own-view-all.md | 16 +- content/docs/permissions/authorization.mdx | 9 +- .../fls-own-field-mask-33828.dogfood.test.ts | 152 ++++++++++++++++++ ...-own-field-mask-binds-over-own-view-all.ts | 47 ++++++ 4 files changed, 214 insertions(+), 10 deletions(-) create mode 100644 packages/qa/dogfood/test/fls-own-field-mask-33828.dogfood.test.ts create mode 100644 packages/spec/src/migrations/entries/semantic/18.permission-own-field-mask-binds-over-own-view-all.ts diff --git a/.changeset/33828-own-field-mask-binds-over-own-view-all.md b/.changeset/33828-own-field-mask-binds-over-own-view-all.md index 7428dcd3b2d..92fe7f1c98b 100644 --- a/.changeset/33828-own-field-mask-binds-over-own-view-all.md +++ b/.changeset/33828-own-field-mask-binds-over-own-view-all.md @@ -1,18 +1,18 @@ --- -'@objectstack/core': patch -'@objectstack/plugin-security': patch +'@objectstack/core': minor +'@objectstack/plugin-security': minor '@objectstack/lint': patch '@objectstack/spec': patch --- fix(core, plugin-security, lint)!: a permission set's own field-mask row binds its own holders over that set's View All vote -Clause-②: no (narrowing) -Metadata-protocol: none +Clause-②: yes (narrowing) +Metadata-protocol: semantic - + -**BREAKING** for the holders of a permission set that grants View All (`viewAllRecords`) on an object and declares `readable: false` on a field of that object in its own `fields`. Per ADR-0066 D2 ⑧ as amended on 2026-11-15 (the maintainer's ruling on the card), that row wins over the same set's View All field vote: the set casts no read vote on the field, so a caller whom no other set serves the field to does not read it. Every reader of the field merge answers the same: the data doors, through `PermissionEvaluator.getFieldPermissions`, and the `fields` slot of `/auth/me/permissions`. Until this release the set's own View All voted the field readable, so the row bound none of the set's holders (the ADR's note of 2026-11-02). +**BREAKING** for the holders of a permission set that grants View All (`viewAllRecords`) on an object and declares `readable: false` on a field of that object in its own `fields`. Per ADR-0066 D2 ⑧ as amended on 2026-11-15 (the maintainer's ruling on the card), that row wins over the same set's View All field vote: the set casts no read vote on the field, so a holder reads it only when another set they hold casts a read vote on it (that set's own `readable: true` row, or its View All or Modify All on the object). A co-held set that says nothing about the field does not restore it. Every reader of the field merge answers the same: the data doors, through `PermissionEvaluator.getFieldPermissions`, and the `fields` slot of `/auth/me/permissions`. Until this release the set's own View All voted the field readable, so the row bound none of the set's holders (the ADR's note of 2026-11-02). **Not moved.** Another set's View All or Modify All on the object still makes the field readable (and, under Modify All, editable) for a caller who holds both sets. A View All set still votes on every field it does not mask itself. An omitted `readable` parses to `true` and is not a mask. View All never granted an edit, so an edit lock beside it binds as before. Modify All is unchanged: a set holding `modifyAllRecords` on the object votes `readable: true` and `editable: true` on every field of it, its own rows included. The row-level bypass is untouched. @@ -20,4 +20,6 @@ Metadata-protocol: none `@objectstack/lint`: `security-superuser-field-mask-inert` reports only a row that its own set's Modify All unbinds (a `readable: false`, an edit lock, or both). A `readable: false` beside the set's own View All is no longer reported, because it binds. The finding's `userTextParams` no longer carry `bypass` (Modify All is the only bypass the rule reports), and its message, hint and user sentence name Modify All. `security-controlled-by-parent-master-reference-hidden` is skipped only beside Modify All and is reported beside View All, and the roll-up source visibility rule reads a View All set's own mask as hiding the field. The rule ids are unchanged. -`@objectstack/spec`: the doc comment above `FieldPermissionSchema` states the exception. No schema, description or generated artifact changes. +`@objectstack/core`: the exported `superuserFieldVote(sets, objectName)` takes an optional third argument, the field name, and reads the `fields` of the sets it is given. Called with two arguments it answers the object-wide vote, as before. + +`@objectstack/spec`: the doc comment above `FieldPermissionSchema` states the exception, and the upgrade guide gains the semantic entry `permission-own-field-mask-binds-over-own-view-all`, which tells an administrator how to find the pair and what to decide. No schema, description or generated artifact changes. diff --git a/content/docs/permissions/authorization.mdx b/content/docs/permissions/authorization.mdx index 04c0e645ff4..6337c1b2b3a 100644 --- a/content/docs/permissions/authorization.mdx +++ b/content/docs/permissions/authorization.mdx @@ -161,9 +161,12 @@ another set's `readable: false` never hides a field from a caller who also holds a View All or Modify All set on its object; a field's `requiredPermissions` capability gate still applies to every caller. One exception: a View All set casts no read vote on a field its **own** -`readable: false` entry hides, so that entry binds the set's holders (unless -another set they hold reads the field). A Modify All set still votes on every -field, its own entries included. Otherwise union without deny is unchanged. +`readable: false` entry hides, so that entry binds the set's holders, unless +another set they hold casts a read vote on the field (its own `readable: true` +entry, or View All or Modify All on the object); a co-held set that says +nothing about the field does not restore it. A Modify All set still votes on +every field, its own entries included. Otherwise union without deny is +unchanged. Until the muting layer lands, protect sensitive fields by granting them only in the sets that need them, grant the object without Modify All to a set that must withhold a field from its own holders, and treat "sensitive field on a diff --git a/packages/qa/dogfood/test/fls-own-field-mask-33828.dogfood.test.ts b/packages/qa/dogfood/test/fls-own-field-mask-33828.dogfood.test.ts new file mode 100644 index 00000000000..a10f56bc57b --- /dev/null +++ b/packages/qa/dogfood/test/fls-own-field-mask-33828.dogfood.test.ts @@ -0,0 +1,152 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. +// +// [ADR-0066 D2 ⑧ note of 2026-11-15] A permission set's own explicit +// `readable: false` row on a field binds that set's holders over the set's own +// View All vote. Pinned here on a real boot, at the two doors a consumer +// meets the rule on: +// +// - row-blind merge `GET /auth/me/permissions` → `fields` +// - list projection `GET /data/sys_business_unit` +// +// Two members are asked at each door. The first holds the pair alone (a set +// granting View All on the object and hiding four of its fields in its own +// rows): the fields are not served. The second also holds a set that grants +// View All on the object and names no field (the control the 2026-11-02 note +// keeps, ruling of record 6573563853): another set's View All still reads +// every field, and never edits one. +// +// The pure merges are pinned in +// `packages/plugins/plugin-security/src/fls-own-field-mask-33828.test.ts` and +// `packages/core/src/security/superuser-field-vote-33828.test.ts`; the doors +// the 2026-11-02 note opened are pinned in `fls-superuser-vote.dogfood.test.ts`. + +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; +import { type VerifyStack } from '@objectstack/verify'; +import { bootShowcase } from './showcase-boot.js'; +import { showcaseAppDefaultSecurity } from './showcase-security.js'; +import { catalogPermissionSet } from './catalog-permission-set.js'; + +const SYS = { isSystem: true } as const; +const OBJ = 'sys_business_unit'; +/** The seeded unit the list assertions read (`examples/app-showcase` seed, `code: 'ACME'`). */ +const UNIT = 'bu_acme'; +/** The fields the pair hides in its own rows. */ +const MASKED = ['code', 'kind', 'manager_user_id', 'active'] as const; +/** The masked fields the seeded unit stores a value for (the oracle of the control's list read). */ +const STORED = ['code', 'kind', 'active'] as const; +/** View All on the object, and the set's own rows hiding fields of it. */ +const PAIR_SET = 'showcase_scratch_bu_own_field_mask'; +/** View All on the object, and no field row. */ +const SECOND_SET = 'showcase_scratch_bu_view_all'; +const HOLDER = 'fls-own-field-mask.holder@verify.test'; +const BOTH = 'fls-own-field-mask.both@verify.test'; + +const rowsOf = (b: any) => b?.records ?? b?.data ?? (Array.isArray(b) ? b : []); +const has = (row: any, key: string) => Object.prototype.hasOwnProperty.call(row ?? {}, key); + +describe('[ADR-0066 ⑧ note of 2026-11-15] a set\'s own readable: false row binds its holders beside its own View All; a second View All set still reads', () => { + let stack: VerifyStack; + let ql: any; + let holderTok: string; + let bothTok: string; + + beforeAll(async () => { + stack = await bootShowcase({ security: showcaseAppDefaultSecurity() }); + const adminTok = await stack.signIn(); // the seeded platform admin first, so the sign-ups are plain members + holderTok = await stack.signUp(HOLDER); + bothTok = await stack.signUp(BOTH); + ql = await stack.kernel.getServiceAsync('objectql'); + + // Both sets are authored through the metadata door (ADR-0131 D3/D4). + const sets = [ + { + name: PAIR_SET, + label: 'Scratch: View All on business units, own field mask', + description: 'Test-authored (ADR-0066 D2 ⑧ note of 2026-11-15): View All on the object, four fields hidden in its own rows.', + objects: { [OBJ]: { allowRead: true, viewAllRecords: true } }, + fields: Object.fromEntries(MASKED.map((f) => [`${OBJ}.${f}`, { readable: false, editable: false }])), + }, + { + name: SECOND_SET, + label: 'Scratch: View All on business units', + description: 'Test-authored (ADR-0066 D2 ⑧ note of 2026-11-15): View All on the object, no field row.', + objects: { [OBJ]: { allowRead: true, viewAllRecords: true } }, + }, + ]; + for (const body of sets) { + const authored = await stack.apiAs(adminTok, 'PUT', `/meta/permission/${body.name}`, body); + expect(authored.status, `${body.name} authored: ${await authored.clone().text()}`).toBeLessThan(300); + expect(await catalogPermissionSet(ql, body.name), `the catalog serves ${body.name}`).toBeTruthy(); + } + + const holderId = (await ql.findOne('sys_user', { where: { email: HOLDER }, context: SYS }))?.id; + const bothId = (await ql.findOne('sys_user', { where: { email: BOTH }, context: SYS }))?.id; + expect(holderId, 'holder provisioned').toBeTruthy(); + expect(bothId, 'second member provisioned').toBeTruthy(); + const grants: Array<[string, string]> = [ + [holderId, PAIR_SET], + [bothId, PAIR_SET], + [bothId, SECOND_SET], + ]; + for (const [user_id, permission_set] of grants) { + await ql.insert('sys_user_permission_set', { user_id, permission_set }, { context: SYS }); + } + + const stored = await ql.findOne(OBJ, { where: { id: UNIT }, context: SYS }); + for (const f of STORED) { + expect(stored?.[f], `the seeded unit carries ${f} (the oracle the reads compare to)`).not.toBeUndefined(); + } + }, 300_000); + + afterAll(async () => { + await stack?.stop?.(); + }); + + const mePermissions = async (tok: string) => { + const r = await stack.apiAs(tok, 'GET', '/auth/me/permissions'); + expect(r.status).toBe(200); + const body: any = await r.json(); + return body?.data ?? body; + }; + + it('premise: the holder holds the pair alone; the second member holds the pair and the plain View All set; neither holds admin_full_access', async () => { + const holder = await mePermissions(holderTok); + expect(holder.permissionSets).toContain(PAIR_SET); + expect(holder.permissionSets).not.toContain(SECOND_SET); + expect(holder.permissionSets).not.toContain('admin_full_access'); + const both = await mePermissions(bothTok); + expect(both.permissionSets).toEqual(expect.arrayContaining([PAIR_SET, SECOND_SET])); + expect(both.permissionSets).not.toContain('admin_full_access'); + }); + + // ── /auth/me/permissions — the row-blind merge ───────────────────────────── + it('/auth/me/permissions: the holder is told every field the set hides is unreadable', async () => { + const { fields } = await mePermissions(holderTok); + for (const f of MASKED) expect(fields?.[`${OBJ}.${f}`], f).toEqual({ readable: false, editable: false }); + }); + + it('[control] /auth/me/permissions: the second set\'s View All reads every hidden field, and edits none', async () => { + const { fields } = await mePermissions(bothTok); + for (const f of MASKED) expect(fields?.[`${OBJ}.${f}`], f).toEqual({ readable: true, editable: false }); + }); + + // ── list projection ───────────────────────────────────────────────────────── + it('list: the holder reads the rows, and none of the fields the set hides', async () => { + const r = await stack.apiAs(holderTok, 'GET', `/data/${OBJ}`); + expect(r.status).toBe(200); + const rows = rowsOf(await r.json()); + expect(rows.map((row: any) => row.id), 'the holder lists the seeded unit (vacuity guard)').toContain(UNIT); + for (const row of rows) { + expect(has(row, 'name'), 'the field the set does not hide is served').toBe(true); + for (const f of MASKED) expect(has(row, f), `holder list strips ${f} (row ${row.id})`).toBe(false); + } + }); + + it('[control] list: the second member is served the hidden fields', async () => { + const r = await stack.apiAs(bothTok, 'GET', `/data/${OBJ}`); + expect(r.status).toBe(200); + const row = rowsOf(await r.json()).find((candidate: any) => candidate.id === UNIT); + expect(row, 'the second member lists the seeded unit').toBeTruthy(); + for (const f of STORED) expect(has(row, f), `second member list carries ${f}`).toBe(true); + }); +}); diff --git a/packages/spec/src/migrations/entries/semantic/18.permission-own-field-mask-binds-over-own-view-all.ts b/packages/spec/src/migrations/entries/semantic/18.permission-own-field-mask-binds-over-own-view-all.ts new file mode 100644 index 00000000000..21729ced74b --- /dev/null +++ b/packages/spec/src/migrations/entries/semantic/18.permission-own-field-mask-binds-over-own-view-all.ts @@ -0,0 +1,47 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +import type { SemanticMigration } from '../../types.js'; + +// No D2 conversion: whether the holders of the set should read the field or +// should not is a judgement only the author can make, and either rewrite would +// change an access decision (deleting the row serves the field to them, keeping +// it withholds the field). Stored rows need none: the pair parses as it did. +export const entry: SemanticMigration = { + id: 'permission-own-field-mask-binds-over-own-view-all', + surface: + 'security.permission.fields.*.readable (FieldPermissionSchema) set to false, in a permission set ' + + 'whose own object entry for the field\'s object (the `*` wildcard included) grants viewAllRecords ' + + 'and does not grant modifyAllRecords', + replacement: + 'Decide which of the two the permission set means. If its holders should read the field: delete the ' + + 'field row, or set `readable: true` on it. If they should not: keep the row, which now hides the ' + + 'field from them. FROM `objects: { crm_lead: { allowRead: true, viewAllRecords: true } }, fields: ' + + '{ \'crm_lead.score\': { readable: false } }` (the row bound none of the set\'s holders) TO the same ' + + 'pair (the row hides `score` from them), or to the pair without the row (they read `score`).', + reason: + 'Maintainer ruling, 2026-11-15 (ADR-0066 D2 ⑧, note of 2026-11-15): an explicit `readable: false` ' + + 'field-permission row on a permission set wins over that same set\'s View All field vote. A set that ' + + 'holds View All on an object, and not Modify All, casts no read vote on a field its own row hides, so ' + + 'a holder reads the field only when another set they hold casts a read vote on it: that set\'s own ' + + '`readable: true` row, or its View All or Modify All on the object. A co-held set that says nothing ' + + 'about the field does not restore it. Every reader of the field-permission merge answers the same: ' + + 'the data doors, through `PermissionEvaluator.getFieldPermissions`, and the `fields` slot of ' + + '`/auth/me/permissions`. Until this release the set\'s own View All voted the field readable, so the ' + + 'row bound none of the set\'s holders (the ADR\'s note of 2026-11-02).\n\n' + + 'NOT MOVED: another set\'s View All or Modify All on the object still reads the field for a caller ' + + 'who holds both sets; a View All set still votes on every field it does not hide itself; an omitted ' + + '`readable` parses to `true` and is not a mask; an edit lock beside View All binds as before; a set ' + + 'holding Modify All on the object votes on every field of it, its own rows included; the row-level ' + + 'bypass does not read field rows.\n\n' + + 'STORED ROWS: a permission set stored before this release keeps loading unchanged, and its row ' + + 'starts to bind when the release runs. No mechanical rewrite exists in either direction: deleting ' + + 'the row and keeping it are both access decisions.', + acceptanceCriteria: + 'Search every authored and stored permission set for a `fields` row with `readable: false` on a field ' + + 'of an object that the same set grants `viewAllRecords` (through the object\'s own entry or the `*` ' + + 'wildcard) without `modifyAllRecords`, and decide as the replacement says. On a release from ' + + '18.3.0 up to this change, `os validate` names each such row with the warning ' + + '`security-superuser-field-mask-inert` beside View All; from this release that rule reports only a ' + + 'row beside the set\'s own Modify All, so it no longer lists the pair. The repository carried no ' + + 'shipped permission set with the pair at the time of the change.', +}; From 880f1686bc6bf02b2830dc35e065b9b7b203bb23 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 14:52:06 +0000 Subject: [PATCH 4/4] test(plugin-security): the View All controls of the computed-field masking suite follow the own field-mask rule A set's own readable: false row binds that set's holders over the same set's View All (ADR-0066 D2 note of 2026-11-15). The two View All controls booted View All on the set that declares the row, so they pinned the earlier reading. - View All on the set that hides the field: the field and the computed fields over it stay withheld (new pin, ablated against the rule). - View All held through another set: still reads the hidden field and the formulas over it, and is still withheld a computed field over a capability-gated or masked field (the two controls, kept via that route). Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw Co-Authored-By: Claude --- ...formula-reads-hidden-field-masking.test.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/plugins/plugin-security/src/formula-reads-hidden-field-masking.test.ts b/packages/plugins/plugin-security/src/formula-reads-hidden-field-masking.test.ts index 2712aa21137..a08dd415e68 100644 --- a/packages/plugins/plugin-security/src/formula-reads-hidden-field-masking.test.ts +++ b/packages/plugins/plugin-security/src/formula-reads-hidden-field-masking.test.ts @@ -92,8 +92,13 @@ interface BootOptions { secondFields?: FieldEntries; /** Capabilities the caller's permission set grants. */ capabilities?: string[]; - /** The object grant's View All (reads every field of the object). */ + /** + * The object grant's View All. It reads every field of the object the set's + * own rows do not declare `readable: false` (ADR-0066 D2 ⑧). + */ viewAllRecords?: boolean; + /** View All on the object in the second set, held only by {@link TWO_SETS}. */ + secondViewAll?: boolean; /** * Boot the identity objects and a delegator user holding {@link DELEGATOR_SET} * with these field entries, so an on-behalf-of read resolves its delegator @@ -321,7 +326,7 @@ async function boot(opts: BootOptions = {}): Promise { }); const second = PermissionSetSchema.parse({ name: SECOND, - objects: { [OBJ]: { allowRead: true }, [REGION]: { allowRead: true } }, + objects: { [OBJ]: { allowRead: true, ...(opts.secondViewAll ? { viewAllRecords: true } : {}) }, [REGION]: { allowRead: true } }, ...(opts.secondFields ? { fields: opts.secondFields } : {}), }); const delegatorSet = PermissionSetSchema.parse({ @@ -952,14 +957,21 @@ describe('controls: what the rule leaves unchanged', () => { }); }); - it('a View All holder reads the hidden field and the formulas over it', async () => { - const { engine } = await boot({ fields: HIDE_OPEN_CASES, viewAllRecords: true }); - expect(await findA1(engine)).toMatchObject({ open_cases: 6, load: 0.5, load_pct: 50, open_cases_stored: 6 }); + it("a holder of another set's View All reads the hidden field and the formulas over it", async () => { + const { engine } = await boot({ fields: HIDE_OPEN_CASES, secondViewAll: true }); + expect(await findA1(engine, TWO_SETS)).toMatchObject({ open_cases: 6, load: 0.5, load_pct: 50, open_cases_stored: 6 }); }); - it('a View All holder is still withheld a computed field over a capability-gated or masked field (the vote lifts readable: false only)', async () => { + it("View All on the set that hides the field does not read it: the field and the computed fields over it stay withheld", async () => { const { engine } = await boot({ fields: HIDE_OPEN_CASES, viewAllRecords: true }); const one = await findA1(engine); + expect(one).toMatchObject({ capacity: 12 }); + for (const f of ['open_cases', 'load', 'load_pct', 'open_cases_stored', 'load_stored']) expect(one, f).not.toHaveProperty(f); + }); + + it("a holder of another set's View All is still withheld a computed field over a capability-gated or masked field (the vote lifts readable: false only)", async () => { + const { engine } = await boot({ fields: HIDE_OPEN_CASES, secondViewAll: true }); + const one = await findA1(engine, TWO_SETS); expect(one).toMatchObject({ open_cases: 6, load: 0.5, phone: '138****5678' }); for (const f of ['gated', 'gated_double', 'gated_stored', 'phone_copy', 'phone_stored']) expect(one, f).not.toHaveProperty(f); });