Skip to content
25 changes: 25 additions & 0 deletions .changeset/33828-own-field-mask-binds-over-own-view-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@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-②: yes (narrowing)
Metadata-protocol: semantic

<!-- adr-0087: registered permission-own-field-mask-binds-over-own-view-all -->

**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.

**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/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.
21 changes: 14 additions & 7 deletions content/docs/permissions/authorization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,21 @@ 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 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 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.
</Callout>

## Package provenance & composition (ADR-0086)
Expand Down
2 changes: 1 addition & 1 deletion content/docs/permissions/permissions-matrix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/adr/0066-unified-authorization-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 44 additions & 10 deletions packages/core/src/security/effective-object-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> | null } | null | undefined>,
sets: ReadonlyArray<
{ objects?: Record<string, unknown> | null; fields?: Record<string, unknown> | 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
* `<objectName>.<fieldName>` 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<string, unknown> | 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<string, unknown> | null;
Expand All @@ -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.
*/
Expand All @@ -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<string, ReturnType<typeof superuserFieldVote>>();
// [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;
Expand Down
Loading
Loading