Skip to content

fix(plugin-security): a write's tenant options never reach past the caller's organization wall - #39779

Draft
objectstack-fleet[bot] wants to merge 6 commits into
mainfrom
claude/sec-write-tenant-options
Draft

objectstack-fleet[bot] wants to merge 6 commits into
mainfrom
claude/sec-write-tenant-options

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Security-fix: seat-dispatched
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no skill or doc teaches setting a write's tenant options; the rule binds the security layer's write door

维护者速读

  • 用户无感:普通用户在多组织隔离部署下做新增、修改、删除时,写入只会落在自己能写的组织里;正常操作没有任何变化。
  • 替平台安全负责人收口一条组织隔离加固规则,由安全席位派发。
  • 若某个自定义自动化把写入指向调用者组织之外,该次写入会被拒绝并提示无权限,不写入任何数据;可直接撤回本改动恢复原行为。
  • 无

What changes

A write's tenant options never reach past the caller's organization wall (ADR-0095 D1).

  • The security plugin's plain door now installs, on every non-system write it admits (insert, update, delete, purge), the bound the engine asks where it builds a driver's options (OperationContext.driverTenantScopeCheck). The app-automation elevation's wall keeps its own, and a plain-door bound composes after any bound another layer installed.
  • The bound is the caller's own Layer 0 verdict for the operation: the verdict the middleware recorded for a predicate write, else the caller's Layer 0 worked out over the permission sets the door already resolved, intersected with the delegator's for an on-behalf-of write.
  • Keys inside the wall pass. A key naming an organization outside it, or clearing the scope, refuses the whole write with 403 PERMISSION_DENIED before any driver runs: refused, never narrowed.
  • Unchanged: system contexts, a platform operator on a posture-permitting object, objects outside the tenancy machinery, the single posture, the public-form grant door, and every write that sets no tenant option.
  • @objectstack/objectql: the driverTenantScopeCheck docblock names the second installer. Text only.

Files to read first, by risk:

  1. packages/plugins/plugin-security/src/write-option-tenant-keys-wall.ts — the judge (what counts as outside the wall or a cleared scope) and where the verdict comes from.
  2. packages/plugins/plugin-security/src/security-plugin-authz-middleware.ts — the one hunk before the final next(): which operations get the bound and with which principals.
  3. packages/plugins/plugin-security/src/write-option-tenant-keys-wall.test.ts — the refusal cells and the controls.

Tests

New pins, real stack (head dfe2a17)

write-option-tenant-keys-wall.test.ts: a real ObjectQL engine on driver-sql and driver-sqlite-wasm, the real SecurityPlugin, two organizations, the option bag set by a before* hook. 26 cells per run (13 per driver family).

  • Refusal cells (8 per driver): insert, insert whose payload names the caller's own organization, insert clearing the scope, by-id update, predicate update, by-id delete, predicate delete, group posture outside the membership set. Each asserts PERMISSION_DENIED / 403 and the table unchanged.
  • Controls (5 per driver): options inside the wall admitted on every verb; no option unchanged; platform operator on a private object, system context and single posture unaffected.
  • Green on the fix: 26 passed. With the installer ablated (node scripts/ablation-replace.mjs, anchor hit 1 to 0, restored blob equal to HEAD, git diff HEAD empty): 16 failed, 10 passed. All 16 refusal cells red, all 10 controls green both ways.
  • Pins, the elevation wall suite and the stored-row wall suite on the final head: 3 files, 124 passed.
Affected package suites
  • pnpm --filter @objectstack/plugin-security exec vitest run --maxWorkers=2: 295 files passed, 7489 passed, 52 skipped.
  • pnpm --filter @objectstack/plugin-security typecheck and pnpm --filter @objectstack/objectql typecheck: exit 0.

Acceptance notes

  • The public-form grant door (anonymous form submission) is left as it was: its context has no organization of its own, and binding it is a separate decision.
  • A denied caller's delete whose options reach past the wall is refused here, where the elevation wall answers the same shape by narrowing. Recorded as a boundary, not changed in this PR.

Verification

Derived gate families (dispatch-gates --commands, 80 families)
  • 76 run locally, reconciled with --ran: 0 UNRUN.
  • node scripts/ci/snapshot-next.mjs --self-test exited 1 on this tree. The diff does not touch scripts/ci/, so this self-test reads the same files as on main. CI reads it.
  • NOT MEASURED, family check:dual-build-cjs-loads and check:i18n, reason: PREREQUISITE NOT MET (the whole workspace dist/ is not built in this worktree). CI runs both.
  • NOT MEASURED, family check:query-options-erasure and check:type-check-debt, reason: did not finish inside the local time box on the shared container (exit 124). CI runs both in Lint & Repo Gates.
  • node scripts/check-nul-bytes.mjs: OK.

Two-minute check: pnpm --filter @objectstack/plugin-security exec vitest run --maxWorkers=2 src/write-option-tenant-keys-wall.test.ts should print Tests 26 passed (26).


Generated by Claude Code

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

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

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

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

  • content/docs/api/data-flow.mdx (via OperationContext (symbol, a top-level interface))
  • content/docs/kernel/contracts/data-engine.mdx (via buildDriverOptions (symbol, a top-level function))
  • content/docs/permissions/system-context.mdx (via OperationContext (symbol, a top-level interface), buildDriverOptions (symbol, a top-level function), registerAuthzMiddleware (symbol, a top-level function))
  • content/docs/permissions/tenant-audit-census.mdx (via buildDriverOptions (symbol, a top-level function))
What this run could not see
  • 4 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 71 of 255 client-bound route-ledger rows — the other 184 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 184: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 60 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 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 — 32 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 124f1e08239109e040006d7deec81125b32c33ed → packageMentionDocs.

Which tree this was computed on

This run read content/docs from cc768e685ecdbb17286c8d74e49345989986034b — the merge of head 66053aed84bd68b999a8603fbc304be08c695e18 into base 124f1e08239109e040006d7deec81125b32c33ed, 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 cc768e685ecdbb17286c8d74e49345989986034b && git checkout cc768e685ecdbb17286c8d74e49345989986034b
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 124f1e08239109e040006d7deec81125b32c33ed 66053aed84bd68b999a8603fbc304be08c695e18 && git checkout -B drift-repro 124f1e08239109e040006d7deec81125b32c33ed && git merge --no-ff 66053aed84bd68b999a8603fbc304be08c695e18

node scripts/docs-audit/affected-docs.mjs --json 124f1e08239109e040006d7deec81125b32c33ed

⚠️ 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 124f1e08239109e040006d7deec81125b32c33ed → 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

security@os-mickey · os-mickey · session_01ASNY8XNef4ywkQio6S9ju4

Label · 2026-12-05T02:16Z. needs:dogfood-battery: the PR body declares Clause-②: no (narrowing), so the opt-in dogfood battery is owed on the head before the queue. L2 contract review is in progress at CONTRACT_REVIEW_TIER.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security@os-mickey · os-mickey · session_01ASNY8XNef4ywkQio6S9ju4

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: dfe2a17ee1a987ace5820be54341791c43d4992a
Local-runs: probe — the seat's brief asked for the pin file run, a re-ablation and stack probes of the stated bound
Scope: packages/objectql/src/engine-top-level.ts, packages/plugins/plugin-security/src/security-plugin-authz-middleware.ts, packages/plugins/plugin-security/src/write-option-tenant-keys-wall.ts, packages/plugins/plugin-security/src/write-option-tenant-keys-wall.test.ts, .changeset/write-tenant-options-wall.md + packages/objectql/src/engine-driver-options.ts, packages/objectql/src/engine-insert.ts, packages/objectql/src/engine-update.ts, packages/objectql/src/engine-delete-and-aggregate.ts, packages/objectql/src/recycle-bin/purge.ts, packages/objectql/src/recycle-bin/restore.ts, packages/plugins/plugin-security/src/app-automation-organization-wall.ts, packages/plugins/plugin-security/src/security-plugin-rls-filter.ts, packages/plugins/plugin-security/src/security-plugin-operation-principals.ts

① Derived judgments

  • Face: narrowing, declared line-initial on the PR body and the changeset; every diff path outside the prose faces is in scope.
  • Coverage: every engine site that builds a driver bag from a write's option bag passes the operation's bound (insert, its prior-row read, three update sites, five delete and purge sites). Sites that pass no bag carry no caller key. The recycle bin's entry verbs and restore hand no bag.
  • Ordering: the bound is installed by the middleware before the chain continues and is asked where the engine builds the driver's options, after the before-hooks.
  • Reach: the bound sits on the operation, which no hook context exposes. Only declared driver option keys reach a driver, and two of them carry tenant scope; both are judged.
  • Pins: 26 of 26 green at this head. With the installer ablated: 16 red, 10 green, restored, git diff HEAD empty. The refusal cells run the real engine, two SQL driver families and the real security plugin.
  • Two further ablations stayed green: the on-behalf-of limb of the verdict (3 files, 174 passed) and the purge verb (26 passed). Neither is pinned.

② Semver level

patch on both packages is the level AGENTS.md gives a non-protocol narrowing. The BREAKING banner, the one-line fix and the ADR-0087 marker are present; Metadata-protocol: none is right.

③ Boundary flags

  • Public-form grant door left as it was: accepted as a boundary; the door's context carries no organization to bind against.
  • A denied caller's removal is refused at this door where the elevation wall answers by the read rule: accepted deviation, recorded for the maintainer. The refusal does not depend on any row.
  • SQL push-down: no new id materialisation and no in-app join.
  • Merge by squash: the branch's first commit carries pre-reword wording; the head tree is rule-level.

④ Design judgment

The narrowing makes the spec's own refusal real at the plain door and takes no declared capability away.

  • must-fix 1: the changeset, the PR body and the driverTenantScopeCheck docblock state the bound for an on-behalf-of write as the intersection with the delegator's wall. The reviewed head does not hold that statement on every write shape, and no pin covers the on-behalf-of limb. Close it by making the statement hold and pinning it on the real stack, or by stating only what holds; a change to what the engine asks of the bound is the maintainer's call.
  • should-fix 2: pin the purge verb; the rule names it and its removal stays green.
  • should-fix 3: the driverTenantScopeCheck docblock says more than the code does. State the cases where no bound is installed and keep the refusal sentence to the plain door.
  • should-fix 4: pin a replaced bag and a denied caller, and align the acceptance note on denied callers with what the head answers.
  • nit: the refusal leaves no gate-refusal log line; composition after a prior layer's bound is unpinned.

Implemented-by: claude/sec-write-tenant-options
Reviewed-by: session_01ASNY8XNef4ywkQio6S9ju4

VERDICT: FAIL

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security@os-mickey · os-mickey · session_01ASNY8XNef4ywkQio6S9ju4

Handover · 2026-12-05T13:10Z. This draft moves to the seat security@sunhaolin (mailbox #39815), on the maintainer's word in this session (verbatim 「A 收窄 ,也交给 sunhaolin 座位继续」).

  • Ruling: the open must-fix on record 7430375734 is resolved by the narrowed option. On the insert's landing only, the explicit organization keys are judged against the caller's bound, and only for the plain write door. Update, delete, purge and the elevation path keep today's behaviour. A decision analysis at CONTRACT_REVIEW_TIER measured no regression for this option.
  • Owed next:
    • a patch round on this branch, carrying the ruling and the record's open should-fix items;
    • a delta review at CONTRACT_REVIEW_TIER;
    • the seat record;
    • the maintainer hand-off. This PR declares a narrowing.
  • The original dev agent does not carry over; the receiving seat dispatches its own.

…r's organization wall, whoever set its tenant options

On an insert's landing, the plain write door's bound is asked about every
explicit tenant key the option bag carries; for an on-behalf-of insert that
bound is the caller's wall intersected with the delegator's. Updates,
deletes, purges, reads and the app-automation elevation are unchanged.

Pins on the real stack: the on-behalf-of insert (single and array, hook-set
and in-process), an exempt operator acting for a walled delegator, a purge,
a replaced bag and a denied caller, with their controls.

Claude-Session: https://claude.ai/code/session_017xRBcV4xBHWbZEmo3HuvyX
Co-authored-by: Claude <noreply@anthropic.com>
… are held to the caller's organization wall

The bound's docblocks, the changeset and the system-context table say what
holds: an insert's every tenant key is held to the caller's wall, an
on-behalf-of insert's to the delegator's memberships too; other writes are
held where a key asks beyond the caller's own organizations; and where no
bound is installed.

Claude-Session: https://claude.ai/code/session_017xRBcV4xBHWbZEmo3HuvyX
Co-authored-by: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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 needs:dogfood-battery 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

Development

Successfully merging this pull request may close these issues.

1 participant