Skip to content

fix(plugin-security, spec): the master-detail write refusal names the master its user needs access to, in their language - #33884

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/area-A2-33524
Nov 15, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/area-A2-33524

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steedos · project thread

维护者速读

  • 改了什么:主从(controlled_by_parent)明细记录因缺少主记录编辑权限被拒(403)时,服务端现在附带 userMessage,用用户的语言点名主对象(如"合同"),新增、编辑、删除都生效。
  • 为什么改:控制台只在拒绝带 userMessage 时显示具体原因,否则只显示"您无权保存此记录";HotCRM 订单到收款的用户看不出缺的是合同上的权限。
  • 风险与回滚:只新增 userMessage,code、状态码、message、details 和放行/拒绝结论都不变;回滚即还原本 PR。
  • 先看:security-plugin-authz-middleware.ts 步骤 2.8 的 catch 与 masterGateDenialMessage;security-plugin-cbp-write-gate.ts 的 MASTER_DENIAL_NAMED_MASTER(看不到主记录引用的用户不点名);operation-message.ts 新增的四个文案键。
  • 两分钟验证:pnpm --filter @objectstack/plugin-security exec vitest run src/controlled-by-parent-master-edit-user-message.test.ts,预期 11/11 通过。
  • 需要你做的:无,席位落地。

Fixes #33524

Clause-②: no
Metadata-protocol: none

What changes

  • spec, operation-message catalog: four new keys in every locale the catalog carries (en, zh-CN, ja-JP, es-ES). master_record_edit_denied and master_record_read_denied take {{master}}, the master object's label. Their _opaque forms name no master. The catalog header gains the table row and the reason for the opaque forms. BUILTIN_OPERATION_MESSAGES is typed as a string-keyed record of string-keyed string records (Record of string to Record of string to string) in the built dist/system/index.d.ts (measured), and the new key names appear in no .d.ts/.d.mts file under packages/spec/dist. So the public type surface does not move.
  • plugin-security, write gate (security-plugin-cbp-write-gate.ts): a weak map beside the existing leg and question maps records which master a refusal may name. masterEditDenied records the caller's object's master. The rewording for a caller who cannot read the master reference records none. nullMasterOwnerDenied (the owner rule of a row with no master) records nothing. masterGateRefusalUserCopyOf(e) reads the map. Nothing is added to the error itself.
  • plugin-security, authz middleware step 2.8 only: a gate refusal gains userMessage through the existing withUserMessage. It is rendered by the existing userFacingDenialMessage on the caller's ladder (request locale, then workspace default, then en). The master is named by its translated label (objects.MASTER.label through the i18n service), else its declared label. With no label (or a label equal to the API name), the opaque form is used. code, status, message and details are unchanged. The same throw serves insert, update, delete, transfer, restore and purge.

Tests

  • controlled-by-parent-master-edit-user-message.test.ts (new, real ObjectQL over SqlDriver, 11 cases): create en; create zh-CN with a translated label; edit en + zh-CN; delete; a de-DE request falls back to the zh-CN workspace; ja-JP with no translation uses the declared label in the ja sentence; the read question on a writeRequiresMasterRead detail; a writer who cannot read the reference gets the opaque sentence; an unlabeled master gets the opaque sentence; CONTROL: the owner-rule refusal carries no userMessage; the REST data door's mapDataError relays it with 403 / PERMISSION_DENIED. Every case also asserts the unchanged code, status and diagnostic opening.
  • operation-message.test.ts (spec): the four keys exist in every locale; named forms carry only {{master}} and opaque forms no placeholder; no grant or API vocabulary; edit differs from read and from sibling keys; en and zh-CN render; deployment override under errors.KEY.

Acceptance notes

  • Card acceptance 1 and 2 (create and edit, en and zh-CN) are pinned server-side here. The console half was pinned by ui/packages/plugin-form/src/ModalForm.markedRefusal-33524.test.tsx (PR fix(console): show the producer’s localized userMessage on metadata-save advisories and refusals #33576), which shows a refusal's userMessage. Acceptance 3 (no userMessage keeps the generic line) is that console pin. The server-side CONTROL is the owner-rule refusal.
  • A refusal raised on a hop above the immediate master (a chain of two controlled_by_parent levels) names the immediate master. That is true of the refusal, because the caller cannot edit that master. On such a hop the sentence's edit/read question mirrors the diagnostic message's question.
  • The record field-access probe runs the same middleware, so a probe refusal now also carries the sentence. The probe reads the verdict, not the text.

Verification

Head for the runs below: cf6ef429. The PR head adds one merge of main (30 commits, none touching the four changed files). The reruns on that head (closure build, spec check:generated, the plugin-security suite, the spec catalog test, both typechecks, rest's master-refusal wording test) are recorded in the os-dev-report on the card.

Ablations (each restored, `git diff HEAD` empty afterwards)
  • Drop the withUserMessage attachment (if (copy && false)): 10 failed, 1 passed. Every naming case is red; the CONTROL stays green.
  • Withheld refusal records the master ({ master: rel?.master }): 1 failed. expected '您需要拥有这条记录所属合同的编辑权限…' to be '您需要拥有这条记录所属上级记录的编辑权限…'.
  • nullMasterOwnerDenied records a master: 1 failed (CONTROL). expected true to be false on 'userMessage' in e.
  • Fall back to the API name (label === master check removed): 1 failed. expected 'You need edit access to the mue_vault…' to be 'You need edit access to the parent re…'.
Suites
  • @objectstack/plugin-security test: 268 files, 6692 passed, 45 skipped. Typecheck clean (including test-typecheck).
  • @objectstack/spec test: 842 files, 26946 passed, 1 todo. Typecheck clean.
  • Direct dependents of plugin-security, full test: rest 412/412 files (8442 passed); runtime 603/603 (10874); plugin-auth 277/277 (5465); organizations 18/18 (252); service-automation 282/282 (3976); plugin-dev 10/10 (89); cloud-connection 81/81 (1217); verify 52/52 (439). cli --project unit: 419/421 files, 5971 tests passed, 0 failed. The 2 failing files are published-subpath-console.pin and published-subpath-hook-body.pin, which refuse in setup because packages/cli/dist was not built. That is NOT MEASURED, not red, and CI builds it. The cli integration layer is declared to CI. Dogfood is declared to CI's merge-queue gate (no ! in the title).
Gates
  • dispatch-gates --commands: 92 commands, all run, 90 exit 0. check:dual-build-cjs-loads and check:i18n exit 3 (PREREQUISITE NOT MET: the workspace was not fully built), so they are NOT MEASURED and left to CI. --ran reconciliation: 92 derived, 90 run, 2 NOT-MEASURED, 0 UNRUN.
  • pnpm lint exit 0; pnpm --dir ui run check:spec-symbols exit 0; node scripts/check-nul-bytes.mjs exit 0.

Generated by Claude Code

🤖 Generated with Claude Code

@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation protocol:system tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

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

1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/permissions/system-context.mdx (via registerAuthzMiddleware (symbol, a top-level function))
What this run could not see
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 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; 123 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 — 176 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 45dee177b7454b58ccce8d440fc0a8862f774344 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 2dafb8142b4c6db887a828c7088133e6c821a549 — the merge of head 10f67c23aa13a7fdd75da8caf3583b428903f2e2 into base 45dee177b7454b58ccce8d440fc0a8862f774344, 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 2dafb8142b4c6db887a828c7088133e6c821a549 && git checkout 2dafb8142b4c6db887a828c7088133e6c821a549
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 45dee177b7454b58ccce8d440fc0a8862f774344 10f67c23aa13a7fdd75da8caf3583b428903f2e2 && git checkout -B drift-repro 45dee177b7454b58ccce8d440fc0a8862f774344 && git merge --no-ff 10f67c23aa13a7fdd75da8caf3583b428903f2e2

node scripts/docs-audit/affected-docs.mjs --json 45dee177b7454b58ccce8d440fc0a8862f774344

⚠️ 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 45dee177b7454b58ccce8d440fc0a8862f774344 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv

Request: review · PR #33884 · S1/A2 · Fixes #33524 · head 10f67c2 · 2026-11-15T14:07Z

Reviewer: review-a of seat domain:server#5. Dev report 6895596567 on #33524. The master-edit refusal gains a producer-marked, translated userMessage (master label or a generic sentence); code, status, message and the allow/deny decision are unchanged, the owner-rule refusal is the control. Clause-② no: the catalog keys live in BUILTIN_OPERATION_MESSAGES (typed Record<string, Record<string, string>>, no key in any .d.ts); please confirm that reading against the #33769 / #33646 precedents. Check that a caller who cannot read the master reference gets the generic sentence (no master label leaks). Surface includes authz-middleware step 2.8 (claim amendment). PR #33897 (#33696) serializes after this one.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM
Review claim (review-a, S1) · head 10f67c2 · 2026-11-15T14:08Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 10f67c23aa13a7fdd75da8caf3583b428903f2e2
Local-runs: none
Scope: packages/spec/src/system/operation-message.ts + packages/plugins/plugin-security/src/security-plugin-authz-middleware.ts, packages/plugins/plugin-security/src/security-plugin-cbp-write-gate.ts

PR #33884, card #33524. Read: the card body and its 9 comments, the PR body and file list, the net diff against c87e2ad2, and the check-runs on this head (56 success, 11 skipped, 0 failure; Check Changeset, Governed Surface Queue Guard, Lint · PM dispatch-gates, Spec property liveness, Test Core 1-8 and both type checks are among the successes). The rest of the diff (the two test files and the changeset) is the lane seat's ACCEPT at TIER_DEFAULT.

① Derived judgments

  • Clause-②: no is right. BUILTIN_OPERATION_MESSAGES is declared as a string-keyed record of string-keyed string records, so four new keys in four locales add data and move no declared type. The diff touches no file under packages/spec/api-surface* and no generated artifact, and the spec gates are green on the head. No export is added: masterGateRefusalUserCopyOf and MasterQuestion are imported only by the middleware, and packages/plugins/plugin-security/src/index.ts does not name the gate module. No accept set moves: renderOperationMessage already takes any messageKey string, and the errors.KEY override address is the existing one.
  • Precedents, as the tree has them. The two PRs named for comparison are not catalog additions. fix(cloud-connection, driver-sql): a package upgrade relaxes the NOT NULL its own declaration makes nullable #33769 declared yes (widening) for new root exports of @objectstack/cloud-connection and the public method SqlDriver.relaxDeclaredNotNull. fix(runtime,service-automation)!: the flow doors judge the served holders, so a disabled holder's slot answers no bare name (ADR-0150 D3) #33646 declared yes (narrowing) for served answers that changed. This PR has neither. The catalog precedent is changeset f09517e in packages/spec/CHANGELOG.md (18.4.0): one new key, record_queue_assign_denied, in all four locales, with only userMessage moving, declared Clause-②: no / Metadata-protocol: none. This PR has the same shape. (a03cf66, which introduced the userMessage channel, declared yes for its strictReadonlyWrites narrowing, not for its catalog keys.)
  • Wire surface: right. The refusal's code, status, message and details are untouched in the diff. The only served change is that an existing optional envelope member, userMessage, is now populated on the master-gate 403. No schema gains a member.
  • Allow/deny decisions: unchanged, right. The gate file's diff is one weak map, one reader and two set calls. The middleware's diff wraps the two existing gate calls in a try and rethrows the same error object. No verdict path is edited.
  • Metadata-protocol: none is right. No schema key, accepted value or metadata type is added. The override under errors.KEY is the existing translation address, as in f09517e.
  • A caller who cannot read the master reference is never told the master's label: confirmed by trace. See ④ for the path-by-path trace.
  • The owner-rule refusal, for a caller who cannot read the master reference, carries the opaque sentence: right. nullMasterOwnerDenied records a leg, so assertControlledByParentWrite rewords it for that caller, as it does on main, and the reworded refusal records { master: undefined }. A missing userMessage there would tell that caller the unreadable reference is empty. For a caller who reads the reference, the owner-rule sentence passes through with no entry and no userMessage, as the changeset states.

② Semver level

Clause-②: no — confirmed against the diff (see ①).

The changeset .changeset/33524-master-edit-refusal-user-message.md takes @objectstack/spec and @objectstack/plugin-security at patch. Those are the two released packages the diff moves, and Metadata-protocol: none takes patch. The PR body and the changeset body carry the same two declaration lines. No !, no BREAKING banner and no ADR-0087 marker are owed, because nothing served before is refused. Check Changeset is green on the head.

③ Boundary flags

  • open_questions: empty in the dev report (6895596567). Nothing to answer.
  • Deviation 1 (the PR opened before the contract self-check rule): answered. The self-check is in the report and its reading holds in ①.
  • Deviation 2 (dependent-package suites ran on cf6ef429, not on the final head): answered by the check-runs on 10f67c23. Test Core 1-8, Test UI 1-16 and the type checks are all success on this head.
  • The dev's two NOT MEASURED gates (check:dual-build-cjs-loads, check:i18n) are answered by CI: Lint & Repo Gates and its sub-jobs are success on the head.
  • Out-of-scope loose end (a refusal from a hop above the immediate master names the immediate master, with the hop's question): judged in ④ as a nit. No escalation.
  • Dev flags: none introduced by the diff.

④ Design judgment

packages/spec/src/system/operation-message.ts (hits). Holds against its first consumer and the card's scenario.

  • All four keys exist in en, zh-CN, ja-JP and es-ES. The named forms carry {{master}} and nothing else. The opaque forms carry no placeholder. interpolateValidationMessage is one pass, so a label is never re-read as a template.
  • The header's table row and paragraph agree with the code: the opaque forms are used for a writer who cannot read the master reference and for a master with no label, and an API name is never rendered.
  • The card's acceptance 1 and 2 (create and edit, en and zh-CN, naming the master object) are met by master_record_edit_denied with the label "Contract" / "合同". Acceptance 3 was pinned by PR fix(console): show the producer’s localized userMessage on metadata-save advisories and refusals #33576.
  • No sentence carries grant or API vocabulary.

security-plugin-cbp-write-gate.ts (implementing). Agrees with the contract. The rule under test is: the master is named only to a caller whose field-level read covers the detail's master reference. Every path:

  • masterEditDenied is the only builder that records a master, and it records rel.master, the immediate master object of the caller's own object. It never records a row id or a row value.
  • Every refusal judgeControlledByParentWrite throws with a leg passes through the catch in assertControlledByParentWrite. When callerReadsMasterReference is false, the original error is discarded and a new one is thrown that records { master: undefined }. The check fails closed: an unresolved relation, an unresolvable schema or posture (getReadableFields returns undefined or []) and a throw all read as "cannot read".
  • Delegated (on-behalf-of) second call: readerContext is opCtx?.context ?? context. Step 2.8 runs only when opCtx.context.userId is set, so both calls ask the read of the request's own context, never of delegatorContext alone. resolveProjectionFieldMask intersects the delegator's field mask on that context and fails closed on a dangling delegator. So the master is named only when both principals read the reference.
  • Nested chain: assertControlledByParentChainEditable receives the caller's masterEditDenied and denyMasterEdit and builds every hop's refusal through them, including the cycle, depth-bound and missing-relation legs and assertMasterRowReadable. A hop above the first therefore records the immediate master, gated by the same read of the caller's own reference field. No ancestor object above the immediate master is ever recorded.
  • The label is per object, not per row, so a predicate write or a batch insert discloses nothing about which rows or masters were selected.
  • Non-verdict errors (MasterDetailRelationMissingError, DetailRecordNotFoundError, MasterReferenceMissingError, MasterReferenceNotWritableError, store faults) carry no entry and pass through unchanged.

security-plugin-authz-middleware.ts (implementing, step 2.8 and masterGateDenialMessage). Agrees with the contract.

  • The catch reads only masterGateRefusalUserCopyOf(e). With no entry it rethrows untouched. With an entry it sets userMessage on the same error and rethrows it.
  • copy.master === undefined returns the opaque form before any label lookup, so neither the translation service nor getSchema is asked about the master for that caller.
  • Label ladder: the deployment's objects.MASTER.label in the language the sentence resolves to, else the declared label. An empty label, a miss that echoes the key, and a label equal to the API name all return the opaque form. Both lookups are wrapped, so a failing i18n service or registry cannot turn the 403 into a 500.
  • The locale ladder is the existing denialLocalesOf / denialLocaleOf pair, and the shape mirrors fieldEditDenialMessage.
  • checkControlledByParentWrite (the served member) is not in the catch and still reports only outcome and leg.

Findings:

  • nit — A refusal raised on a hop above the immediate master, including the metadata-cycle and depth-bound legs, tells the user to ask the immediate master's owner. That owner may not be able to grant the access, because the immediate master's access is itself derived. The sentence is still true of the refusal, and it also offers the administrator. The dev recorded this in the report and the PR's acceptance notes. Left as an accepted deviation.
  • nit — On a delegated write refused on the delegator's pass, the sentence reads "You need ...", although the access is missing on the delegator. The diagnostic message has the same shape on main. Accepted deviation.
  • nit — The docblock of withUserMessage still lists "the owner-anchor, queue and field-write 403s" as its three users. The UserFacingDenialKey docblock was updated and this one was not. A fix moves the head, so it is left for a follow-up.
  • nit (for the lane seat, outside ④'s files) — The new test file has no case for the delegated second gate call, the nested-chain hop, or the owner-rule refusal reaching a caller who cannot read the reference. All three were confirmed here by reading the code. A follow-up pin would keep them confirmed.

No must-fix and no should-fix.

Implemented-by: claude/area-A2-33524
Reviewed-by: session_01QsR2jTjrNnh6b2BkCXFugM

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM

Review — PASS

Head-sha: 10f67c23aa13a7fdd75da8caf3583b428903f2e2
Reviewer: review-a (areas S1 + S3) · read 2026-11-15T14:14Z · diff read against the merge's main parent c87e2ad2 (6 files, +489/−15, matches the PR files list)
Implemented-by: session_01QsR2jVPGBoi3MCGoKbW1Hv (area S1 dispatch) · Reviewed-by: session_01QsR2jTjrNnh6b2BkCXFugM; the contract face by an isolated sub-agent at CONTRACT_REVIEW_TIER

Contract face: packages/spec/src/system/operation-message.ts is a published-schema path, so the review is owed at CONTRACT_REVIEW_TIER. Its record is comment 6895788536 (PASS, Local-runs: none). It also covers the two implementing files, security-plugin-authz-middleware.ts and security-plugin-cbp-write-gate.ts. This verdict covers the rest of the diff at TIER_DEFAULT.

What holds

  • Area point 1, Clause-②. no / none is right. The four keys are data in a string-keyed record. No declared type, export or accepted request moves. The matching precedent is the record_queue_assign_denied catalog addition, which was declared no. fix(cloud-connection, driver-sql): a package upgrade relaxes the NOT NULL its own declaration makes nullable #33769 and fix(runtime,service-automation)!: the flow doors judge the served holders, so a disabled holder's slot answers no bare name (ADR-0150 D3) #33646 declared yes for other reasons (a new export, a changed served answer), so they are not the comparison.
  • Area point 2, no label leak. The master's label never reaches a caller who cannot read the master reference. The reword catch fails closed, records no master and returns the opaque form before any label lookup. The delegated second gate call reads the request's own context, so the delegator's field mask is intersected. A nested hop only ever records the immediate master, behind the same check. All of this was traced in the code. The ablation "withheld refusal records the master" goes red.
  • code, status, message and details are unchanged. Only userMessage is added. The label ladder (translation, then declared label, then the opaque form when the label is empty or equals the API name) cannot turn the 403 into a 500, because both lookups are wrapped.
  • Tests: 11 real-stack cases, the REST relay case, and the spec catalog checks. All four ablations go red as reported. Changeset: patch for both packages, which is right for a non-protocol addition.

Nits (no re-review needed)

  1. The owner-rule refusal does carry the opaque userMessage when the caller cannot read the reference. On main that caller is already reworded into the master-access refusal, so the opaque copy matches the message they get, and that is right. The changeset and PR body say the owner-rule refusal "carries no userMessage". That holds only for a caller who can read the reference. Tighten the wording if you touch the body again.
  2. A follow-up pin card (or fold-in on a later card) for the three paths the record confirmed by reading: the delegated second gate call, the nested-chain hop, and the owner-rule refusal reaching a caller who cannot read the reference.
  3. The withUserMessage docblock still lists three users. It now has four.
  4. The record's accepted deviations: on a hop above the immediate master the sentence names the immediate master, and a delegator-pass refusal reads "You need …".

Gates: at review time 56 success, 11 skipped, none red, so every check is green.

Ordering: #33897 serializes after this PR (per the area).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv

席位核对 · ACCEPT · Head-sha: 10f67c2 · 2026-11-15T14:16Z

  • Review: review-a PASS 6895810194 at this head. Contract review at CONTRACT_REVIEW_TIER: record 6895788536 (PASS, isolated reviewer), covering the catalog, authz-middleware and write-gate files.
  • Declarations: Clause-②: no (confirmed by review against the record_queue_assign_denied precedent, f09517e), Metadata-protocol: none, patch changeset. Nothing served is refused; code, status, message and the allow/deny decision are unchanged.
  • Governed: check-governed-merges --pr 33884 says NOT governed, +489/−15, under the 3000-line threshold.
  • Checks on this head: 56 success, 11 skipped (path-filtered), 0 red, 0 pending. Mergeable state clean.
  • Review nits (no re-review): the changeset's "carries no userMessage" sentence is too broad for the owner-rule refusal to a caller who cannot read the reference; follow-up pins for the delegated, nested-hop and owner-rule-unreadable paths; the withUserMessage docblock count. They go into one loose-ends card after this lands.
  • Landing: area S1, on the maintainer's line in the area thread (2026-11-15T11:06Z). pr_ready + automerge_enable follow in this stroke. PR perf(objectql): drop a required master's parent chain for a View All reader over unrestricted hops #33897 (security: an unrestricted reader of a controlled_by_parent detail with a required FK drops the vacuous parent-chain leaf (epic #33631 R4) #33696) rebases after it.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 15, 2026 14:16
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit c59198f Nov 15, 2026
68 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/area-A2-33524 branch November 15, 2026 15:27
scbdzhwl pushed a commit to scbdzhwl/objectstack-analysis that referenced this pull request Nov 16, 2026
…reader over unrestricted hops (objectstack-ai#33897)

<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbSUQWB2j9eHYsRcrCiq1X1C)_

**Do not land before objectstack-ai#33820 (ADR-0139 status-line amendment) merges.**

## 维护者速读

-
改了什么:对"受控于父对象"且主从字段必填的明细对象,只有同时持有明细"查看全部"、且每一级主对象读取范围都不受限的读者(典型是单租户管理员),读取时不再带父链子查询;其他读者完全不变;所有写操作(条件更新/删除、按
id 写、钩子里的读取)仍带父链,行为与 main 完全一致。
- 为什么改:这类读者的父链子查询挡不住任何有主记录的行,只拖慢管理员的列表、计数和汇总(卡上 1M 行实测快 29% 到 42%,本 PR
未重测)。
-
风险与回滚:该类读者的合计、计数、汇总可能包含孤儿行(主记录缺失或为空的明细),这是维护者裁决接受的;限制读者、仅有明细查看全部的读者、普通成员仍看不到孤儿行;回滚即
revert 本 PR。
- 先看:`engine-readable-ids-permission-formula.ts` 第 5
步、`readerViewsAllOf` 与
`READABLE_IDS_WRITE_IN_FLIGHT`;`engine-middleware-and-context.ts`
新增的写作用域;`security-plugin-cbp-read-filter.test.ts` 的反向钉子与写路径钉子。
- 两分钟验证:`pnpm --filter @objectstack/plugin-security exec vitest run
--maxWorkers=2 src/security-plugin-cbp-read-filter.test.ts`,预期 12 个测试全绿。
- 需要你做的:等 objectstack-ai#33820(ADR-0139 状态行修订)合并后再合并本 PR。

Fixes objectstack-ai#33696

Clause-②: no
Metadata-protocol: none

## Ruling

Ruling record 6893666857 (replaces 6893097935), quoted verbatim as it
binds this card:

> - The parent chain is dropped only for a reader who holds view-all on
the detail AND whose every master hop answers unrestricted (the engine's
per-hop scope, not `hasSuperuserReadBypass`), with a required master FK.
That reader sees null and dangling-FK rows inside its own tenant wall,
consistent with objectstack-ai#30905 ruling A. Every other reader, members included,
keeps the chain unchanged.
> - This deliberately lifts objectstack-ai#24932 ruling B item 4 and ADR-0139 D6's ⛔
for that reader class only. **The PR must not land before the ADR-0139
status-line amendment** (citing this record; ADR-0055's 10-22 note in
step) merges. That amendment is a docs/adr/** card for the skills lane,
which the seat files.
> - Pins: the three controlled-by-parent-leaf-switch tests are rewritten
for the view-all + unrestricted reader. Reverse pins stay: a reader with
a restricted master hop, and a reader with view-all on the detail only,
still never see null or dangling rows.
> - Release note: totals, counts and aggregates for that reader may
include orphan rows. A follow-up card to close the orphan sources
(option B of the original request) is owed as the PR's one loose-ends
card.
> - Multi-tenant deployments: a tenant admin's master scope is the
tenant wall, so it is not unrestricted. No speed-up there, by design;
widening that is a separate decision.

## Review 6895328067: route (a), write doors unchanged

The review found that the drop reached the write doors. The security
plugin's predicate-write narrowing, its 2.8 gate's predicate leg and its
step-2.7 by-id read all ask `ql.find`/`findOne` under the caller's
context. The seat ruled route (a), claim amendments 6895345175 and
6895620230: the write paths stay byte-identical to main. A write's
middleware chain now runs inside an engine async scope, and step 5 drops
nothing inside it. No plugin-security write-door source file changes.

## What changes

- `packages/objectql/src/engine-readable-ids-permission-formula.ts`:
`composeReadableIdsChain` gains step 5. A leaf over the REQUIRED master
of a `controlled_by_parent` object, in an AND position and as the whole
comparand of a `$in` on its `master_detail` field, is dropped instead of
composed. Two conditions must both hold:
- the master's answered scope is `undefined` (admitted, no row
condition), per hop: a nested scope left empty once its own leaves are
dropped answers `undefined`, so a chain drops whole only when every hop
is unrestricted;
- the caller holds View All (`viewAllRecords` or `modifyAllRecords`) on
the detail, read from `ISecurityService.getEffectiveObjectPermissions`
(`readerViewsAllOf`, asked once per read). A delegated caller, a service
without that member, or a call that throws keeps the chain. A failure
costs the subquery, never a row.

An optional master, a leaf inside `$or` or `$not`, and every
non-`controlled_by_parent` object compose exactly as before.
- `packages/objectql/src/engine-middleware-and-context.ts`: **approved
widening** (claim amendment 6895620230, `executeWithMiddleware` only,
+4/−1). For a write-epoch operation (insert, update, delete, purge,
restore), the middleware chain runs inside
`READABLE_IDS_WRITE_IN_FLIGHT`, an `AsyncLocalStorage` exported from
`engine-readable-ids-permission-formula.ts`. `readerViewsAllOf` answers
false inside it, so every read made while a write runs keeps the chain:
the security write-door reads, hook reads and cascade reads. It is an
async scope rather than a context stamp, for the reason
`SecurityPlugin.engineOperationScope` gives: a context is shared and
spread across those very reads.
- `packages/objectql/src/engine.ts`: **approved widening** (coordinator,
2 lines). The private `composeReadableIdsChain` host literal gains a
`_registry` getter, the same getter shape the neighbouring host literals
use.
- `packages/plugins/plugin-security/src/security-plugin.ts`: a
prose-only paragraph in the `computeControlledByParentFilter` docblock
(review should-fix 2). It says the drop is read-only and that write
paths keep the chain.
-
`packages/plugins/plugin-security/src/security-plugin-cbp-read-filter.ts`:
a docblock paragraph only. The leaf is still written for every caller,
and the engine drops it. View All on the detail alone never drops it.
-
`packages/plugins/plugin-security/src/controlled-by-parent-leaf-switch.test.ts`:
**approved widening**. The existing pins are unchanged. A new reader
(View All on the account, contact, quote and line objects) gets legs in
the three leaf-switch tests, and those legs see the dangling and null
rows and run one statement with no `in (select`.
- `.changeset/33696-drop-unrestricted-cbp-chain.md`: patch for
`@objectstack/objectql`, with the ruling's release-note sentence.

Perf, the card's measurement, not re-run here (1M rows): page SQLite 397
to 281 ms, PG 97 to 56 ms; total SQLite 217 to 136 ms, PG 78 to 54 ms.

## Tests

Pins on a real stack (`security-plugin-cbp-read-filter.test.ts`:
ObjectQL, SqlDriver on better-sqlite3, the real SecurityPlugin and
SharingService, orphan rows seeded through the driver), 8 tests:

- (a) View All on the detail over unrestricted hops: no parent-chain
subquery, every stored row including the orphans, count 7, `findOne` of
a dangling row. Plus parity on the rows whose chain resolves, and the
analytics door (the `getReadFilter` scope passed as `where`) composing
the same way.
- (b) a reader with a restricted master hop keeps the whole chain and
sees no orphan.
- (c) a reader with View All on the detail only keeps the whole chain
and sees no orphan.
- (d) a plain member keeps the chain over a restricted master and over
an unrestricted (`public_read_write`) one. The admin control on the same
object drops it.
- (e) isolated tenancy: org A and org B never read each other's rows,
and the tenant wall keeps the chain.
- An optional master keeps its leaf.

Write-door pins (review 6895328067, route (a)), in the same file, 4
tests. The View All admin reads over unrestricted hops, and the set it
writes holds orphans:

- a hook's read inside a write, under the caller's context, keeps the
chain and sees no orphan (control: the same caller's plain read drops
it);
- a predicate delete over a set holding an empty-required-master orphan
lands on the other row and leaves the orphan;
- a predicate update over a set holding an empty-master orphan and a
dangling-master orphan lands on the other row and leaves both;
- a by-id update of a dangling orphan and a by-id delete of an
empty-master orphan both still answer `RECORD_NOT_FOUND` / 404.

Measured on head 2c6025c's objectql source (the three objectql files
set back to 2c6025c, then restored with `git diff HEAD` empty), all 4
are red:

| Pin | Red on 2c6025c |
|---|---|
| hook read | it sees the 4 orphans (`line_a_ghost`,
`line_a_ghost_account`, `line_a_null`, `line_b_ghost`) |
| predicate delete | refused: `MISSING_REQUIRED_FIELD` / 422 |
| predicate update | refused: `MISSING_REQUIRED_FIELD` / 422 |
| by-id write | refused: `PERMISSION_DENIED` / 403, not
`RECORD_NOT_FOUND` / 404 |

On origin/main's objectql source, the 3 write pins pass and the hook
pin's write leg passes. Its plain-read control leg fails there, as it
should, because main drops nothing. Ablations (`ablation-replace`, every
restore checked as blob == HEAD):

- deleting the `READABLE_IDS_WRITE_IN_FLIGHT` guard in
`readerViewsAllOf` turns all 4 red;
- running a write's chain outside the scope in `executeWithMiddleware`
turns all 4 red.

Unit pins (`engine-readable-ids-nested-composition.test.ts`, a new
describe, 17 tests in the file): the drop at the root, in an `$and` and
in a merged-key position; a restricted hop keeps both leaves; `$or`,
optional and non-cbp positions compose; five kinds of caller without
View All on the detail keep the chain (no View All, View All on another
object, no service member, a service that throws, delegated); a
non-readable master gives `$in: []`.

Ablations, on the committed implementation (`node
scripts/ablation-replace.mjs`, every restore proven `blob == HEAD
8ec17d5` and `git diff HEAD` empty):

| Mutation | Real-stack pins red | Unit pins red |
|---|---|---|
| per-hop check removed (drop whenever the master answered) | (b), (c) |
restricted hop keeps; caller without View All keeps |
| `readerViewsAllOf` answers `true` | (d) | caller without View All
keeps |
| step 5 disabled | (a), parity, analytics, (d) admin control | drop at
root and `$and`; `$or`/optional/non-cbp |

<details><summary>Full suites</summary>

Runs were under `scripts/pm/os-verify-lock.sh`, with each exit captured
before any pipe.

On head `df3fb3b9` (the implementation plus origin/main at c59198f,
which includes objectstack-ai#33884's step-2.8 changes):

- `@objectstack/plugin-security`: `pnpm test` exit 0, 269/269 files,
6705 passed and 45 skipped. `typecheck` exit 0.
- `@objectstack/objectql`: `pnpm test` exit 0, 598/598 files, 13238
tests. `typecheck` exit 0.

On head `3089656f` (the same implementation, one main merge earlier),
the direct runtime dependents of objectql, after `pnpm --filter
'PKG^...' build` (exit 0). All exits 0:

- example-embed-objectql 1/1 files, 2 tests
- plugin-audit 94/94, 1541
- plugin-email 53/53, 1018
- plugin-pinyin-search 4/4, 39
- plugin-sharing 74/74, 1525
- plugin-webhooks 25/25, 307
- runtime 605/605, 10958 (19 skipped)
- scenarios 34/34, 859
- service-automation 282/282, 3982
- cloud-connection 82/82, 1224
- example-todo 9/9, 249
- plugin-dev 10/10, 89
- verify 52/52, 439
- cli `vitest run --project unit` 422/422 files, 6002 tests

The second main merge touches none of this PR's files.

Packages that depend on objectql only as a devDependency, the cli
integration tier, and dogfood are left to CI. The PR title has no `!`,
so the full dogfood battery is not owed.

</details>

## Acceptance notes

- Loose-ends card owed (the ruling's one): stop orphan rows at their
sources (option B of the original request). Measured sources: a
system-context insert or update that names a missing master is stored
(the documented residual in `engine-referential-integrity.ts`), and
promoting an optional master to required leaves rows with a NULL foreign
key. The seat files it.
- objectstack-ai#33820 (skills lane) carries the ADR-0139 status-line amendment. This
PR does not touch `docs/adr/**`.
- Under walled tenancy the tenant admin's master scope carries the
Layer-0 tenant equality, so nothing is dropped there, by design. Pin (e)
measures this.
- Open PR objectstack-ai#33652 (another seat) edits the same function in
`engine-readable-ids-permission-formula.ts`: the import line and the
final `composeReadableIdsLeaves` call. The two PRs conflict as text, and
whichever lands second rebases. They do not conflict in meaning. Its
planned relation-semi-join leaves are never asked into `chain.answers`,
and step 5 drops only a leaf whose master has an answer, so it leaves
them alone. objectstack-ai#33703 touches `engine.ts` far from this literal.

## Verification

- At head `df3fb3b9`, `dispatch-gates --commands --repo
objectstack-ai/objectstack` derived 77 gate families.
- 74 of them ran locally, every one exit 0. `--ran` reconciliation: "77
derived, 74 run, 0 NOT-MEASURED, 3 UNRUN". The 3 are whole-repo families
left to CI: `check:i18n`, `check:dual-build-cjs-loads`,
`check:type-check-debt`.
- `node scripts/check-nul-bytes.mjs` exit 0. `pnpm lint` (whole-repo
eslint) is left to CI.
- `git merge-tree --write-tree --name-only` from `df3fb3b9`:
- origin/main: clean. Main is now 18 commits ahead, and none of them
touches this PR's files.
- objectstack-ai#33887 (`engine-middleware-and-context.ts`, its
`claimReferentialCascadeDelete`): clean. This PR's hunk stays inside
`executeWithMiddleware`.
  - objectstack-ai#33884: merged into main as c59198f and included in this head.
- objectstack-ai#33652: conflicts in `engine-readable-ids-permission-formula.ts`, in
two hunks: the import block and the step-5 / final
`composeReadableIdsLeaves` lines. That overlap was known before. The two
changes do not conflict in meaning, and whichever lands second rebases.

---

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
<!-- signed: domain:server#5 · zhuangjianguo ·
session_01QsR2jVPGBoi3MCGoKbW1Hv -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
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 protocol:system size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant