fix(organization): reject updating an org other than the authenticated one - #6541
Open
Tyagiquamar wants to merge 1 commit into
Open
fix(organization): reject updating an org other than the authenticated one#6541Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
Contributor
|
@Tyagiquamar instead of checking |
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.
Problem
ORGANIZATION_UPDATEtakesidas the org to update but never checked it againstctx.organization?.id(the path-resolved, membership-verified org). A caller authenticated against org A could passinput.idfor org B and reachboundAuth.organization.updatewith an org they may have zero membership in. As with ORGANIZATION_DELETE before #6501, Better Auth's ownupdateOrganizationre-checks permission for the target org, so this is not a live bypass today — but it left the tool one vendored-dependency behavior away from one, and it was the last sibling in the directory without the guard (member-add.ts,member-remove.ts,delete.tsall have it).Fix
The same defense-in-depth guard used in
member-remove.ts/delete.ts: reject wheninput.id !== ctx.organization?.id.Testing
bun test apps/api/src/tools/organization/update.test.ts apps/api/src/tools/organization/delete.test.ts→ 6 pass, 0 fail (new case: updating a different org rejects and never reachesboundAuth; existing cases updated for the now-presentctx.organization).bun run --cwd=apps/api check→ exit 0.bunx biome checkon touched files → clean.Summary by cubic
Rejects updating an organization other than the authenticated one in
ORGANIZATION_UPDATE. Previously it accepted anyidand relied on downstream checks; now it throws wheninput.id !== ctx.organization.id, preventing cross-org updates and surfacing an earlier error if a client passes a mismatchedid.boundAuth.organization.updatewhen the target org differs from the authenticated org.ctx.organizationin update tests.Written for commit 895fd1a. Summary will update on new commits.