fix(plugin-security): #2937 — Layer 0 insert post-image 租户检查#2940
Merged
Conversation
多组织模式下用户 insert 可伪造 organization_id 越租户墙 (ADR-0095 D1 读侧 W1 的写侧未竟部分)。Layer 0 的租户墙作用于读 + update/delete 的 pre-image, 但 insert 无 pre-image 且不带 AST,从未被门控。 新增中间件步骤 3.7:对 insert 的 post-image 复用读侧同一套 Layer 0 决策 (computeInsertTenantCheckFilter → computeLayeredRlsFilter 的 layer0)校验 —— 显式提供的 organization_id 必须等于调用者活动组织,否则 fail-closed 拒绝。 缺省值不受影响(由 @objectstack/organizations auto-stamp 补全,故与其注册顺序 无关);isSystem 上下文中间件入口短路,合法代客设 org_id(import/迁移/seed replay)完全不受影响。matrix gate + 授权一致性 ledger 覆盖。 Closes #2937 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019QRUvVfpvSycAHMMF2xTxs
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 2 package(s): 12 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
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.
背景
Closes #2937(安全修复 + 行为变更)。多组织模式(tenancy.mode='multi'+@objectstack/organizations)下,一个普通用户此前可以insert一条伪造organization_id(指向别的租户)的业务记录并使其落进受害租户。ADR-0095 D1 的 Layer 0 租户墙 AND-composed 到读 + update/delete 的 pre-image,但 insert 没有 pre-image、也不带 AST,从未被门控(是 D1 读侧 W1 的写侧未竟部分)。配套 cloud PR:objectstack-ai/cloud#829(auto-stamp 权威覆盖,纵深防御)。两处任一被绕过,另一处仍堵住跨租户落地。
改动
security-plugin.ts新增中间件步骤 3.7:对 insert 的 post-image 复用读侧同一套 Layer 0 决策(computeInsertTenantCheckFilter→computeLayeredRlsFilter的layer0)做校验 —— 一个显式提供的organization_id必须等于调用者的活动组织,否则 fail-closed 拒绝(PermissionDeniedError)。organization_id列或tenancy.enabled:false)、platform-admin 姿态豁免的对象 → 不适用;无活动组织的用户提供任意 org_id → 拒(deny sentinel)。organization_id)的 insert 由@objectstack/organizations的 auto-stamp 补全 —— 职责分离,因此本检查与 auto-stamp 中间件的注册顺序无关。authz-matrix-gate.test.ts:新增describe('[#2937] Layer 0 insert post-image tenant guard')八格。authz-conformance.matrix.ts:新增multi-tenant-insert-postimageledger 行(单元证明;多组织为企业版,不进 open-core dogfood boot)。行为 delta(release-notes callout)
此前能成功的「带跨租户
organization_id的用户级 insert」现被拒绝。缺省 insert、system-context 写、platform-admin 豁免对象、单组织模式 均不受影响。验证(实测)
pnpm --filter @objectstack/plugin-security test→ 391 passed(18 files),含新增 8 格 insert 测试。authz-conformance.test.ts(ledger)→ 1 passed。tsc --noEmit(plugin-security)→ clean。rls-multitenant.dogfood.test.ts→ skipped(企业版@objectstack/organizations才激活多组织路径 —— 与 issue 说明一致,故以 unit 矩阵门覆盖)。Reviewer checklist(重点:合法代客设 org_id 不受影响)
isSystem在security-plugin.ts中间件入口(L513)即return next(),本检查不触及。已确认 cloud 的每-org seed replay /clone-org-seed-data.ts/claim-orphan-org-rows.ts全部走SYSTEM_CTX = { isSystem: true },它们故意为新 org 设置 explicit(跨 org)organization_id—— 这些合法写路径保持原样。suppliedOrg != null && suppliedOrg !== ''门控,缺省值放行(矩阵门member inserting with NO organization_id passes the wall)。🤖 Generated with Claude Code
https://claude.ai/code/session_019QRUvVfpvSycAHMMF2xTxs