Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/36053-skills-three-permission-axes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@objectstack/skills': patch
'@objectstack/spec': patch
---

docs(skills): the data skill teaches the three permission axes, `viewAllFields` and the sensitivity tiers

Clause-②: no
Metadata-protocol: none

objectstack-data's `rules/security.md` now teaches the permission model in three axes. Object permission (`allowRead`, `allowCreate`, `allowEdit`, `allowDelete`) decides whether the caller can use the object at all. Record scope (`viewAllRecords`, `modifyAllRecords`) widens which records the caller reaches, and from v19 those two bits open no field. Fields are visible by default, so an author writes only the exceptions: nothing for an ordinary field, `fields` rows in the sets that differ for a position-dependent one, and `requiredPermissions` on the field itself for a high-sensitivity one (salary, ID numbers), with `maskingRule` where a partial value is needed. That gate is strictest-wins over every field row, `viewAllFields`, View All and Modify All.

A new section teaches `viewAllFields: true` as the way to say "this set reads every field", for admin-like sets: a read vote on every field, fields added later included, and never an edit vote; the set's own `readable: false` row beats it; it grants no object access and widens no record; on the `'*'` entry it also votes on the fields of private-posture objects, which a plain `'*'` does not grant; it is authored in metadata, as Studio's permission matrix keeps the key and has no control for it.

`evals/hooks-security-seeds-datasources.json` gains two cases: a read-everything auditor set written with `viewAllFields`, and salary and ID-number fields gated with `requiredPermissions` and `maskingRule`. Two restatements in `rules/security.md` were removed to pay for part of the new text (the "Locks, never grants" bullet and the recipe link of the `when` section).

`@objectstack/spec`: two docblock sentences in `src/security/permission.zod.ts`, comments only. The `viewAllFields` docblock now says the key changes nothing on an object entry that carries View All or Modify All (it said "on a set"), and the `FieldPermissionSchema` docblock names `viewAllFields` beside the super-user bits as a voter in the field merge. No schema, description or generated artifact changes.
6 changes: 5 additions & 1 deletion content/docs/permissions/authorization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ 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.
unchanged. A set that carries `viewAllFields` on the object casts the same
read vote as View All, under the same own-entry exception, and never an edit
vote. From v19 View All and Modify All stop voting on fields: where a set
should read every field, grant
[`viewAllFields`](/docs/permissions/field-level-security#viewallfields-a-set-that-reads-every-field).
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
Expand Down
106 changes: 98 additions & 8 deletions content/docs/permissions/field-level-security.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,92 @@ description: "Control visibility and editability of specific fields — readable

Control visibility and editability of specific fields.

## The three axes

A permission set answers three separate questions, and each key answers one
of them:

| Axis | Keys | What it decides |
|:---|:---|:---|
| **Object permission** | `allowRead`, `allowCreate`, `allowEdit`, `allowDelete` | Whether the caller can use the object at all. |
| **Record scope** | `viewAllRecords`, `modifyAllRecords` | Which records the caller reaches. |
| **Fields** | `fields` rows, `viewAllFields`, and a field's own `requiredPermissions` | Which fields of those records the caller reads and edits. |

<Callout type="warn">
**From v19, View All and Modify All stop opening fields.** Until then a set
that holds `viewAllRecords` on an object also reads every field of it, and a
set that holds `modifyAllRecords` reads and edits every field (the exact votes
are under [Server-side enforcement](#server-side-enforcement-of-declared-rules)).
Do not build on that: where a set should read every field, grant
[`viewAllFields`](#viewallfields-a-set-that-reads-every-field).
</Callout>

## Choosing by sensitivity

Fields are visible by default: a field that no permission set names follows
the object grant. Write a rule only for an exception, and pick the mechanism
by how sensitive the field is:

| The field is | Write | Why |
|:---|:---|:---|
| **Ordinary** | Nothing. | It follows the object grant. |
| **Position-dependent**: one position reads or edits it, another does not | `fields` rows in the permission sets that differ. | Rows union across a user's sets, and the most permissive answer wins. |
| **High-sensitivity**: salary, ID numbers | `requiredPermissions` on the field itself, plus `maskingRule` where a partial value is needed. | The capability gate is applied after the sets are merged, so no field row, `viewAllFields`, View All or Modify All re-opens the field. |

```typescript
// On the object: the gate travels with the field.
fields: {
salary: { type: 'currency', requiredPermissions: ['hr.view_compensation'] },
id_number: { type: 'text', requiredPermissions: ['hr.view_identity'], maskingRule: 'id_card' },
}

// On the permission set whose holders read both in full.
definePermissionSet({
name: 'hr_specialist',
systemPermissions: ['hr.view_compensation', 'hr.view_identity'],
objects: { employee: { allowRead: true, allowEdit: true } },
});
```

A caller who does not hold the capability gets `salary` stripped from every
record and reads `id_number` as its masked value. A write to either field is
refused.

## `viewAllFields`: a set that reads every field

`viewAllFields: true` on a set's object entry casts a read vote on every field
of that object, fields added later included. Use it for admin-like sets that
must read everything:

```typescript
definePermissionSet({
name: 'sales_manager',
objects: { crm_account: { allowRead: true, allowEdit: true, viewAllFields: true } },
// The set's own row beats its own bit: its holders do not read this field.
fields: { 'crm_account.partner_margin': { readable: false } },
});
```

- **Read only.** It never casts an edit vote. An edit comes from the default
(a field no set names follows the object grant) or from an explicit
`editable: true` row.
- **A set's own row beats it.** A `readable: false` row in the same set keeps
that field hidden for that set. Another set's `viewAllFields` still reads
the field, because grants union across sets.
- **A field vote only.** It grants no object access, so pair it with
`allowRead`. It widens no record: that is `viewAllRecords`.
- **On the `'*'` entry** it votes on every object the set does not name
itself, private objects (`access.default: 'private'`) included. A `'*'`
entry without View All or Modify All gives no access to a private object,
but its `viewAllFields` still votes on that object's fields. So it re-opens
a field that is hidden by the set which does grant the object.
- **A capability gate still applies.** It does not lift a field's
`requiredPermissions` or a masking rule.
- **High-privilege.** A set that carries it cannot be bound to the `everyone`
or `guest` audience.
- **Authored in metadata.** Studio's permission matrix has no control for the
bit. It keeps the key when it saves a set that already carries it.

## Field Permissions in Permission Sets

Field permissions are keyed `<object>.<field>` and use `readable` / `editable`,
Expand Down Expand Up @@ -156,9 +242,9 @@ roll-up is not a computed field in this sense: it does not follow the
fields it aggregates, so mask it on its own where a set must not see it.
The record the engine echoes for a
public-form submission carries no computed field that reads through a
reference. View All and Modify All lift a permission set's `readable:
false`, not a capability gate or a masking rule, so their holders are
withheld a computed field over such a field too. To let a permission
reference. View All, Modify All and `viewAllFields` lift a permission set's
`readable: false`, not a capability gate or a masking rule, so their holders
are withheld a computed field over such a field too. To let a permission
set's holders read a computed field, grant that set read on every field
the expression reads, unmasked: the capability a field's
`requiredPermissions` names also lifts a masking rule it gates, and a
Expand Down Expand Up @@ -198,16 +284,20 @@ only constrain fields they explicitly enumerate, and field grants union
most-permissively across a user's sets (one set's `readable: true`
out-votes another set's `false`). Until a subtractive muting layer lands
(ADR-0066 ⑧), a `{ readable: false }` rule masks the field only as long
as **no other set the user holds** declares it `readable: true` or holds
as **no other set the user holds** declares it `readable: true`, carries
`viewAllFields` on that object, or holds
View All (`viewAllRecords`, reads every field of the object) or Modify All
(`modifyAllRecords`, reads and edits every field) on that object, and
the set that declares it does not itself hold Modify All on that object:
the set's own View All leaves its `readable: false` binding, while its
the set's own View All or `viewAllFields` leaves its `readable: false`
binding, while its
own Modify All still reads and edits every field of the object, its own
rows included (`security-superuser-field-mask-inert` warns on such a row),
until the field-axis split (#34365) — so
protect sensitive fields by granting them only in the sets that need
them, and treat a sensitive field on a broadly-granted object as a
until v19, when View All and Modify All stop voting on fields — so
gate a high-sensitivity field with `requiredPermissions`
([Choosing by sensitivity](#choosing-by-sensitivity)), grant a
position-dependent field only in the sets that need
it, and treat a sensitive field on a broadly-granted object as a
review smell — see the
[FLS posture warning](/docs/permissions/authorization#combination-semantics-the-fixed-order).
Declared rules themselves are enforced fail-closed: a masked field is
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 @@ -159,7 +159,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 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.
**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. From v19 these two bits stop reaching fields: a set that should read every field carries `viewAllFields`, and a high-sensitivity field is gated by `requiredPermissions` on the field itself ([Field-level security](/docs/permissions/field-level-security#choosing-by-sensitivity)).

### FLS States

Expand Down
31 changes: 30 additions & 1 deletion packages/core/src/security/superuser-field-vote-33828.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
*/

import { describe, it, expect } from 'vitest';
import { buildEffectiveFieldPermissions, superuserFieldVote } from './effective-object-permissions.js';
import {
buildEffectiveFieldPermissions,
buildEffectiveObjectPermissions,
superuserFieldVote,
} from './effective-object-permissions.js';

describe('a set\'s own readable: false row and that set\'s own super-user vote', () => {
const viewAll = (
Expand Down Expand Up @@ -129,3 +133,28 @@ describe('[field-axis split, ruling 6912661484] viewAllFields: a read vote throu
}
});
});

describe('[field-axis split, ruling 6912661484] a wildcard viewAllFields is posture-blind: it votes on a private object\'s fields and grants no object', () => {
// `vault` is private-posture, `deal` is public. The wildcard set carries a
// plain read grant and the bit: no super-user bit, so its `'*'` does not
// cover a private object.
const schemas = [{ name: 'vault', access: { default: 'private' } }, { name: 'deal' }];
const wildcard = { objects: { '*': { allowRead: true, viewAllFields: true } } };
// Another set grants `vault` by name and hides one field of it.
const hider = { objects: { vault: { allowRead: true } }, fields: { 'vault.pin': { readable: false, editable: false } } };

it('the object axis: the wildcard grants the public object and nothing on the private one', () => {
const objects = buildEffectiveObjectPermissions([wildcard], { allSchemas: () => schemas });
expect(objects.deal?.allowRead).toBe(true);
expect(objects.vault).toBeUndefined();
});

it('the field axis: the same wildcard still casts its read vote on the private object\'s field', () => {
expect(superuserFieldVote([wildcard], 'vault', 'pin')).toEqual({ readable: true, editable: false });
// Control: without the bit the field stays hidden, so the vote below is the bit's.
expect(buildEffectiveFieldPermissions([{ objects: { '*': { allowRead: true } } }, hider])).toEqual({
'vault.pin': { readable: false, editable: false },
});
expect(buildEffectiveFieldPermissions([wildcard, hider])).toEqual({ 'vault.pin': { readable: true, editable: false } });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,21 @@ describe('[ruling 6912661484, step 2] no behaviour change: the built-in admin se
expect(merge([withBit(variant), APP_MASK])).not.toEqual(merge([variant, APP_MASK]));
});
});

describe('[ruling 6912661484] a wildcard viewAllFields is posture-blind: it votes on a private object\'s fields and grants no object · getFieldPermissions', () => {
it('the wildcard does not cover the object when it is private, and its read vote on the fields stands', () => {
// The object axis honours the posture: a plain `'*'` (no View All, no
// Modify All) covers a public object and not a private one.
expect(evaluator.checkObjectPermission('find', OBJ, [WILDCARD_VIEW_ALL_FIELDS], { isPrivate: false })).toBe(true);
expect(evaluator.checkObjectPermission('find', OBJ, [WILDCARD_VIEW_ALL_FIELDS], { isPrivate: true })).toBe(false);
// The field axis takes no posture: the bit votes on every field of the
// object, so it re-opens what the set that DOES grant the object hides.
// Control first: a plain wildcard leaves the fields hidden. The row-blind
// merge is pinned beside it in core's `superuser-field-vote-33828.test.ts`.
const plainWildcard = set({ name: 'wildcard_plain', objects: { '*': { allowRead: true } } });
const hidden = merge([plainWildcard, APP_MASK]);
for (const f of MASKED) expect(hidden[f], f).toEqual({ readable: false, editable: false });
const fp = merge([WILDCARD_VIEW_ALL_FIELDS, APP_MASK]);
for (const f of MASKED) expect(fp[f], f).toEqual({ readable: true, editable: false });
});
});
16 changes: 10 additions & 6 deletions packages/spec/src/security/permission.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,8 @@ const ObjectPermissionBaseSchema = lazySchema(() => strictObject(
* set does not name explicitly (the same lookup the super-user bits take).
*
* Today `viewAllRecords` / `modifyAllRecords` still vote on every field
* too, so on a set that carries either bit this key changes nothing; the
* too, so on an object entry that carries either bit (the set's own entry
* for the object, else its `'*'` entry) this key changes nothing; the
* built-in admin sets carry it so they keep their field visibility when
* those two bits stop voting on fields.
*
Expand Down Expand Up @@ -1083,11 +1084,14 @@ const FIELD_PERMISSION_ROLLUP_REASON_ON_HIDDEN =
* condition matches, the entry votes as declared; on any other row the entry
* is absent, so the most-permissive merge
* (`PermissionEvaluator.getFieldPermissions`) is unchanged. Beside the
* declaring sets, a set holding the super-user bypass on the object votes on
* 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. One exception (ADR-0066 ⑧ note of 2026-11-15): a set
* declaring sets, a set holding the super-user bypass on the object, or
* carrying `viewAllFields` on it, votes on every field of it, on every row
* (ADR-0066 ⑧ note of 2026-11-02, ruling of record 6573563853; the field-axis
* split, ruling of record 6912661484): `viewAllRecords` votes
* `readable: true`, and so does `viewAllFields` (under the same exception as
* View All, below), `modifyAllRecords` votes `readable: true` and
* `editable: true`; View All and View All Fields
* never grant 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
Expand Down
21 changes: 19 additions & 2 deletions scripts/check-skills-token-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,8 +1337,25 @@ export const CEILINGS = new Map([
// `origin/main` the file was 16164 bytes (4041 tokens, headroom 0); the
// LANDED file is 16272 bytes -> 4068 tokens, ceiling +27, pinned AT the
// measurement, zero headroom.
// ceil($(wc -c < skills/objectstack-data/rules/security.md) / 4) == ceil(16272 / 4)
['skills/objectstack-data/rules/security.md', 4068],
// 4068 -> 4292 (card #36053, the Skills-docs follow-up of the field-axis
// split, ruling of record 6912661484): the three permission axes in the
// ruled model's words (object permission, record scope, fields);
// `viewAllFields` as "reads every field" (a read vote on every field, never
// an edit vote; the set's own `readable: false` row beats it; no object
// access and no record; on `'*'` it also votes on a private-posture object's
// fields; authored in metadata); the three sensitivity tiers; "from v19"
// View All / Modify All open no field; and `maskingRule` beside a field's
// `requiredPermissions` — none of which the file taught, so an author
// granted View All to open fields. Same standing ruling, tap A, verbatim and
// untranslated: 「A:先削重复,余额按实测提高」 (record 6513306068). PAID DOWN
// FIRST, 274 bytes: the `when` section's "Locks, never grants" bullet (140;
// the choice rule above it already says the other sets keep their grant,
// and the new section states the union rule) and the recipe URL (134; the
// docs anchor the same bullet keeps links it). On `origin/main` the file was
// 16272 bytes (4068 tokens, headroom 0); the LANDED file is 17168 bytes ->
// 4292 tokens, ceiling +224, pinned AT the measurement, zero headroom.
// ceil($(wc -c < skills/objectstack-data/rules/security.md) / 4) == ceil(17168 / 4)
['skills/objectstack-data/rules/security.md', 4292],
// 3024 -> 3109 (2026-08-31 app-repo-principles raise, see the block above).
// Severity Levels listed the three values and left the CHOICE unstated: a
// block rests on a judgement a person made, so a machine-inferred signal — a
Expand Down
Loading
Loading