Skip to content

feat(security, verify): a controlled_by_parent row with no master is written by its owner or by Modify All on the detail - #31082

Merged
objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/issue-30906-null-master-write-gate
Nov 7, 2026
Merged

objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/issue-30906-null-master-write-gate

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #30906
Clause-②: yes
Metadata-protocol: semantic
Skills-docs: follow-up #30907

维护者速读

  • 改了什么:可选主表(required: false)的 controlled_by_parent 子对象里,主表引用为空的行现在可以写了:它的属主(owner_id)或对该子对象有「修改全部」的人可以改、删,其他人(包括只有「查看全部」的人)一律 403;新建一条不挂主表的行直接放行,创建者就是属主;给这种行挂上主表,要对那条主记录有编辑权;把已挂的主表清空,要对原主记录有编辑权,「属主可编辑」开关不覆盖清空。链式子对象(如联系人下的备注)在联系人没挂客户时,同样按联系人的属主规则判。os verify 的父级写入证明同时覆盖「挂主表」和「不挂主表」两种行,security/explain 会说明这条属主规则。
  • 为什么改:您对 controlled_by_parent admits an optional master (1/3): spec, lint and the read owner branch: a null-master detail row is readable by its owner only #30905 的裁决「A」:没有客户的联系人是私有联系人,只属于它的属主。这是三张卡的第 2 张;第 1 张放开了声明和读,写一直是 422,这类联系人建不出来、也改不了。
  • 风险与回滚:只放宽「可选主表且引用为空的行」这一类(以前一律 422),必填主表的所有答复逐字节不变;能看不等于能改,「查看全部」的人改不了别人的私有行。回滚即撤 PR,无数据迁移。
  • 先看:packages/plugins/plugin-security/src/security-plugin-cbp-write-gate.ts 里的 nullMasterRowWritable,以及 assertControlledByParentWrite 中 masterId == null && rel.optional 那一段;再看 controlled-by-parent-optional-master.test.ts 末尾的真实引擎用例块。
  • 两分钟验证:pnpm --filter @objectstack/plugin-security exec vitest run src/controlled-by-parent-optional-master.test.ts,预期 47 个全部通过;把 nullMasterRowWritable 改成恒返回 true 再跑,会红 10 个(见下文消融)。
  • 需要你做的:无,席位落地。

What changes

@objectstack/plugin-security — the write gate (ADR-0055 §3, step 2.8). A row of an OPTIONAL master (CbpRelation.optional) whose master reference is empty used to answer 422 MISSING_REQUIRED_FIELD on every write. It is now judged, on every shape the gate judges:

  • Owner rule (nullMasterRowWritable, new): such a row is written by its owner (owner_id, non-null, equal to the principal's userId) and by a holder of modifyAllRecords on its object (PermissionEvaluator.hasSuperuserWriteBypass). Everyone else is refused 403 PERMISSION_DENIED, details: { operation, object, recordId } naming the row, leg master_chain. A queue row (no owner) and every row of an object without an owner_id column are Modify All's alone.
  • Create: an insert (single or batch) naming no optional master is admitted; the creator becomes the owner (the platform's owner stamp). Every master a batch's rows do name is still asked.
  • Update / delete by id of a stored null-master row: the owner rule. Step 2.7 hands a detail's ownership floor to this gate, so without it a principal who merely READS the row (View All) could write it.
  • Predicate writes (multi: true): controlledByParentPredicateWriteMasters returns the selected null-master rows beside the masters (CbpPredicateWriteSelection) instead of throwing; each is judged by the owner rule, and a body naming a master is asked even when every selected row names none.
  • Setting a master (none → M): the row's owner rule, then edit on M. Emptying one (M → none): the §3 walk with edit on the stored master. The ownerMayEdit leg steps aside for a body that empties an optional master (card item 4).
  • Chains: a hop whose master is itself controlled_by_parent with an optional master of its own, left empty, ends the chain and asks the owner rule of that row (card item 5).
  • On behalf of: both passes ask the owner rule, each of its own principal (agent, then delegator). ISecurityService.checkControlledByParentWrite answers allow or deny / master_chain for such a row.
  • The frozen #9137 branch is untouched: the new block runs ahead of it and only for rel.optional, which none of the three frozen shapes can be (a master with no required derives no relation at all; readonly/system is refused by masterNotWritable first). A required master is answered byte for byte as before. Ownership transfer stays on allowTransfer.
  • security/explain names the owner rule when the served check refuses a null-master record (it would otherwise narrate the refusal as an unwalkable chain).

@objectstack/verify — the ADR-0054 proof. deriveParentWriteReachCases marks an optional-master detail (optionalMaster: true, via the spec's controlledByParentMasterOf). runParentWriteReachProofs proves it in both cases: its records under a master as every detail, and a new masters: 'none' reach per persona where the expectation is the owner rule — edit/delete allowed iff the persona holds the verb AND (owns the record OR holds Modify All on the object); create naming no master allowed iff it holds create. A null-master record the persona cannot read is listed in unreadableDetails, not probed.

Tests

  • packages/plugins/plugin-security/src/controlled-by-parent-optional-master.test.ts: card 1's "write gate is unchanged" block now pins the admitted insert; a new top-level block on the real engine (SQL driver, real sharing service, member_default floor) pins create, by-id update/delete (owner, View-All reader, Modify All, queue row, no owner column, non-reader), setting and emptying a master (with and without the opt-in), the chain hop, predicate update/delete, both on-behalf-of passes, the served member, and a required-master control. Every refusal asserts code + status + details and the stored row. Two explain pins for the narration.
  • packages/verify/src/parent-write-reach.test.ts: pwr_contact (optional master) joins the fixture; a new case proves the null-master reach per persona (View All on the detail is refused another's record, Modify All writes it, the owner writes its own); the count pins move to the measured totals.

Every negative pin was ablated: forbidden behaviour put back through scripts/ablation-replace.mjs (anchor must hit, restore proven against HEAD), suite red, restored.

Ablation Red
A1 owner rule admits everyone 10 failed / 35 passed
A2 ownerMayEdit leg covers an emptying body 1 (the emptying refusal)
A3 predicate asks the body's master only when a selected row names one 1
A4 setting a master on a null-master row asks nothing of it 1
A5 chain hop ends without the owner rule 1
A7 predicate null-master rows unjudged 1
A8 by-id null-master row unjudged 8
A9 explain without the null-master argument 1
verify A1 through dist/ pwr_contact CONTRADICTED on 2 of 64 writes

A4's first attempt was a no-op (the tool refused it: the replacement text already occurred, so the mutation did not count as landed); it was re-run in --delete mode and went red. The verify ablation was built into dist/ and checked by ablation-dist-preflight.mjs on both legs (marker present after mutate, absent after restore).

Acceptance notes

  • Mechanism assumptions, measured. (1) Step 2.7 hands the floor to the gate on every non-delegated by-id write of a controlled_by_parent detail (masterGateCoversThisWrite = !delegatorSets, platformFloorYieldsToObjectWriteModel): A1 shows a View-All reader's update of a row created by another principal LANDS once the owner rule is removed, so the rule has to live inside the gate. (2) @objectstack/verify synthesis does skip non-required relations (seedRecord), but every probe pinned the master explicitly, so the family produced no null-master record before this change; the new reach seeds the empty reference explicitly.
  • The refusal's leg is master_chain. ControlledByParentWriteDenialLeg is a closed spec vocabulary and packages/spec/** is outside this card; master_chain is the leg its text already gives "a master that is itself controlled_by_parent ... has an empty master reference", and here the chain ends at the row itself. A dedicated leg would be a spec contract change.
  • Card item 3 is read fail-closed. Setting a master on a null-master row asks the row's own owner rule first, then edit on the new master: an account editor who reads, but does not own, someone's private contact cannot adopt it. Pinned.
  • A principal who cannot read a null-master row meets the read door at step 2.7 (404 RECORD_NOT_FOUND) before the gate, as for every hidden row. Pinned.
  • An insert of a null-master row on an object with no owner_id column is admitted (card item 2), and its creator cannot read it back: such rows are View All's to read and Modify All's to write, as card 1 reads them.
  • Prose owed elsewhere, left untouched here (outside this card's surface): the ADR-0055 2026-11-06 amendment still says §3 is unchanged and "is amended again for §3 then" (docs/adr/**, Tier H); the spec contract docs of master_chain and master_reference_missing do not mention the optional master. Card 3 (controlled_by_parent admits an optional master (3/3): docs and the authoring skills teach it instead of a copied owner field #30907) teaches the docs and skills.
  • The verify proof covers the detail's own null master; the chain hop over a null-master middle row is pinned in the plugin-security suite only.

Verification

Full package suites, on head e6bb523
  • pnpm --filter @objectstack/plugin-security exec vitest run --maxWorkers=2: Test Files 248 passed (248), Tests 5796 passed, 45 skipped (5841). VERDICT command-exit 0.
  • pnpm --filter @objectstack/verify exec vitest run --maxWorkers=2: Test Files 48 passed (48), Tests 409 passed (409). VERDICT command-exit 0.
  • pnpm --filter @objectstack/plugin-security typecheck and pnpm --filter @objectstack/verify typecheck (each with its test layer): exit 0.
  • pnpm exec eslint --no-inline-config over the six changed source files: exit 0.
Derived gate families, on head e6bb523

node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 63 commands from the 7 changed paths (1085 changed lines, under the 3000 threshold). Each was run with its exit code recorded before any pipe, then --ran reconciled: 63 derived, 61 run, 2 NOT MEASURED, 0 UNRUN.

  • NOT MEASURED: pnpm check:dual-build-cjs-loads (exit 3, PREREQUISITE NOT MET: needs every package's dist/, a whole-tree build) and pnpm check:i18n (exit 3, PREREQUISITE NOT MET: needs the built CLI and its extract closure). Both run in CI's Lint & Repo Gates.
  • node scripts/check-plugin-teardown-shape.mjs --self-test first exited 3 (its positive control is pinned to a commit this shallow checkout lacked); the one commit was fetched and the re-run exited 0.
  • Every other derived command exited 0.

Generated by Claude Code

…e optional master is empty

WIP: the owner rule (owner or Modify All on the detail) on a by-id write,
on each row a predicate write selects and on a chain hop; an insert that
names no optional master is admitted; emptying an optional master asks
edit on the master it leaves, never the ownerMayEdit leg.

Claude-Session: https://claude.ai/code/session_017xRBcTJTE7kSbcMoJQ4Txf
Co-authored-by: Claude <noreply@anthropic.com>
…'s null-master records

WIP.

Claude-Session: https://claude.ai/code/session_017xRBcTJTE7kSbcMoJQ4Txf
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/plugin-security, @objectstack/verify, touching 32 documentable anchor(s).

22 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json d6b88f19f5bf9df334fa6ee95c5f88c67f7943a3.

⛔ 8 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: PERMISSION_DENIED (literal, 51 pages)
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 63 of 226 client-bound route-ledger rows — the other 163 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 163: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 104 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 21 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json d6b88f19f5bf9df334fa6ee95c5f88c67f7943a3 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from b5e6d04c89b4d3261874cc3819922b0417a9a25f — the merge of head 5fe5cdb46222e16b232765d98f8bfafd1448b653 into base d6b88f19f5bf9df334fa6ee95c5f88c67f7943a3, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin b5e6d04c89b4d3261874cc3819922b0417a9a25f && git checkout b5e6d04c89b4d3261874cc3819922b0417a9a25f
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin d6b88f19f5bf9df334fa6ee95c5f88c67f7943a3 5fe5cdb46222e16b232765d98f8bfafd1448b653 && git checkout -B drift-repro d6b88f19f5bf9df334fa6ee95c5f88c67f7943a3 && git merge --no-ff 5fe5cdb46222e16b232765d98f8bfafd1448b653

node scripts/docs-audit/affected-docs.mjs --json d6b88f19f5bf9df334fa6ee95c5f88c67f7943a3

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs d6b88f19f5bf9df334fa6ee95c5f88c67f7943a3 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…a null optional-master insert is refused

The verify family's ParentWriteReachReach (re-exported from the package
entry) widens, so the changeset declares Clause-② yes. The comment on
omissionRefusedByValidation said the write gate still refuses an insert
that leaves an optional master empty; the gate now admits it. Comment only.

Claude-Session: https://claude.ai/code/session_017xRBcTJTE7kSbcMoJQ4Txf
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#1 · sunhaolin · session_017xRBcTJTE7kSbcMoJQ4Txf

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 5fe5cdb46222e16b232765d98f8bfafd1448b653
Local-runs: none

The face is the Clause-②: yes declaration alone. The PR's file list carries no packages/spec/src/** and no governed path, so TIER_DEFAULT by the lane seat.

① Derived judgments

  • @objectstack/verify public surface (widened, correct). ParentWriteReachReach is re-exported from the package entry (packages/verify/src/index.ts). masters gains 'none', masterRead gains 'none', and an optional unreadableDetails?: ParentWriteReachOwner[] is added. All of it is additive on a report (output) type. Its only producer and renderer is parent-write-reach.ts, which the PR updates. No in-repo source outside packages/verify names the type (a git grep at this head finds only CHANGELOG lines; the control is that index.ts itself hits).
  • @objectstack/plugin-security accept set (widened at runtime, ruled). A write on a controlled_by_parent row whose optional master is empty was refused 422 MISSING_REQUIRED_FIELD. Now an insert is admitted under the detail's own create grant, and an update or delete is admitted to the row's owner or a Modify All holder on the detail (hasSuperuserWriteBypass, the modify bit). Everyone else gets 403 PERMISSION_DENIED on the master_chain leg. The by-id path, each null-master row a predicate write selects, the chain hop, and both on-behalf-of passes (per the PR's tests) all reach the one rule, nullMasterRowWritable. This runtime permission change is the human-floor class; the maintainer ruled it (「A」, quoted in controlled_by_parent admits an optional master (2/3): the write gate judges null-master rows (owner or modify-all), clearing a master needs edit on it, and the verify proof #30906's body).
  • Card item 4 holds. A body that empties an optional master skips the ownerMayEdit leg (!(rel.optional && bodyEmptiesMasterReference(...))) and takes the §3 walk on the stored master.
  • Accepted deviation, stricter than the card. null → M first asks the row's owner rule, then edit on M. Card item 3 asks only the new master. The extra leg stops a non-owner from attaching someone's private row to a master, and it narrows; it never widens.
  • No new published name in plugin-security. CbpPredicateWriteSelection lives in security-plugin-cbp-write-gate.ts, which src/index.ts does not re-export (zero hits; the control export has 42 hits in that file). ISecurityService.checkControlledByParentWrite returns existing union members only.
  • Required masters unchanged. The new branches are all guarded by rel.optional, and the Freeze note on assertControlledByParentWrite — the guard is the sole enforcement for three authorable master-reference shapes until the #8772 ramp completes #9137 frozen branch is untouched.

② Semver level

minor for both @objectstack/plugin-security and @objectstack/verify (.changeset/30906-cbp-null-master-write-gate.md). That matches an additive output-type widening and a ruled runtime admission. No !, no (narrowing) arm.

③ Boundary flags

Implemented-by: claude/issue-30906-null-master-write-gate
Reviewed-by: session_017xRBcTJTE7kSbcMoJQ4Txf

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#1 · sunhaolin · session_017xRBcTJTE7kSbcMoJQ4Txf

席位核对

ACCEPT · Head-sha 5fe5cdb46222e16b232765d98f8bfafd1448b653 · read at 2026-11-07T04:29Z

  • Shape. Draft into main. The body opens Fixes #30906, then Clause-②: yes, Metadata-protocol: semantic and Skills-docs: follow-up #30907. The changeset carries the same three lines. No other open card number sits beside a closing keyword. 8 files, +1037/−54: the changeset, plugin-security (security-plugin-cbp-write-gate.ts, security-plugin.ts, explain-engine.ts, security-plugin-cbp-relation.ts comment-only, the optional-master test) and verify (parent-write-reach.ts and its test). All are inside the claim's file surface as corrected in 6701304837.
  • Premise measured. On origin/main before dispatch, a null optional master threw MasterReferenceMissingError on the create, update and predicate paths. The dev confirmed step 2.7 hands the floor to this gate, so the rule lives in the gate.
  • Gate check-runs on this head. 37 success and 15 skipped, none failed or pending. Lint & Repo Gates and TypeScript Type Check both succeeded. mergeable_state is clean. check-governed-merges --pr 31082: NOT governed, 1091 lines ≤ 3000.
  • Accepted deviations.
    • null → M asks the row's owner rule before edit on M (stricter than card item 3).
    • explain-engine.ts narrates the null-master refusal.
    • The dev left the PR assignee and the post-create body to the seat (the seat patched the body for the Clause-② correction).
    • Repo-wide pnpm lint is CI's; Lint · ESLint succeeded on this head.
  • Out-of-scope dispositions.
  • Landing clause. The contract review record 6702137573 (TIER_DEFAULT, PASS) is on this same head. Not governed, so: ready, then auto-merge. Fixes #30906 closes the card on merge, and the seat strips pm:dispatched in the same stroke as the landing note. Then controlled_by_parent admits an optional master (3/3): docs and the authoring skills teach it instead of a copied owner field #30907's Blocked-by: #30906 is due for its unblock scan.

Spot checks of the diff: refusals assert code + status + details{operation,object,recordId} (the real-engine block of controlled-by-parent-optional-master.test.ts). The owner rule's ablation reads 10 red when it is forced to true, per the dev's run log in the PR body. The changeset's sentences match the gate diff (create admitted; update and delete by the owner or Modify All, 403 otherwise; emptying asks the stored master and is not covered by ownerMayEdit; required masters unchanged).

席位意见:可落地。只对「可选主表且引用为空」的行放宽,按您的裁决「A」只给属主或有「修改全部」的人;必填主表的行为不变。

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 7, 2026 04:30
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 7, 2026 04:31
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 0373715 Nov 7, 2026
53 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-30906-null-master-write-gate branch November 7, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants