Repository navigation
Commit 751e839
feat(security): the access explanation names the channel that opened each field (#38616)
<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ812XJN3qiB4BunLgsS3T39D)_
Fixes #36051
Clause-②: yes
Metadata-protocol: added
Skills-docs: none — `fieldChannels` is a read-only key of the access
explanation's answer; no metadata author writes it, and
`content/docs/permissions/field-level-security.mdx` teaches reading it
## 维护者速读
- 管理员查看某个用户的权限说明时,现在能看到每个字段是被哪个权限集、通过哪种方式打开的;普通用户无感。
- 属于「查看/修改全部只管记录、不管字段」那次权限改造,回答作者「我明明隐藏了这个字段,是哪个权限集又把它打开了」。
- 只改说明、不改实际权限;出错最多是说明写错了打开字段的那个权限集,实际能看到的字段不变,可以直接撤回。
- 无
## What changes
The access explanation (`/api/v1/security/explain`,
`ISecurityService.explain`) now names, per field, the channel that cast
the winning read vote and the winning edit vote. The premise is the
corrected one on the card (comment 7257037135): since protocol 19, View
All and Modify All cast no field vote, so there are four channels and
the CLI is out of scope.
- **Spec** (`packages/spec/src/security/explain.zod.ts`): `ExplainLayer`
gains an optional `fieldChannels` list, set on the `fls` layer only.
Each entry is a field with optional `read` / `edit`, each a channel with
the voting set names:
- `own_row`: a set's own field row opens it, and no held set's row
closes it.
- `other_set_row`: a set's row opens it while another held set's row
closes it, which is the union re-opening a field one set hides.
- `view_all_fields`: no row opens it, and a set's `viewAllFields` bit
casts the read vote. Read axis only: the edit axis has its own
three-value enum.
- `default`: no held set names the field. It carries no set names.
`read` / `edit` is present only where the field merge kept that vote
open; the object grant stays the `object_crud` layer's answer. The two
channel schemas are not exported, following the pattern of
`ExplainRecordVerdictSchema`, so the API surface is unchanged.
- **Vote source** (`permission-evaluator.ts`):
`PermissionEvaluator.fieldVoteSources(object, sets)` names the readers,
hiders, editors, lockers and `viewAllFields` voters per field. It uses
the merge's own vote functions: `fieldPermissionVote`, with no judge,
and `viewAllFieldsReadVote` asked per set, so a set's own hiding row
still beats its own bit. It decides nothing.
- **Engine** (`explain-engine.ts`): the decision stays the enforcement
mask (capability gates folded in, the D10 intersection), step 4's hidden
list and the partial-mask set. A field that mask closes gets no channel
on that axis, and a field served only through its masking rule (the
detail's PARTIALLY masked list) gets no read channel. The edit axis
follows the step 2.5 write gate's two arms: the mask's edit bit (a
capability gate folds to `readable:false, editable:false`; the D10
intersection ANDs the delegator's edit bit), and the computed fields the
caller is not served whole, which the gate refuses in a payload. That
set reaches the engine through a new optional dep,
`getComputedFieldsNotServedWhole`, wired in
`security-plugin-explain-access.ts` to the gate's own composition
(`computedFieldsNotServedWhole` over `computeQueryGuardFieldPerms`), not
re-derived. A row's `readable:false` on a stored field closes the read
axis only, so a write-only row keeps its edit channel. Fields are listed
in schema order. When a field one held set hides is readable through
another set, the `fls` detail adds one sentence naming the field and the
set.
- **Docs**: `content/docs/permissions/field-level-security.mdx` gains a
"Which set opened a field" section. The generated references,
authorable-surface list and strictness-ledger counts are regenerated.
Read-only: no enforcement path changes.
## Why
When a field is readable that an author meant to hide, the first
question is which permission set opened it. Until now the answer meant
reading the merge code. This is step 2 of the ruled field-axis split
(#34365, ruling 6912661484 「同意,立决策卡」).
## Tests
`packages/plugins/plugin-security/src/explain-engine.test.ts`, new
describe "fls names the channel that opened each field". It runs the
plugin's own mask wiring (`getFieldPermissions`) and parses each
decision through `ExplainDecisionSchema`:
- one set hides `f`, another names it on its own row: `other_set_row`
naming that set, on read and edit, and the detail names it;
- a single set's own row: `own_row`;
- `viewAllFields` on another set: `view_all_fields` naming that set,
read only;
- View All and Modify All beside the hiding set: no channel, and no
detail sentence;
- a field no set names: `default` on both axes, with no set;
- a capability gate the principal lacks closes the field: the opening
row is not reported;
- a field served only through a gate-less masking rule: no read channel
while the detail says PARTIALLY masked, edit still `own_row`;
- a write-only row (`readable: false, editable: true`): edit `own_row`,
no read channel;
- a computed field the write gate refuses (the dep's set): no edit
channel while its row opens it.
`packages/plugins/plugin-security/src/formula-reads-hidden-field-masking.test.ts`
(real `ObjectQL` + SQL driver + `SecurityPlugin`), in "one write
verdict": the explanation names no edit channel for a computed field
withheld for its input (`open_cases_stored`) or served only through its
own masking rule (`plain_masked`), the same two the preview, the write
and the projections refuse; control: `name` and, for a caller served the
input whole, `open_cases_stored` keep theirs.
`packages/spec/src/security/explain.test.ts`: the read axis has exactly
four channels and the edit axis three (pinned by introspection);
`view_all_fields` is refused on edit, `view_all_records` on both axes,
and a layer without the key still parses.
Ablation (first round): forcing the row channel to `own_row` turned the
`other_set_row` case red (1 failed, 5 passed). The mutation landed on
disk through `scripts/ablation-replace.mjs`, and `git diff HEAD` was
empty afterwards. Second round: restoring the edit axis's
`!hidden.has(field)` turned the write-only case red (1 failed, 7
passed). Third round: dropping the `computedNotWhole` exclusion turned
the plugin-level case red with both fields leaking `{ channel: 'default'
}`.
## Acceptance notes
- `Metadata-protocol: added` (not the claim's `none`): the new key
enters the `packages/spec/authorable-surface/security.json` shard, and
`Check Changeset` reads any shard move as a protocol kind
(`none-baseline-moved`). `@objectstack/spec` is graded `minor`;
`@objectstack/plugin-security` stays `patch`.
- Review round 1 (seat L1 REWORK + contract-review L2 FAIL on
`24a778da`) closed: partial fields lose the read channel, the read/edit
wording says what presence means, the edit axis has its own enum, the
spec pins both enums, and the evaluator names sets as the engine does.
The seat keeps the full per-field list (not sparse).
- Review round 2 closed: the edit axis no longer drops a hidden field.
The capability gate and the D10 intersection already close
`mask.editable`; a row's `readable:false` and a computed field withheld
for what it reads gate the response, not the write
(`FieldMasker.detectForbiddenWrites` reads the edit bit alone), so no
source needs its own exclusion.
- Review round 3 closed: the round-2 audit missed the write gate's
second arm (`computeForbiddenFieldWrites` refuses a payload naming a
computed field not served whole). The edit axis now closes for the
gate's own set, handed over through the new dep; this also closes the
masking-rule computed field that already diverged at `ed83df68`.
Deviation from the order's surface: `security-plugin-explain-access.ts`
and `security-plugin.ts` (the explain host) carry the wiring, per the
seat's ruling to hand over the gate's set rather than re-derive it.
- Under ADR-0090 D10 the channel names the principal's own sets. The
delegator's mask only removes a channel, through the intersection.
## Verification
Final head `6c9b214e`. CI: all 72 check-runs on it are success or
skipped by their selector; none failed.
Local subset on `6c9b214e` (round 3):
- `explain-engine.test.ts` 150/150; the 27 test files that exercise the
explanation: 1647 passed / 7 skipped;
`formula-reads-hidden-field-masking.test.ts` 70/70.
- `pnpm --filter @objectstack/plugin-security typecheck` (source,
scripts and the test layer): exit 0. Spec `src/security` 421/421;
`check:generated --fix`: all 14 up to date.
Local subset on `1bebf96b` (round 2):
- `pnpm --filter @objectstack/spec build`, then `vitest run
src/security`: 15/15 files, 421/421 tests. `@objectstack/spec` and
`@objectstack/plugin-security` typecheck: exit 0.
`explain-engine.test.ts`: 149/149.
- `pnpm --filter @objectstack/spec check:generated --fix`: all 14
generated artifacts up to date (the round-2 text change is a docblock;
no `.describe()` moved).
Local subset on `ed83df68` (round 1):
- `pnpm --filter @objectstack/spec build`, then `vitest run
src/security`: 15/15 files, 421/421 tests. `@objectstack/spec` and
`@objectstack/plugin-security` typecheck: exit 0.
`explain-engine.test.ts`: 148/148.
- `pnpm --filter @objectstack/spec check:generated --fix` regenerated
the stale `check:docs` and `check:strictness-ledger` and re-checked them
green. `check:liveness`: exit 0.
- `node scripts/pm/dispatch-gates.mjs --commands` derived 119 families
(the same set as round 0). `--ran` with exit codes: 118 exit 0, 1 NOT
MEASURED, 0 unrun.
- First round, on `67523d47`: `pnpm --filter
@objectstack/plugin-security test` 290/290 files, 7358 passed / 45
skipped.
<details><summary>The 1 NOT MEASURED (exit 3, prerequisite not met in
this container; CI runs it)</summary>
- `node scripts/check-plugin-teardown-shape.mjs --self-test`: its pinned
positive control needs an unshallowed clone.
</details>
Not run locally: `test:repo`, full dogfood (no `!` in the title and no
narrowing arm), and `pnpm lint`. All of these belong to CI.
Two-minute check: `pnpm --filter @objectstack/plugin-security exec
vitest run --maxWorkers=2 src/explain-engine.test.ts -t "names the
channel"` shows 9 passed.
Read first, by risk: `explain-engine.ts` `fieldChannelsOf` (whether a
channel can claim a field the mask or the write gate closes),
`security-plugin-explain-access.ts` `getComputedFieldsNotServedWhole`
(parity with `computeForbiddenFieldWrites`), `permission-evaluator.ts`
`fieldVoteSources` (parity with `getFieldPermissions`), `explain.zod.ts`
(the new optional key).
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (CI).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01JQwxba7R1thfXzYipYgzGJ
<!-- signed: repo:objectstack#2 · os-warren ·
session_01JQwxba7R1thfXzYipYgzGJ -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 43eaf5e commit 751e839
14 files changed
Lines changed: 493 additions & 12 deletions
File tree
- .changeset
- content/docs
- permissions
- references/security
- docs/audits/2026-07-unknown-key-strictness-ledger.counts
- packages
- plugins/plugin-security/src
- spec
- authorable-surface
- docs/references/api
- src/security
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
192 | 226 | | |
193 | 227 | | |
194 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
| 168 | + | |
167 | 169 | | |
168 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
169 | 179 | | |
170 | 180 | | |
171 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2280 | 2280 | | |
2281 | 2281 | | |
2282 | 2282 | | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
0 commit comments