Repository navigation
Commit 4138ce8
fix(plugin-security): a View All / Modify All set reads every field of its object, so an app field mask no longer hides fields from admins (#29387)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9A6kAUSDc7TXDVUJeUigpMx)_
Part of #29106. This is the runtime half. The ADR-0066 D2 ⑧ note is the
card's second PR, governed Tier H, and it opens from this branch once
this one merges.
Clause-②: no
Metadata-protocol: none
Ruling-ref: 6573563853
## 维护者速读
-
改了什么:在某对象上持「查看全部」(`viewAllRecords`)的权限集,在字段合并时对该对象每个字段投「可读」;持「修改全部」(`modifyAllRecords`)的投「可读+可编辑」。判断谁是超级用户只用一个函数,行级和字段级共用。
- 为什么改:应用权限集遮掉平台对象字段时,同时持有该集的平台管理员也被遮住(列表少列、按该字段排序 403、Setup 页面显示为空)。按裁决
6573563853 选 A。
- 风险与回滚:只放宽持「查看全部 / 修改全部」者的字段可见性;全仓没有已发布的权限集同时声明这两个位和 `readable:
false`(已在卡上贴查证结果)。回滚 = revert 本 PR。
-
先看:`packages/core/src/security/effective-object-permissions.ts`(`holdsSuperuserBypass`、`superuserFieldVote`)→
`packages/plugins/plugin-security/src/permission-evaluator.ts`(`getFieldPermissions`、`superuserBypassSets`)→
`packages/qa/dogfood/test/fls-superuser-vote.dogfood.test.ts`。
- 两分钟验证:`pnpm --filter @objectstack/dogfood exec vitest run
test/fls-superuser-vote.dogfood.test.ts`,预期 11 条全绿:管理员看到全部字段并能按 `code`
排序,普通成员仍被遮、排序 403。
- 需要你做的:无,席位落地。
## What changes
- **The super-user vote.** `getFieldPermissions` (per object) and
`buildEffectiveFieldPermissions` (the row-blind `/auth/me/permissions`
merge) apply `superuserFieldVote` after the declared-entry votes. A set
holding `viewAllRecords` on the object votes `readable: true` on every
field of it. A set holding `modifyAllRecords` votes `readable: true` and
`editable: true`. View All never grants an edit. The vote touches only
fields the merge already holds an entry for, because an absent field is
already unrestricted.
- **One predicate.** `holdsSuperuserBypass(set, object, bit)` is new in
`@objectstack/core`. `PermissionEvaluator.superuserBypassSets` now reads
each set through it, and so does `superuserFieldVote`. The row bypass
and the field vote therefore name the same sets: the set's own entry for
the object if it has one, otherwise its `'*'` wildcard. The private
posture never changed that answer, since it withholds only a wildcard
that carries neither bit. The new pin `the private posture never changes
the super-user answer` holds it.
- **Every reader agrees.** The list projection, record read, sort/filter
gate, field-level write gate, `/auth/me/permissions` and `POST
/security/explain` all read one of those two merges.
- **Unchanged.** Union without deny is otherwise unchanged: a caller who
holds no super-user set on the object is still masked. A field's
`requiredPermissions` capability gate still applies after the merge.
- **Docs.** Two published pages described what the runtime no longer
does:
- `content/docs/permissions/permissions-matrix.mdx` §3: the Sales
Manager column, whose set holds View All on `contact` and Modify All on
`opportunity`, plus one sentence on why.
- `content/docs/permissions/field-level-security.mdx`: the union
paragraph now names View All / Modify All.
- Changeset `.changeset/29106-superuser-field-vote.md`: `patch` for
`@objectstack/plugin-security` and `@objectstack/core`.
## Tests
- `packages/plugins/plugin-security/src/fls-superuser-vote.test.ts`
(new, 25 cases). It covers the card's repro against the shipped
`admin_full_access`, order independence, the member control, the
plain-read control, view-only-never-edits, modify reads and edits, a
wildcard shadowed by an explicit entry, a vote held on another object,
and undeclared fields staying absent. It also pins one predicate (field
votes equal the `superuserBypassSets` answers, and the private posture
never changes them) and parity between the row-blind and per-object
merges.
- `packages/core/src/security/effective-object-permissions.test.ts`: two
cases, one for the row-blind vote and one for `holdsSuperuserBypass`.
- `packages/qa/dogfood/test/fls-superuser-vote.dogfood.test.ts` (new, 11
cases, real showcase boot). The card's repro on `sys_business_unit`: an
admin holding `admin_full_access` plus an app set with `readable: false`
on `code`, `kind`, `manager_user_id` and `active`. Each door is checked
as an admin case and a member control case: `/auth/me/permissions`,
list, record read, sort and filter, and explain.
- **Forced test edit 1 of 2:**
`packages/plugins/plugin-security/src/explain-principal-person.test.ts`.
Its `qa_pp_directory_masked` fixture held `viewAllRecords` on `sys_user`
and `readable: false` on `sys_user.email`. Under the ruling that set
reads its own masked field, so 4 cases went red. The fixture keeps its
intent (every user row, email withheld) by reaching the rows through a
`select` row policy instead of View All. All 16 cases are green, and the
"armed" cases measure the read door itself.
- **Forced test edit 2 of 2 (FAIL round 1):**
`packages/services/service-automation/src/resume-decider-identity.integration.test.ts`.
Its `deal_manager` fixture held `viewAllRecords` + `modifyAllRecords` on
`deal` beside `'deal.restricted_note': { editable: false }`. Under the
ruling the lock is out-voted by the set's own Modify All, so the
decider's write landed and `a post-decision node the decider may not
perform is refused loudly` went red in CI (Test Core 8/8). The manager
now reaches every deal through `readScope: 'org'` / `writeScope: 'org'`
instead of the super-user bits. Every assertion is unchanged. The GUARD
case still shows the manager's write rests on the manager's own grants.
21/21 green.
## Acceptance notes
- The precondition grep is posted on the card (issuecomment-6576959092).
It found 0 declared sets that hold View All / Modify All beside a
`readable: false` / `editable: false` entry on the same object, across
the default sets, the showcase, the hotcrm fixture, skills and docs code
blocks. The one docs near-hit (the permissions matrix) is fixed here at
seat 2's request.
- FAIL round 1, repo-wide fixture sweep (packages, examples, showcase
and app metadata, tests included) for a set declaring `viewAllRecords` /
`modifyAllRecords` beside `readable: false` / `editable: false` on the
same object. Shipped and app metadata: 0 hits. Tests: the two forced
edits above, plus
`packages/qa/dogfood/test/admin-ledger-decision-metadata.dogfood.test.ts`.
That file's `ald_withhold_set` / `ald_withhold_only_set` pair View All
on `sys_user` with `email` withheld, so the `withheld` class no longer
applies to those readers. Its assertions are about which ledger rows are
served (none about the subject, through every door), not about the
field, and it stays green. Noted here, not edited.
- Every package with a field-permission test fixture beside a security
boot was run on the new head: objectql (4 files), rest (4), runtime (1),
cli (1), and service-automation in full (260 files / 3338 tests). All
green.
- The `/auth/me/permissions` merge lives in `@objectstack/core`
(`buildEffectiveFieldPermissions`), not in `current-user-endpoints.ts`,
so the diff touches `packages/core` and leaves `plugin-hono-server`
unchanged. Seat 2 accepted this file-surface change.
## Verification
Head `252a02f4` (FAIL round 1: one test-fixture commit on top of
`718ba1b2`; origin/main `47718699` merged in). The gates and the full
dogfood battery below ran on `718ba1b2`; the round-1 commit changes one
service-automation test file only.
<details><summary>Red first on main (5780fa4 + tests only)</summary>
- plugin-security `fls-superuser-vote.test.ts`: 7 failed / 18 passed.
Every admin vote case failed (`expected { readable: false, editable:
false } to deeply equal { readable: true, editable: true }`). Controls
and parity were green.
- dogfood `fls-superuser-vote.dogfood.test.ts` (first layout): 6 failed
/ 2 passed. The admin sort was refused with the card's own message: `403
… references field(s) not readable by the caller: code`. Explain
reported `4 field(s) masked from responses: [code, kind,
manager_user_id, active]` for the admin. The member's
`/auth/me/permissions` control was green.
</details>
<details><summary>Green after the fix</summary>
- plugin-security `fls-superuser-vote.test.ts` 25/25 · core
`effective-object-permissions.test.ts` 43/43 · dogfood
`fls-superuser-vote.dogfood.test.ts` 11/11.
- Package suites before the main merge: core 129 files passed;
plugin-security 240 files / 5241 tests, with the 4 red cases named above
fixed by the forced edit and that file rerun 16/16; plugin-hono-server
38 files / 472 tests passed. Typecheck (`tsc` + `check:test-typecheck`)
passed for core, plugin-security and plugin-hono-server after a DTS
build.
- `eslint --no-inline-config` over `packages/core/src`,
`packages/plugins/plugin-security/src` and the new dogfood file: exit 0.
</details>
<details><summary>Ablation of the new vote</summary>
`superuserFieldVote` was made to return `null` first, through
`scripts/ablation-replace.mjs`. Marker
`ABLATION_29106_NO_SUPERUSER_VOTE`; `ablation-dist-preflight` showed it
in `packages/core/dist/index.js` and `index.cjs`.
- plugin-security unit: 6 failed / 19 passed. Admin vote, view-only,
modify and three predicate rows went red; controls stayed green.
- dogfood: 5 failed / 6 passed. Red: admin `/auth/me/permissions`, list,
record read, sort+filter, explain. Green: premise and all 5 member
controls.
- core: 1 failed / 42 passed (the row-blind vote case).
- Restore: blob back to HEAD `09e5a75c`, core rebuilt,
`ablation-dist-preflight --absent` exit 0, `git status --porcelain`
clean.
</details>
<details><summary>Gates and full dogfood (718ba1b)</summary>
- `node scripts/pm/dispatch-gates.mjs --commands` on `718ba1b2`: 94
derived families, all run. 93 exit 0 on the first pass.
`check-plugin-teardown-shape.mjs --self-test` exited 3 because its
positive control commit was missing in the shallow clone; after `git
fetch origin 621a487…` it exits 0 (48 cases). `--ran` reconciliation:
94 derived, 94 run, 0 NOT-MEASURED, 0 UNRUN.
- Full dogfood battery on `718ba1b2` after a full `turbo run build
--filter=./packages/** --filter=./examples/**` (10m41s under the lock):
`pnpm --filter @objectstack/dogfood test` → VERDICT command-exit 0 ·
Test Files 394 passed / 3 skipped (397) · Tests 3254 passed / 28 skipped
(3282) · no failures.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmSgjH5Vi4jT3KVJpvt
<!-- signed: domain:server#2 · os-steve ·
session_01ADHkmSgjH5Vi4jT3KVJpvt -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f95d0db commit 4138ce8
11 files changed
Lines changed: 598 additions & 17 deletions
File tree
- .changeset
- content/docs/permissions
- packages
- core/src/security
- plugins/plugin-security/src
- qa/dogfood/test
- services/service-automation/src
| 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 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
144 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
573 | 574 | | |
574 | 575 | | |
575 | 576 | | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
576 | 610 | | |
577 | 611 | | |
578 | 612 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
741 | 741 | | |
742 | 742 | | |
743 | 743 | | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
744 | 805 | | |
745 | 806 | | |
746 | 807 | | |
| 808 | + | |
| 809 | + | |
747 | 810 | | |
748 | 811 | | |
749 | 812 | | |
| |||
756 | 819 | | |
757 | 820 | | |
758 | 821 | | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
759 | 825 | | |
760 | 826 | | |
761 | 827 | | |
| |||
774 | 840 | | |
775 | 841 | | |
776 | 842 | | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
777 | 856 | | |
778 | 857 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
323 | 327 | | |
324 | 328 | | |
325 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
54 | 60 | | |
55 | 61 | | |
56 | | - | |
| 62 | + | |
57 | 63 | | |
| 64 | + | |
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
| |||
0 commit comments