Skip to content

fix(organization): fail closed on unresolved org in ORGANIZATION_SETTINGS_UPDATE - #5104

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/settings-update-unscoped-org-guard-w2
Jul 23, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/settings-update-unscoped-org-guard-w2

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

Source: bug found while auditing apps/mesh/src/tools/organization for auth-scoping issues (core services / tier-resolution focus area).

Why a maintainer wants this: the cross-org guard in ORGANIZATION_SETTINGS_UPDATE was if (ctx.organization && ctx.organization.id !== input.organizationId) throw. That only rejects a mismatch when ctx.organization is already resolved. Every sibling org-scoped write tool (e.g. member-add.ts's if (organizationId !== ctx.organization?.id), settings-get.ts deriving the id itself) either checks unconditionally or never trusts client input for the org id — this tool was the one outlier.

Failure scenario: if ctx.organization ends up unresolved on a request that still passes ctx.access.check() (e.g. an org-id/slug hint mismatch upstream in context-factory.ts, which explicitly leaves ctx.organization undefined to "fail closed" for other tools), the guard here is skipped entirely and the handler upserts organization settings straight into whatever input.organizationId the client supplied, with zero validation that the caller belongs to that org.

Fix: replaced the conditional guard with requireOrganization(ctx) (throws "requires organization scope" when unresolved) followed by an unconditional equality check against input.organizationId — matching the pattern already used elsewhere in this file's sibling tools.

Regression test: settings-update.test.ts (new file) — asserts (1) a mismatched organizationId is rejected, (2) when ctx.organization is undefined the handler throws "organization scope" and never calls storage.organizationSettings.upsert, and (3) a matching id still succeeds.

To verify: bun test apps/mesh/src/tools/organization/settings-update.test.ts

Checks run locally: bun run fmt, cd apps/mesh && bunx tsc --noEmit (clean), and the targeted test file above (3 pass). Full CI validates the rest.


Summary by cubic

Fixes an auth-scoping bug in ORGANIZATION_SETTINGS_UPDATE by requiring a resolved organization and rejecting mismatched organizationId. This blocks unscoped updates when ctx.organization is undefined and adds tests to prevent regressions.

  • Bug Fixes
    • Use requireOrganization(ctx) and compare organization.id to input.organizationId.
    • Fail closed when no org is resolved; throw on cross-org mismatch.
    • Add settings-update.test.ts covering mismatch, unresolved context (no write), and success.

Written for commit 958ec0a. Summary will update on new commits.

Review in cubic

…INGS_UPDATE

The cross-org guard `if (ctx.organization && ctx.organization.id !== input.organizationId)`
only fired when ctx.organization was resolved. When it wasn't (e.g. a
membership/header mismatch upstream leaves ctx.organization undefined), the
whole condition was false and the client-supplied input.organizationId was
used to write settings with no validation at all. Every sibling tool
(member-add.ts, settings-get.ts) either checks unconditionally or derives the
org id itself instead of trusting client input.

Fix: use requireOrganization(ctx), which throws when the context has no
resolved org, then compare unconditionally against input.organizationId.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 23, 2026 16:24
@pedrofrxncx
pedrofrxncx merged commit a8d616a into main Jul 23, 2026
14 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/settings-update-unscoped-org-guard-w2 branch July 23, 2026 16:30
decocms Bot pushed a commit that referenced this pull request Jul 23, 2026
PR: #5104 fix(organization): fail closed on unresolved org in ORGANIZATION_SETTINGS_UPDATE
Bump type: patch

- decocms (apps/mesh/package.json): 4.108.1 -> 4.108.2

Deploy-Scope: server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant