Repository navigation
test(dogfood): probe app-authored RLS wideners on the bulk write path (#6736) - #7274
Merged
Merged
Conversation
…#6736) End-to-end probe, not a fix. #6736's acceptance section names an end-to-end measurement as the first thing needed ("the mechanism above is a code read"), and the maintainer's 2026-08-08 ruling on #5493 (Q2 = A1) deferred the fix for this path with a stated reason: no measured pull. This supplies the missing measurement and pins today's behaviour so it cannot change unobserved in either direction. Measured on the real stack (bootStack + real SecurityPlugin + real SharingServicePlugin + real ObjectQL engine), app-authored RLS wideners on update and delete: update({multi}): declaration admits 3 rows, statement touches 1, no error delete({multi}): declaration admits 3 rows, statement removes 1, no error Both narrowed by the same predicate, `{ owner_id: <caller> }`, which buildWriteFilter contributes and the bulk branch ANDs into the AST. Zero WARN or ERROR lines in the whole run: the affected-row count is the only signal and it names no authority. Two discrimination controls keep the headline numbers meaningful: the same principal / row / widener SUCCEEDS on the by-id path (so the declaration is live, post-#5493), and a row the widener does not admit is still refused with the ADR-0112 envelope (so the widener has a real boundary). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BM1tNf5U3nEbHKR4fo5qVQ
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckNo hand-written docs reference the 0 changed package(s). ✅ |
os-zhuang
marked this pull request as ready for review
August 10, 2026 04:41
This was referenced Nov 26, 2026
Nenzyz
pushed a commit
to Nenzyz/objectstack
that referenced
this pull request
Dec 1, 2026
…p-authored update or delete policy admits (objectstack-ai#38131) Fixes objectstack-ai#37535 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:业务用户按条件批量改或删记录时(流程里的批量节点、脚本),应用自己写的“满足条件可改 / 可删”规则现在也生效;以前单条能改四条、批量只改两条且不报错,现在批量和单条改的是同一批记录。 - 为什么做:这是你在“批量改记录时,要不要也认应用自己写的放行规则?”上选的“现在定:批量也认”,属于“按条件批量写的权限判定”专题,让读、写、批量写的结果一致。 - 出错会怎样:碰到的是写了改 / 删放行规则的应用,批量会多改到规则放行的那些记录;没写这类规则的应用、代他人操作的写入都和以前完全一样;有问题可以直接撤回这个改动。 - 要你做什么:无。 ## What changes Ruling record 7190344023 on objectstack-ai#35934, option **2a**: the security service gains an optional, filter-shaped answer, and the record sharing middleware ORs it into its bulk write scope. - **`@objectstack/spec`**: `ISecurityService.getAuthoredRowWriteFilter?(object, operation, context)`, the filter-shaped twin of `checkAuthoredRowWrite`. It is optional, typed on the same `AuthoredRowWriteOperation` (`update` / `delete`), and `undefined` is the answer that widens nothing (absence, abstention, failure). - **`@objectstack/plugin-security`**: the head of `checkAuthoredRowWrite` (principal, on-behalf-of, sets, the authored `using` pre-check, Layer 0 + Layer 1 compiled with the floor taken out of the sets by provenance) moved, unedited, into one helper, `authoredRowWriteLayers`. The verdict and the new `getAuthoredRowWriteFilter` both read it, so a row matches the filter iff the verdict admits it, and there is a pin for that. The filter is `layer0 AND layer1`, the verdict's probe predicate without its `{ id }` term. It does no read. The member is served on the registered `security` service (`security-plugin-security-service.ts`, which is where the registration lives since cut 11, beside `security-plugin.ts`). - **`@objectstack/plugin-sharing`**: `SharingSecurityProbe` declares the member. `SharingService.probeAuthoredRowWriteFilter` is a passthrough that answers `null` for an absent service or member, a principal-less or delegated context, a throw (logged once at `warn`), or anything that is not a filter object. The middleware's bulk branch (`sharing-plugin.ts`, after the ADR-0090 D10 delegator intersection) sets `writeFilter = { $or: [writeFilter, authoredScope] }` before the existing `ast.where = composeAnd(...)`. The branch is skipped when the scope is already `null` and for an on-behalf-of write. Ruled terms, as implemented: - (i) The bulk scope is sharing scope OR authored scope, then ANDed into the write as today. plugin-security's own layers are untouched. - (ii) Verb for verb: the operation is the middleware's write class, and the policies are collected per operation. - (iii) A delegated write is not widened: the middleware, the passthrough and the security helper each abstain on `onBehalfOf`. - (iv) An absent member, no authored `using` policy, or any failure leaves today's scope. - (v) The pins moved. See Tests. - `buildWriteFilter`, `checkEdit` and `checkDelete` are not edited. There is no per-row probe on the bulk path. - The 2026-08-15 ruling block (no filter-provenance marking on this merge) is intact. The new composition is unmarked, as that block requires. `content/docs/permissions/rls.mdx`: one paragraph said a policy-admitted row "is not reached" by a predicate write and told authors to write it by id. This change makes that false, so the paragraph now states the widened bulk scope. ## Why By id, a row an app-authored `using` update or delete policy admits was written (the sharing gate defers to `checkAuthoredRowWrite`). A predicate write left the same row out, silently, with a smaller count. The ruling replaces the 2026-08-08 deferral on objectstack-ai#5493 (Q2 = A1) and the objectstack-ai#6736 reopen condition, and states the bulk composition semantics that hold required. ## Tests The premise clause, measured first at `f72f3353` (this branch's base): - **Premise 10** holds. The relief pin `predicate-write-floor-deferral.test.ts:632-637` expected by id `r1`–`r4` and by predicate `r1`, `r2`. - **Premise 12** holds. `grep -rn -A8 "rowLevelSecurity" examples packages/apps --include=*.ts | grep -E "operation|using"` finds one authored row policy, the showcase's `select` policy, and no authored update or delete widener. Pull is still zero. The ruling decided it anyway. - **The PR objectstack-ai#7274 probe** is `packages/qa/dogfood/test/bulk-widener-probe.dogfood.test.ts`, the one file PR objectstack-ai#7274 added (read off its file list). `git grep 7274` misses it because the file cites `objectstack-ai#6736`. Without the fix (ablation below) its MEASURE cases read exactly their old pins: update touches `['n_bob_open']`, and delete leaves `['d_alice_stale_1', 'd_alice_stale_2']`. - **Named premise: holds.** With the authored scope ORed in, the rows a predicate write changes equal the rows the by-id write admits: - on the relief fixture: predicate `r1`–`r4`, by id `r1`–`r4`; - on the objectstack-ai#7274 fixtures: update touches `n_alice_open_1`, `n_alice_open_2`, `n_bob_open` = `declaredAdmitted`, `affected: 3`; delete removes all 3, `survivors: []`, `affected: 3`; - no row changes for a caller who holds no authored `using` policy (ALICE and CAROL under the rep set, ALICE under a check-only policy), and the scope answers `undefined` for them. Pins moved (term (v)), plus one more: - `predicate-write-floor-deferral.test.ts`, "the relief only ever adds rows": the predicate expectation moves from `['r1','r2']` to `['r1','r2','r3','r4']`. - `bulk-widener-probe.dogfood.test.ts`, the two MEASURE cases: update 1 → 3 and delete 1 → 3, held to `declaredAdmitted`. The header is rewritten from "pins the defect" to "pins the fix". - **Not named by (v)**: `plugin-security/src/operator-id-write-gate-33928.test.ts` pinned the same divergence on a `private` object with a read share. A two-key `{ id, stage }` predicate under `multi: true` "leaves the row" the policy admits. It now writes it, as the by-id write does. See Acceptance notes. New pins: - **`predicate-write-floor-deferral.test.ts`**, `[objectstack-ai#37535]` describe, real `SecurityPlugin` + `SharingService` middleware over better-sqlite3. Each case is the objectstack-ai#35802 three-way comparison: predicate rows = by-id rows = the named set. - Widening: ALICE update and delete `r1`–`r4`. BOB update with `r1` closed: `r2`, `r3`, `r4`. CAROL delete with `r2` closed: `r1`, `r3`, `r4`. Tenant wall: an open deal in another org is not written. - Verb for verb: an update-only policy widens update (`r1`–`r4`) and not delete (`r1`, `r2`), and the reverse. - CONTROLS: no authored policy, check-only policy, and a delegated write (ALICE on behalf of FRANK, both under the wideners, FRANK a plain member so his half keeps a sharing scope) writes `[]` as by id. A spy shows the scope is never asked. - Absent member, a rejecting member, and an internal compile failure all leave `r1`, `r2` or answer `undefined`. - One answer: over a mixed matrix, the scope's rows equal the rows `checkAuthoredRowWrite` admits, for both verbs. - **`plugin-sharing/src/authored-row-write-deferral.test.ts`**: the old "the BULK path is untouched" describe is replaced. It pins the exact composed `where` (`{ $and: [pred, { $or: [sharing, authored] }] }`), the delete verb asked as delete, an unchanged scope for a no-policy caller, no call for a delegated write, and unchanged scope for an absent member, a throw (one `warn`), a non-object answer (4 shapes) and no security service. - **`spec/src/contracts/security-service.test.ts`**: the member is optional (unguarded call is a compile error, `@ts-expect-error`), not listable as required, its operation is `AuthoredRowWriteOperation` (`select` refused), and absence is `undefined`. - `registered-security-service-members.pin.test.ts` lists the member (its typecheck reds until it does). The two plugin-sharing middleware doubles (`lifecycle-verb-write-gate`, `operator-id-write-gate-33928`) serve `probeAuthoredRowWriteFilter: async () => null`. Red without the fix (ablations, each through `scripts/ablation-replace.mjs` with a `dist/` preflight, restore proven by blob hash and a rebuilt clean `dist/`): - **A**: the middleware's OR line replaced by a never-true guard. 8 widening pins in `predicate-write-floor-deferral.test.ts` go red (relief pin, 4 widening, 2 verb-for-verb, tenant wall) and so does the composition pin in `authored-row-write-deferral.test.ts`. All controls stay green. Against the dogfood probe: both MEASURE cases red (`expected [ 'n_bob_open' ]`; 2 survivors), integrity/C1/C2 green. The plugin-security full run at `2d086e65`, before the third pin moved, showed that pin red under the fix in the other direction. - **B**: the three delegated guards removed. Both delegated controls go red (`expected [ 'r1', 'r2', 'r3', 'r4' ] to deeply equal []`). - Two first attempts were no-ops and were re-run: a deleted line failed the DTS build, and a `void` marker was dropped by esbuild. The preflight caught the second. Neither counted. ## Acceptance notes - **Landing point**: as named on the card, plus `security-plugin-security-service.ts`. The `security` service registration lives there since cut 11 and `security-plugin.ts` only hands it the host. `sharing-service.test.ts` gets no new case: the passthrough is pinned in `authored-row-write-deferral.test.ts`, the existing harness for its by-id twin (AGENTS.md: a new pin for a component with a shared harness goes into that file). - **A third pin moved** beyond (v)'s two: plugin-security's `operator-id-write-gate-33928.test.ts`. Its expectation was the divergence the ruling removes, on a `private` object with a read share. Which branch each shape takes is still pinned against the engine's dispatch decision in plugin-sharing's file of the same name. - **Member name** `getAuthoredRowWriteFilter`, on the precedent of `getReadFilter` (filter-shaped, `undefined` = no answer) and `checkAuthoredRowWrite` (the same question as a verdict). It is open to the veto window. - Where the sharing scope is already `null` (org write depth, public objects, no owner field) the authored scope is not asked. There is nothing to widen. ## Verification Two-minute check: `pnpm --filter @objectstack/plugin-security exec vitest run --maxWorkers=2 src/predicate-write-floor-deferral.test.ts`. Expect 109 passed, including the `[objectstack-ai#37535]` describe. Read first, by risk: 1. `packages/plugins/plugin-sharing/src/sharing-plugin.ts`, the bulk branch: the new `if (writeFilter && !exec?.onBehalfOf?.userId)` hunk. 2. `packages/plugins/plugin-security/src/security-plugin-authored-row-write.ts`: `authoredRowWriteLayers` (moved head) and `getAuthoredRowWriteFilter`. 3. `packages/plugins/plugin-sharing/src/sharing-service.ts`: `probeAuthoredRowWriteFilter`. Readings, head `c2c17a47` (this branch merged with `origin/main` at `8e3980a9`; the merge touches none of this diff's sources): <details><summary>Package suites and typecheck</summary> - `pnpm --filter @objectstack/plugin-security test` at `ace203aa` (the last code commit before the merge): 290/290 files, 7330 passed, 45 skipped. At `2d086e65`, before `operator-id-write-gate-33928.test.ts` moved, 2 failed there: its two pins of the old divergence. - `pnpm --filter @objectstack/plugin-sharing test` at `2d086e65`: 78/78 files, 1754 passed, 11 skipped. Before the two middleware doubles were completed, 25 failed with `service.probeAuthoredRowWriteFilter is not a function`. - `pnpm --filter @objectstack/plugin-security typecheck`: exit 0. Before `registered-security-service-members.pin.test.ts` listed the member, 1 error, which is that pin doing its job. `pnpm --filter @objectstack/plugin-sharing typecheck`: exit 0. - `pnpm --filter @objectstack/spec build && pnpm --filter @objectstack/spec check:generated`: all 14 generated artifacts up to date. - On `c2c17a47`, focused: plugin-security 3 files / 115 tests, plugin-sharing 3 / 76, spec contract 1 / 32, dogfood `bulk-widener-probe` + `authored-row-write-scope` 2 / 17. All green. </details> <details><summary>The objectstack-ai#7274 probe readings (dogfood, real stack)</summary> - With the fix: update `declaredAdmitted` = `touched` = `n_alice_open_1, n_alice_open_2, n_bob_open`, `authoredScope: { stage: open }`, `affected: 3`. Delete: `survivors: []`, `affected: 3`. - Ablation A: update `touched` = `n_bob_open` only, and delete keeps the two Alice rows. These are the pins as they stood on main. </details> <details><summary>Derived gate families</summary> - `node scripts/pm/dispatch-gates.mjs --commands`: 119 families. All run on `c2c17a47`, and `--ran` reconciles 119 derived, 118 run, 1 NOT MEASURED, 0 unrun. - NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs --self-test` exits 3 (its positive control is pinned to a commit this shallow clone cannot reach). CI runs it on a full checkout. - Three families first read red only because the merge left stale state (a pre-merge `lint` dist; `pnpm install` not yet re-run for a dependency `service-knowledge` gained; a CLI build behind it): `check:docs-transcript-drift`, `check:i18n`, `check:type-check-debt`. Each was green after the refresh AGENTS.md § 9 orders, re-run on the same head. - Local-only `check:dev-prereqs`: exit 1, "35 of 110 workspace packages … not on disk". This worktree built only this diff's closures; it is a reading of the local tree, not of the diff. </details> Dogfood battery: not owed (no `!` in the title and no narrowing arm). `Test Core`, `Lint & Repo Gates` and the rest run in CI. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes (CI). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed (`check:generated`: all 14 up to date, nothing to regenerate). - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. --- _Generated by [Claude Code](https://claude.ai/code/session_017xRBcVFZPt78r8HPjDVLC9)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #6736 — probe only, deliberately NOT
Fixes.The fix for this path is deferred by the maintainer's 2026-08-08 ruling on #5493 (Q2 = A1), and #6736 exists precisely so that deferral cannot die inside a ruled thread (the #6216 failure mode). Auto-closing the card on merge would destroy the record this card was filed to keep. What the ruling did not defer is the card's own first acceptance step — "An end-to-end probe first (the mechanism above is a code read)". This PR is that probe, and nothing else.
What this adds
One dogfood test file,
packages/qa/dogfood/test/bulk-widener-probe.dogfood.test.ts. It pins today's behaviour, and today's behaviour is defective-by-declaration. The file says so in its own header, in those words. It is not a fix, contains no fix, and must not be read as one.The measurement
Real stack —
bootStackwith the realSecurityPlugin, the realSharingServicePluginand the real ObjectQL engine. A member holds an app-authored permission set declaring, in the author's own words, "any holder may UPDATE a note in stageopen, and DELETE a note in stagestale" — said about the row, never about its owner.update({multi})n_bob_open,n_alice_open_1,n_alice_open_2)n_bob_open)delete({multi})d_bob_stale,d_alice_stale_1,d_alice_stale_2)d_bob_stale)The claim in the card reproduces, on both verbs.
The narrowing predicate, read off the running system rather than inferred, is identical for both verbs:
deletecomposes the same way and for a documented reason, not by accident:buildWriteFilterreturns the owner-match alone for the delete verb (ADR-0111 D3 — a share widens rows, never verbs), so there is no share branch for a widener to have been OR-ed alongside either.What surfaces the discrepancy: nothing. The engine returns an affected-row count of
1, which is indistinguishable from "only one row matched the caller's predicate". The whole probe run emits zero WARN and zero ERROR lines. Contrast two nearby precedents that do speak: the by-id delete denial one block up in the same middleware logs a specific reason (ADR-0111 D10), and #6783 addedSYSTEM_WRITE_SKIP_NOTICEfor exactly the "configured but inert stops being silent" shape. This branch has neither.Why the fixture is a
public_readobjectDeliberate, and load-bearing.
buildReadFilterreturnsnullfor any non-privatemodel, so reads are open and cannot confound the measurement — on aprivateobject the cross-owner rows would be invisible to the caller and a bulk write that touched nothing would be explained by read scoping rather than by the write composition, which is the wrong thing to measure. MeanwhilebuildWriteFilterreturns the owner-match forprivateandreadalike (only a fullypublicobject is write-open). So on this object the sharing write filter is the only narrowing agent: the composition under test, isolated.Discrimination controls — why the headline number means anything
"1 out of 3" proves nothing on its own. An inert widener (never parsed, never applicable) and a fixture that accidentally granted ownership would each produce a confident-looking number. Two controls split those apart, and both hold:
sharing.checkEditanswersdeny,security.checkAuthoredRowWriteanswersadmit, the PATCH returns 2xx and the row really changes. An inert declaration would 403 here.FORBIDDEN/PERMISSION_DENIED), not as a bare throw. A fixture that leaked ownership, or a disabled gate, would let this through.Plus an explicit integrity case asserting the resolved principal, that the app-authored set actually reached the execution context, that the run is not
isSystem, and that the caller owns exactly one row of each fixture.Reverse verification — direction predicted in writing BEFORE the run
Manipulation: neutralise
composeAnd(ast.where, writeFilter)in the bulk branch only; revert immediately. Predicted, before running: the two MEASURE cases go red (touched 1 to 3; survivors 2 to 0), and the three other cases — integrity, C1, C2 — stay green, because the by-id path never enters that branch. Recorded reasoning: if C1 or C2 also moved, the probe would not be isolating the bulk branch and the headline count would not be attributable to it.Measured: exactly that.
2 failed | 3 passed, the two failures being the two MEASURE cases, withaffected1 to 3 on both verbs andsurvivors2 to 0.No delta to report honestly: the prediction and the measurement agree case for case.
Scope — what this PR deliberately does NOT do
Per the ruling and the dispatch: no filter-shaped authored-only write
FilterCondition, no second composition site, no change tobuildWriteFilter's composition, and no extension ofcheckAuthoredRowWrite(a per-row verdict has no seat in AST composition, which is exactly why the by-id surface cannot reach this path). Zero production files change;git diff origin/mainoverpackages/andexamples/is empty apart from the new test.Gates
pnpm --filter @objectstack/dogfood exec vitest run test/bulk-widener-probe.dogfood.test.ts— 5 passedpnpm --filter @objectstack/dogfood typecheck— cleaneslint packages/qa/dogfood/test/bulk-widener-probe.dogfood.test.ts --no-inline-config— cleancheck:nul-bytes,check:verify-stand-in,check:engine-double-contract,check:error-code-casing,check:route-envelope,check:query-options-erasure,check:authz-resolver— all greenNo changeset: test-only, releases nothing (
skip-changeset).Generated by Claude Code