Repository navigation
Commit f84dc19
fix(plugin-security)!: a computed field over a field the caller cannot read is hidden from that caller (#34135)
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — `skills/objectstack-data` (`rules/relationships.md`)
teaches a rate as a `formula` over a `summary` and tells an author to
mask the summary on a set that must not see it; that instruction is
complete as written now, because a formula over the masked summary is
withheld with it, so no page needs a new sentence.
## 维护者速读
- 改了什么:字段级安全现在覆盖计算字段的输入——调用者未被完整提供某字段时(权限集 `readable: false`、未满足
`requiredPermissions`、或按 `maskingRule` 打码),读取该字段的 formula /
存储计算字段对其隐藏:本记录直接引用、经 `label()`
之类函数、经另一计算字段;或经引用读取被引用对象声明的字段(调用者读不了该对象、读不了该字段、或只拿到打码值;被引用对象上经其自身引用而被扣下的存储字段亦然,沿链每个对象判一次)。写入载荷点名此类字段一律
403。
- 为什么改:字段级安全应当覆盖一个值由什么算出;此前计算字段不随其输入一起隐藏。
- 风险与回滚:收窄(BREAKING)。受影响者是输入字段被扣下却在读其上计算字段的调用者,包括对能力门控或打码字段的 View All /
Modify All 持有者,以及无解码门的 `maskingRule`
下所有非系统调用者。读不出字段名的表达式在有任一其他字段未被完整提供时整体隐藏。公共表单的引擎回显不带任何经引用读取的计算字段。判的是字段,不是行(见变更集)。回滚即
revert 本 PR,无数据迁移。
-
先看:`packages/plugins/plugin-security/src/field-masker.ts`(读集、引用跳读与传递折叠)、`security-plugin-object-inputs.ts`(引用判定:被引用对象可读与完整提供的字段集)、`security-plugin-authz-middleware.ts`(第
2.5 步写入拒绝、查询守卫、第 4 步与公共表单回显)。
- 两分钟验证:`pnpm --filter @objectstack/plugin-security exec vitest run
src/formula-reads-hidden-field-masking.test.ts`,预期 67 个用例全绿。
- 需要你做的:无,席位落地。
## What changes
Field-level security now covers what a field's value is computed from. A
computed field — a `formula`, computed on read, or a stored field
declaring an `expression`, computed on write — is withheld from a caller
who is not served whole a field it reads. Each input kind is pinned for
a formula and for a stored field, with a control and an ablation:
- a field of its own record the caller may not read (a permission set
marks it `readable: false`, or the caller fails its
`requiredPermissions`) or is served masked (its `maskingRule`, gated or
not), whether the expression names it directly, inside a function such
as `label()`, or through another computed field;
- a field the referenced object declares, on the record the expression
reads through one reference, where the caller may not read that object,
may not read the field, or is served it masked, directly or through a
computed field of the referenced object — including a stored field there
that is withheld for what it reads through a reference of its own. A
computed field reading through a chain of references is withheld when
any field along the chain is withheld from the caller, however long the
chain and wherever it comes back to an object it has already passed
through: the withheld sets of every object the references reach grow
together until none grows, each object resolved once per operation. A
field the referenced object does not declare is no field to withhold:
the formula reads `null`, as before;
- an expression whose reads cannot be named (a computed key, a method or
macro on the record, the record handed whole to a function, a dialect
other than CEL) is withheld whenever some other field of the object is
not served whole to that caller (fail closed); such a field is also
withheld for what it reads through a reference, as any computed field
is.
What is judged is the field, not the row: a computed field is not
withheld because the caller may not read the particular record a
reference points at (a formula reads `null` there; a stored one keeps
the value its writer computed).
The readers, each pinned at its own door with a control: `find` /
`findOne` and a projection; the `insert` and `update` echoes; a write
payload naming such a field (`403 PERMISSION_DENIED`, whatever value it
carries); filtering, sorting, grouping and aggregating by a stored
computed field (`403`; a `formula` is refused there for every caller
already); `getReadableFields`, `getMetadataReadableFields` (and the
object schema the metadata plane and `describe_object` serve),
`getQueryableFields`, `getWritableFields` and `getRecordFieldAccess`
(both halves); the explain `fls` layer; the `$expand` name of a
`referenceNameVisible` reference (the floor name where the target's name
field is withheld); a delegated read driven through the engine; and the
record the engine echoes for a public-form grant, which carries no
computed field that reads through a reference, for every submitter (the
form submit route itself answers the created id only).
One derivation feeds every reader: each object's computed-field reads
are taken once, from one parse, into the cached security posture;
`foldComputedFieldReads` folds them, transitively, into the field map
after the per-field capability fold and the delegator intersection; a
computed field reading through a reference is judged by the caller's
object admission and query projection of the referenced object (the
fields served whole there), that projection folding the referenced
object's own references in turn. The read projection stays the exact
complement of what the read mask deletes, and the query projection still
differs from it by exactly the fields served masked, as
`packages/spec/src/contracts/security-service.ts` states; no spec text
moves.
No change to `packages/spec`, to `packages/lint`, or to the
metadata-plane schema scrub code.
Files: `field-masker.ts`, `security-plugin.ts`,
`security-plugin-object-inputs.ts`, `security-plugin-field-readers.ts`,
`security-plugin-authz-middleware.ts`, `explain-engine.ts`,
`security-plugin-explain-access.ts`, the rule's test file, the two
`describe_object` pins and the second-object ledger row named under
Acceptance notes, the docs page
`content/docs/permissions/field-level-security.mdx`, one changeset.
## Tests
`packages/plugins/plugin-security/src/formula-reads-hidden-field-masking.test.ts`:
a real `ObjectQL` over a real SQL driver behind the real
`SecurityPlugin`, 67 tests named by the rule. The input-kind × reader
matrix:
- same record, `readable: false`: formula and stored; `find`, `findOne`,
projection, both echoes, the four query positions, both read
projections, query, write and record-access projections, explain,
delegated read; payload refusal for a matching and a differing value,
with control;
- same record, a failed `requiredPermissions`, and served masked (gated
rule, and a rule with no unmask gate): formula and stored, each with a
control (the capability, the unmask capability, a system context); a
View All holder is still withheld them;
- `label()` and a computed field over a computed field: formula and
stored, with control;
- through a reference: `readable: false`, a failed
`requiredPermissions`, served masked, an object the caller may not read,
a formula of the referenced object, and a stored field there that reads
through a reference of its own (a chain of two); formula and stored for
each, with control; an undeclared field reads `null` for every caller;
- fail closed, for a formula and a stored field, with control;
- the reference name door, the public-form echo and the delegated read,
each with its control;
- controls: union of two sets, system context, View All over `readable:
false`, the aggregate input gate unchanged;
- the read set: every literal spelling, held equal to the platform
member reader (`analyzeRelationshipTraversals`), and the shapes it
cannot name.
## Acceptance notes
- Two existing pins moved with the rule. Each now states a rule-named
expectation, and no assertion was loosened.
`packages/runtime/src/domains/mcp-object-schema-mask.test.ts` used to
hold that `describe_object` still served the member a stored expression
over a field the member cannot read, with the expression stripped. Under
this rule that field is withheld, so the pin now asserts it is not
served, with a control: a caller who reads the input is served it. The
stdio twin,
`packages/mcp/src/stdio-data-bridge.object-schema-mask.test.ts`, keeps
its parity literal with it; its stubbed security answer is set to what
the real service now answers.
- `packages/core/src/security/second-object-read-exposure.pin.test.ts`
classifies the new caller of the reference-target arbiter
(`computedHopTargetsOf`, `field-masker.ts`) as not a served read.
- No author-time warning names a computed field over a field a set
masks; the runtime withholds it either way.
## Verification
Readings at head `9d8e0766babadc87e234df4c5073e63853ac5fc0`, under the
verify lock.
<details><summary>Rule suite, package suites, typecheck and
ablations</summary>
- `pnpm --filter @objectstack/plugin-security exec vitest run
src/formula-reads-hidden-field-masking.test.ts`: Tests 67 passed (67).
- `pnpm --filter @objectstack/plugin-security exec vitest run`: Test
Files 273 passed (273); Tests 6794 passed | 45 skipped (6839).
- Pins: `packages/runtime` `src/domains/mcp-object-schema-mask.test.ts`
75 passed (75); `packages/mcp`
`src/stdio-data-bridge.object-schema-mask.test.ts` 37 passed (37);
`packages/core` `src/security/second-object-read-exposure.pin.test.ts` 4
passed (4).
- Typecheck: `@objectstack/plugin-security` (with the scripts project
and `check:test-typecheck`), `@objectstack/core`,
`@objectstack/runtime`, `@objectstack/mcp`: each exit 0.
- Ablations, one-shot through `scripts/ablation-replace.mjs` (anchor 1
to 0, blob changed; each restored: blob equal to HEAD, `git diff HEAD`
empty), each a red run of the 67:
- the withheld sets grow once instead of to a fixed point: 3 failed (a
chain of two, a chain back to the record read, a chain back to an object
along it);
- the write preview asks the earlier field verdict alone: 1 failed;
- the read projection keeps a withheld computed field: 5 failed (the
reference name door among them);
- an expression whose reads cannot be named drops the references it
names: 2 failed;
- the write refusal's sentence asks a map without the reference arm: 1
failed.
</details>
<details><summary>Derived gates and the dogfood battery</summary>
- `dispatch-gates --commands` ∪ `--ran`: 106 derived, 106 run, 0
NOT-MEASURED, 0 UNRUN. `check:docs` and `check:skill-examples` each
re-run alone exit 0 after a sweep run that overlapped a `spec` rebuild;
`check:type-check-debt` is measured by CI's `Type Check · debt ledger`
(success on this head).
- `node scripts/check-platform-checklist.mjs --changed-from
origin/main`: exit 0, 0 anchors lost.
- `node scripts/check-role-word.mjs`: exit 0.
- **Dogfood battery** (`pnpm --filter @objectstack/dogfood test`, no
shard, no path): Test Files 474 passed | 3 skipped (477), Tests 4006
passed | 42 skipped (4048), no failures.
- CI on this head: 68 check-runs, 58 success, 10 skipped, none failing.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f)_
<!-- signed: security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent d01f399 commit f84dc19
14 files changed
Lines changed: 1780 additions & 67 deletions
File tree
- .changeset
- content/docs/permissions
- packages
- core/src/security
- mcp/src
- plugins/plugin-security/src
- runtime/src/domains
| 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 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
127 | 168 | | |
128 | 169 | | |
129 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
261 | 261 | | |
262 | 262 | | |
263 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
264 | 274 | | |
265 | 275 | | |
266 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
612 | | - | |
613 | | - | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
614 | 615 | | |
615 | 616 | | |
616 | 617 | | |
| |||
629 | 630 | | |
630 | 631 | | |
631 | 632 | | |
632 | | - | |
633 | | - | |
| 633 | + | |
| 634 | + | |
634 | 635 | | |
635 | 636 | | |
636 | 637 | | |
| |||
641 | 642 | | |
642 | 643 | | |
643 | 644 | | |
644 | | - | |
645 | 645 | | |
646 | | - | |
| 646 | + | |
| 647 | + | |
647 | 648 | | |
648 | 649 | | |
649 | 650 | | |
| |||
696 | 697 | | |
697 | 698 | | |
698 | 699 | | |
699 | | - | |
| 700 | + | |
700 | 701 | | |
701 | 702 | | |
702 | 703 | | |
703 | 704 | | |
704 | 705 | | |
705 | | - | |
706 | | - | |
| 706 | + | |
707 | 707 | | |
| 708 | + | |
708 | 709 | | |
709 | 710 | | |
710 | 711 | | |
711 | 712 | | |
712 | 713 | | |
713 | 714 | | |
714 | | - | |
| 715 | + | |
715 | 716 | | |
716 | 717 | | |
717 | 718 | | |
718 | 719 | | |
719 | | - | |
| 720 | + | |
720 | 721 | | |
721 | 722 | | |
722 | 723 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
380 | 396 | | |
381 | 397 | | |
382 | 398 | | |
| |||
3254 | 3270 | | |
3255 | 3271 | | |
3256 | 3272 | | |
3257 | | - | |
3258 | | - | |
3259 | | - | |
3260 | | - | |
| 3273 | + | |
| 3274 | + | |
| 3275 | + | |
| 3276 | + | |
| 3277 | + | |
| 3278 | + | |
| 3279 | + | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + | |
| 3283 | + | |
| 3284 | + | |
| 3285 | + | |
3261 | 3286 | | |
3262 | 3287 | | |
3263 | 3288 | | |
| |||
0 commit comments