fix(security): prevent admin-to-owner privilege escalation in member tools#4022
Open
0xcucumbersalad wants to merge 1 commit into
Open
fix(security): prevent admin-to-owner privilege escalation in member tools#40220xcucumbersalad wants to merge 1 commit into
0xcucumbersalad wants to merge 1 commit into
Conversation
ORGANIZATION_MEMBER_ADD and ORGANIZATION_MEMBER_UPDATE_ROLE accepted arbitrary role strings with no validation. Better Auth's addMember / updateMemberRole also performs no role hierarchy check — it just joins the array into a comma-separated string. An admin could assign "owner" to any user (including themselves), gaining full org control. Add canAssignRole() guard: owners can assign any role, admins can assign anything except "owner". Applied to both member-add and member-update-role tool handlers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
ORGANIZATION_MEMBER_ADDandORGANIZATION_MEMBER_UPDATE_ROLE— both tools accepted arbitrary role strings (including"owner") with no validation. Better Auth'saddMember/updateMemberRolealso performs no role hierarchy check (parseRolesjust joins the array into a string). An admin could assign"owner"to any user — including themselves — gaining full org control (SSO config, member management, org deletion).canAssignRole()guard inauth/roles.ts: owners can assign any role; admins can assign anything except"owner". Applied to both tool handlers before the Better Auth call.Files changed
apps/mesh/src/auth/roles.tscanAssignRole(callerRole, targetRole)apps/mesh/src/auth/roles.test.tsapps/mesh/src/tools/organization/member-add.tsaddMember()apps/mesh/src/tools/organization/member-update-role.tsupdateMemberRole()Test plan
bun run check— passesbun run fmt— passesbun run lint— passes (0 errors)bun test apps/mesh/src/auth/roles.test.ts— 5 pass, 0 failrole: ["owner"]gets errorrole: ["owner"]succeedsrole: ["owner"]gets error🤖 Generated with Claude Code
Summary by cubic
Blocks admin-to-owner privilege escalation by enforcing role assignment rules in organization member tools. Owners can assign any role; admins can assign non-owner roles only.
canAssignRole(callerRole, targetRole)inauth/roles.tswith unit tests.ORGANIZATION_MEMBER_ADDandORGANIZATION_MEMBER_UPDATE_ROLEbefore calling Better Auth.ownernow fail; owner assignments by owners still succeed.Written for commit 67526d6. Summary will update on new commits.