Repository navigation
fix(plugin-security, spec): the master-detail write refusal names the master its user needs access to, in their language - #33884
Conversation
… localized userMessage naming the master Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
…age on create, edit and delete Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVPGBoi3MCGoKbW1Hv
📓 Docs Drift CheckThis PR changes 2 package(s): 1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 176 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # 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
|
|
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 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM Contract reviewServed-tier: PR #33884, card #33524. Read: the card body and its 9 comments, the PR body and file list, the net diff against ① Derived judgments
② Semver levelClause-②: no — confirmed against the diff (see ①). The changeset ③ Boundary flags
④ Design judgment
Findings:
No must-fix and no should-fix. Implemented-by: VERDICT: PASS |
|
domain:server#5 · zhuangjianguo · session_01QsR2jTjrNnh6b2BkCXFugM Review — PASSHead-sha: Contract face: What holds
Nits (no re-review needed)
Gates: at review time 56 success, 11 skipped, none red, so every check is green. Ordering: #33897 serializes after this PR (per the area). |
|
domain:server#5 · zhuangjianguo · session_01QsR2jVPGBoi3MCGoKbW1Hv 席位核对 · ACCEPT · Head-sha: 10f67c2 · 2026-11-15T14:16Z
|
…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>
Requested by Steedos · project thread
维护者速读
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
master_record_edit_deniedandmaster_record_read_deniedtake{{master}}, the master object's label. Their_opaqueforms name no master. The catalog header gains the table row and the reason for the opaque forms.BUILTIN_OPERATION_MESSAGESis typed as a string-keyed record of string-keyed string records (RecordofstringtoRecordofstringtostring) in the builtdist/system/index.d.ts(measured), and the new key names appear in no.d.ts/.d.mtsfile underpackages/spec/dist. So the public type surface does not move.security-plugin-cbp-write-gate.ts): a weak map beside the existing leg and question maps records which master a refusal may name.masterEditDeniedrecords 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.userMessagethrough the existingwithUserMessage. It is rendered by the existinguserFacingDenialMessageon the caller's ladder (request locale, then workspace default, then en). The master is named by its translated label (objects.MASTER.labelthrough 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,messageanddetailsare unchanged. The same throw serves insert, update, delete, transfer, restore and purge.Tests
controlled-by-parent-master-edit-user-message.test.ts(new, realObjectQLoverSqlDriver, 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 awriteRequiresMasterReaddetail; a writer who cannot read the reference gets the opaque sentence; an unlabeled master gets the opaque sentence; CONTROL: the owner-rule refusal carries nouserMessage; the REST data door'smapDataErrorrelays 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 undererrors.KEY.Acceptance notes
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'suserMessage. Acceptance 3 (nouserMessagekeeps the generic line) is that console pin. The server-side CONTROL is the owner-rule refusal.controlled_by_parentlevels) 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 diagnosticmessage's question.Verification
Head for the runs below:
cf6ef429. The PR head adds one merge ofmain(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)
withUserMessageattachment (if (copy && false)): 10 failed, 1 passed. Every naming case is red; the CONTROL stays green.{ master: rel?.master }): 1 failed.expected '您需要拥有这条记录所属合同的编辑权限…' to be '您需要拥有这条记录所属上级记录的编辑权限…'.nullMasterOwnerDeniedrecords a master: 1 failed (CONTROL).expected true to be falseon'userMessage' in e.label === mastercheck 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-securitytest: 268 files, 6692 passed, 45 skipped. Typecheck clean (including test-typecheck).@objectstack/spectest: 842 files, 26946 passed, 1 todo. Typecheck clean.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 arepublished-subpath-console.pinandpublished-subpath-hook-body.pin, which refuse in setup becausepackages/cli/distwas 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-loadsandcheck:i18nexit 3 (PREREQUISITE NOT MET: the workspace was not fully built), so they are NOT MEASURED and left to CI.--ranreconciliation: 92 derived, 90 run, 2 NOT-MEASURED, 0 UNRUN.pnpm lintexit 0;pnpm --dir ui run check:spec-symbolsexit 0;node scripts/check-nul-bytes.mjsexit 0.Generated by Claude Code
🤖 Generated with Claude Code