Repository navigation
fix(plugin-security): under group, a no-active-organization insert gets the ADR-0123 D2 403, not a 500 - #24819
Conversation
…rganization insert Reads red on the base: group answers ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED/500 where isolated answers PERMISSION_DENIED/403 for the same context. Claude-Session: https://claude.ai/code/session_011TdZ8GjixNZFLz1xJD9zzK Co-authored-by: Claude <noreply@anthropic.com>
…n gets the ADR-0123 D2 403 Under group, a member whose session has no active organization passed the Layer 0 scope pre-test (it reads the membership set) and the engine then refused the row as an organization-less system write with a 500. The wall now refuses that insert on its stored image with the same answer isolated gives. Claude-Session: https://claude.ai/code/session_011TdZ8GjixNZFLz1xJD9zzK Co-authored-by: Claude <noreply@anthropic.com>
…oup-no-active-org-write-403
…oup-no-active-org-write-403
📓 Docs Drift CheckThis PR changes 1 package(s): 4 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 15 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 3fd0e664c69869edfd7c4eecf9e54e4ca8b99ee0 && git checkout 3fd0e664c69869edfd7c4eecf9e54e4ca8b99ee0
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin c56115bf962cb301fb046c54680620d37e5ab2fb 94f661fbeab27684553f418c182d46fb8e700dcd && git checkout -B drift-repro c56115bf962cb301fb046c54680620d37e5ab2fb && git merge --no-ff 94f661fbeab27684553f418c182d46fb8e700dcd
node scripts/docs-audit/affected-docs.mjs --json c56115bf962cb301fb046c54680620d37e5ab2fb
|
席位核对 · ACCEPT ·
|
…s — the union-scope insert and the crossing operator's ADR-0123 D2's scope paragraph and its "What does not change" line were narrower than the runtime after PR #24819 (8a058d8) and PR #24868 (98c3d00). A dated amendment in the status block names both arms and their reasons (ADR-0105 D5; ADR-0095 D3 with ADR-0131 D9); the scope paragraph keeps its text with a dated pointer, and the "Platform operators" entry is struck and corrected in place. Claude-Session: https://claude.ai/code/session_01M82feuetLzrCiBz41BJb7L Co-authored-by: Claude <noreply@anthropic.com>
…R-0131 D7/D9 (objectstack-ai#32126) <!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBNXUbHBekZQ6WxHpNfGu7wV)_ Fixes objectstack-ai#32111 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么:** 只改测试清单一个条目 `access-security.no-active-org-session-semantics`(r9 → r10):审计条款 acceptance[4]/[6] 改为按 ADR-0131 D7/D9 判定(审计日志不归租户墙管,按对象权限读),去掉过时的 `blocked` 标记和两条已过期的 knownGaps。 - **为什么改:** QA 运行 objectstack-ai#32102 在隔离/分组两种墙下实测:清空当前组织的成员登出,审计行 `tenant_id` 为空;平台管理员能读到(200),成员本人 403(对象权限)。旧条款要求「审计行不能没有租户、否则 RLS 读不到」,写于审计日志还在墙内时(objectstack-ai#8245),D7 之后已不成立,所以判 FAIL 是规格过期,不是产品缺陷。 - **风险与回滚:** 纯文档(`docs/qa/**`),无产品代码、无 changeset(`skip-changeset`)。回滚 = revert。 - **先看:** acceptance[4] 新条款 + verify(谁必须能读、谁应被拒),以及 knownGaps[3] 新增的「生产者 (2)」段。 - **两分钟验证:** `node scripts/check-platform-checklist.mjs` exit 0;`node scripts/checklist-select.mjs access-security.no-active-org-session-semantics --json` 不再需要 `--include-blocked`。 - **需要你做的:** 回答文末「Question for the maintainer」(清空当前组织的成员登出,审计行是否必须带组织归属?)。本 PR 不回答它,只把它带上来;席位审阅落地。 ## What changes One item in `docs/qa/platform-checklist/areas/access-security.json`, `access-security.no-active-org-session-semantics`, revision 9 → 10, with a `history` entry (ref objectstack-ai#32111) citing QA run objectstack-ai#32102 (subject `ff04ad81`, repro rule R-1). No other file: no `knownGaps[n]` cross-reference in this file, `RUNNER.md` or `FOLLOW-UPS.md` names the dropped lines (`git grep -n "knownGaps\[" -- docs/qa`; only this item's own `history` rows mention its `[4]`/`[5]`, and history is append-only). ### Re-points, before → after | Where | Before | After | |---|---|---| | `acceptance[4].clause` | "the audit carve-out is paid for by ORDERING, not by an exemption: audit rows from a first session carry a real tenant — no audit row is NULL-tenanted and therefore permanently invisible to RLS readers (objectstack-ai#8245)" | The ledger is read through object permission, not the wall (ADR-0131 D7): the session's login/logout rows exist in `sys_audit_log` (`systemFields: { tenant: false }`), whose `tenant_id` is an attribution field with its NULL arm kept by design (D7's 2026-10-22 note) and outside D9's no-NULL rule. The platform operator reads every such row, a NULL-attributed one included; the user is refused 403 by object permission. The attribution question is open (knownGaps[3]) and not scored. | | `acceptance[4].verify` | "read … as a tenant-scoped reader; they must be visible. A row present in the raw table but invisible to every RLS reader is a FAIL" | As the operator, `GET /api/v1/data/sys_audit_log` filtered by user_id → 200 with every row, `tenant_id` quoted; a raw row the operator's read omits is a FAIL. As the user, the same read → 403 (a 5xx, or another user's rows, is a FAIL). A NULL `tenant_id` alone is not a FAIL: record it with its producer and knownGaps[3]. | | `acceptance[4].evidence` | "raw rows + the RLS-scoped read of the same rows" | "raw rows with tenant_id + the operator's read of the same rows + the user's 403 envelope" | | `acceptance[6]` clause + verify | three subsystems give the same answer; any disagreement is the finding | Unchanged, plus: under D7 the ledger's answer is acceptance[4]'s (written, read through object permission); a NULL `tenant_id` there is attribution, not a tenant column, so it is not a disagreement with the wall's refusal. A lost ledger row, or one the operator's read omits, still is. | | `fixtures.knownGaps[3]` | open question for producer (1) only (a member-less user) | The same question for both producers. Producer (2), a member that cleared its active organization: objectstack-ai#32102's rows (login A, login A, logout with `tenant_id` NULL, login A), operator 200, member 403, and the mechanism (`auth-session-audit.ts#logoutEventFor` takes the session's `activeOrganizationId`; `auth-event-audit.ts` writes `tenant_id` from the event, null when absent). It also says what a "must be attributed" answer would make of it. | | `blocked` | `{ by: "fixture", ref: "objectstack-ai#9334" }` | Dropped. objectstack-ai#32102 booted the stock showcase walled from the tree (`OS_TENANCY_POSTURE`, `OS_PLATFORM_OWNER_EMAIL`, `OS_AUTH_MEMBERSHIP_POLICY`) on group and isolated and served every leg, which is RUNNER.md "A walled boot is a fixture of its own". Its run resolved the item with `--include-blocked` only because of this marker. | | `fixtures.knownGaps[2]`, last sentence | "(no example app declares it) … The item stays blocked (fixture, objectstack-ai#9334) because … the stock showcase provisions no walled boot" | "(examples/app-showcase declares it)" and: the walled boot runs from the tree, objectstack-ai#32102 served every leg, so the item carries no blocked marker; a run that does not provision the walled boot records each walled leg blocked(fixture). | | `fixtures.knownGaps[4]`, `[5]` | objectstack-ai#24784 open: `group` producer (2) create → 500; acceptance[7] red until it lands, "when objectstack-ai#24784's fix merges, re-run the clause and drop this line" | Dropped. objectstack-ai#24784 closed (PR objectstack-ai#24819) and objectstack-ai#32102 measured it holding live on a walled group boot (acceptance[7] pass; the acceptance[1] 403, not the 500). `[0]`–`[3]` keep their indexes. | ## Why QA run objectstack-ai#32102 scored acceptance[4] and [6] FAIL. Under checklist-test §5 that is a stale spec: the product follows ADR-0131 D7 (`sys_audit_log` is "governed by object permission, not by the wall"; its `tenant_id` "is not a tenant column", NULL arm kept by design), and the clause pins the shape from objectstack-ai#8245, when the ledger was walled. D9 scopes the no-NULL rule to tenant-column objects ("column ⇒ in scope"). Rule 7 of the run had a second agent re-derive the verdict from the evidence; it agreed. The other four edits are the run's own checklist-accuracy note A-1 and the re-runs that knownGaps[4]/[5] asked for. ## Question for the maintainer Should a logout by an organization member who cleared its active organization carry organization attribution? - **If yes ("must be attributed"):** this becomes a product defect in plugin-auth `auth-session-audit.ts` `logoutEventFor`, which takes the session's `activeOrganizationId` (null in this state). knownGaps[3] says so, and acceptance[4] would then gain the attribution as a scored fact. - **If no:** knownGaps[3]'s question closes for producer (2) and acceptance[4] stands as re-pointed here. The same question has been open for producer (1), a member-less user, since QA run objectstack-ai#24783 (finding F3). This PR answers neither. It carries both in `fixtures.knownGaps[3]`, and it changes no product code (`plugin-auth/**` and `plugin-audit/**` untouched). ## Verification - `node scripts/check-platform-checklist.mjs` → exit 0 (16 areas, 361 items; symbol anchors resolve, including `auth-session-audit.ts#logoutEventFor`). - `node scripts/pm/dispatch-gates.mjs --commands`: 16 families derived; each run, each exit 0 (`check:doc-formula-expressions` first exited 3, since it reads built output, then exit 0 after building `@objectstack/formula` and `@objectstack/lint`). `dispatch-gates --ran` → 16 derived, 16 run, 0 NOT-MEASURED, 0 UNRUN. - No live run is owed: the run record objectstack-ai#32102 is the evidence. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (n/a, not touched) - [x] 2. Every name I added uses the casing for its kind. (no names added) - [ ] 3. No formatter ran; `pnpm lint` passes. (no formatter ran, the item was edited in place; `pnpm lint` was not run locally, CI judges it) - [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. (publishes nothing: `skip-changeset`) - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (n/a) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [ ] 8. Title, body and comments are in English. (the 维护者速读 section is in Chinese, as the seat's order asks) - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WGufzgHeKXV549vk5BBEj9 Co-authored-by: Claude <noreply@anthropic.com>
Fixes #24784
Clause-②: no
What changed
On the
grouptenancy posture (any union-scope posture), a member whose session has no active organization sent a create on a tenant-scoped object. The Layer 0 write wall inplugin-securitylet it through: its scope pre-test (callerHasOrganizationScope) reads the membership set under a union-scope posture, and a member's set is not empty. But a new row lands in the active organization (ADR-0105 D5), and there was none. So the engine met the row as an organization-less system write and refused it with500 ERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED. Nothing was written.The wall now refuses that insert itself, with the ADR-0123 D2 answer
isolatedalready gave the same session:403 PERMISSION_DENIED, "[Security] Access denied: 'OBJECT' is scoped to an organization, and this session has no active organization — so this insert has no organization to place the record in. Join or select an active organization and retry."packages/plugins/plugin-security/src/security-plugin.ts, the step 3.7 write wall:carriesActiveOrganization(context)is new, besidecallerHasOrganizationScope. The non-union branch ofcallerHasOrganizationScopenow calls it, with the same answer as before.refuseNoActiveOrganization. The scope pre-test throws it as before, with the same message, details and operator text. The new arm throws it too, with its own operator text, which says what the context does and does not carry under this posture.insert, under a union-scope posture, when the caller's own Layer 0 applies to the object and the context carries notenantId. It judges the stored image, in the post-hook seam the engine already runs (postHookWriteImageCheck). That is the row after thebeforeInsertchain, the same rows the engine's own organization check (resolveSystemInsertOrganization) reads one step later. It runs first in that seam, so the session's state is the reason reported.canWriteObjectdoc names the new arm among the post-image refusals it does not judge.no-active-organization-write-refusal.test.ts: the control "a NON-EMPTY membership set lands, even with no active organization" pinned exactly the branch this card changes. Its terminal stands in for the engine, so it never met the 500. It is replaced by the refusal case and its single-fact control: the same set with an active organization lands.no-active-organization-insert-union-scope.test.tsis new. It runs on the real stack: ObjectQL, SqlDriver and SecurityPlugin, booted the waytenant-wall-post-hook-image.test.tsboots them.Why the stored image, and not
organizationWallRefusalI measured the base before choosing. Under
grouptoday, an insert whose own appbeforeInserthook places the row in an organization the membership wall admits is admitted, whileisolatedrefuses it ahead of the hooks. A row-less change to the predicate inorganizationWallRefusalwould refuse it too. That turns a 2xx into a 403, which is outside "the change turns a 500 into the designed 403". The stored image asks exactly the engine's question, so every answer this PR changes was a 500 before.The cost:
canWriteObjectis asked about no row. It keeps answeringtruefor this caller's create preview, as it did before. Its doc already lists post-image refusals as outside its answer, and now names this arm there.Readings: real stack, in process
A member of
org_aandorg_c, no active organization, on a public tenant object. Basea43405d596, fixcca0ba958a:groupbeforegroupafterisolatedbefore and afterERR_SYSTEM_WRITE_ORGANIZATION_REQUIREDPERMISSION_DENIEDPERMISSION_DENIEDorg_aorg_aThe engine's static read-only strip drops a session payload's
organization_idon insert. So a payload value never decides where a session's new row lands, before or after this change.Which verbs ADR-0123 D2 and the checklist item cover
access-security.no-active-org-session-semantics: acceptance[1] and step 3 test a create, and acceptance[5], acceptance[6] and negative[3] require no 500 anywhere. Covered for insert, single and bulk.groupit states the scope as the membership set. A no-active-org member's update of a row that set admits answers 200 before and after, and the row keeps its own organization. Nothing has nowhere to land, so it is not changed.Tests (head
94f661fbea, the merge oforigin/main307ce4c4b4)a43405d596, before the fix: 4 failed, 2 passed.groupansweredERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED/ 500 whereisolatedansweredPERMISSION_DENIED/ 403. The fourth failure was the active-org control's sort order in the test itself, fixed before the fix commit.pnpm --filter @objectstack/plugin-security test: 193 files passed, 4013 passed, 45 skipped.pnpm --filter @objectstack/plugin-security typecheck: exit 0, andcheck:test-typecheckis OK.tsc -p tsconfig.test.json --listFileslists both test files among the package's test files.&&-joined command under the verify lock, after the closure build (turbo,--filter='@objectstack/plugin-security...', 19/19 tasks). The lock printedVERDICT command-exit 0.Ablation, on the committed fix, run on
cca0ba958aand again on94f661fbea.node scripts/ablation-replace.mjsreplaced the arm's last conjunct with a constant false, which puts the old predicate back:0f12f626to4c7f7ebfon the final head).groupcase receivedERR_SYSTEM_WRITE_ORGANIZATION_REQUIRED, the equality-with-isolatedcase failed, and the unit case was not refused. Every control stayed green.git checkout HEAD -- PATH: the blob equals HEAD's, andgit diff HEADandgit statusare empty.Gates (local, head
94f661fbea)node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack, with no paths, derived 69 commands for this diff. All 69 exited 0, and each exit was captured before any pipe.--ranover that record answered "69 derived, 69 run, 0 NOT-MEASURED, 0 UNRUN" and exited 0.check:i18nandcheck:dual-build-cjs-loadsfirst answered exit 3 (PREREQUISITE NOT MET, nothing measured) on an earlier head. Both measured green once the builds they name existed.pnpm lintfirst),test:repo, Test Core, Build Core and the Type Check lanes. The main-only battery (dogfood, Temporal Conformance) runs after merge. This PR's check-runs decide them.origin/mainwas 6 commits past this head's merge base when it last ran. The queue rebuilds on currentmain.Acceptance notes
group, 'no organization scope' means an empty membership set". That sentence now describes the scope pre-test only. A union-scope insert with no active organization is also refused, with the same answer. This is the card's ruled answer (triage record 6285293541). An ADR addendum or status-line amendment is a governed docs change, not part of this PR.500 ERR_SYSTEM_WRITE_ORGANIZATION_REQUIREDunder bothgroupandisolated. This is an in-process reading only, not measured at the HTTP door. The card's second candidate, the engine mapping a non-system caller to a 4xx, would cover it.group, a member with active organizationorg_awhose payload namesorg_cfrom the same set gets a 2xx, and the row is stored inorg_a. The payload value is dropped by the engine's read-only strip, not refused. The organizations runtime's stamping comment says a supplied value is admitted or refused, never rewritten.packages/objectql/src/engine.tsstill says, at the insert post-image seam, that the Layer 0 tenant wall judges only the pre-hook image. That has been stale since the wall gained its stored-image judgement. It is out of bounds for this PR.organization_idrows from framework writers and remains open. This PR changes none of them.Generated by Claude Code