fix(auth): recognize multi-role owner/admin in my-capabilities endpoint#4949
Merged
Conversation
Match AccessControl's hasAdminRole check so a comma-joined multi-role owner/admin (e.g. "admin,billing-manager") isn't shown a restricted-UI capability set the server would actually grant in full.
pedrofrxncx
enabled auto-merge (squash)
July 21, 2026 19:02
decocms Bot
pushed a commit
that referenced
this pull request
Jul 21, 2026
PR: #4949 fix(auth): recognize multi-role owner/admin in my-capabilities endpoint Bump type: patch - decocms (apps/mesh/package.json): 4.84.0 -> 4.84.1 Deploy-Scope: server
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.
Source: found while sweeping recent auth-related merges (#4944, #4947, #4943 — all fixed the same active-org-vs-target-org role confusion) for other latent multi-role bugs in the same neighborhood.
Why a maintainer wants this:
GET /api/auth/custom/my-capabilities/:slugis documented as "the single source of truth for proactive UI gating" and is supposed to mirrorAccessControl's owner/admin bypass.AccessControluseshasAdminRole(this.role)(access-control.ts:227), which correctly splits Better Auth's comma-joined multi-role string and checks each entry. This route instead did a plainrole === "owner" || role === "admin", which only matches a single-role member.Failure scenario: a member holds a multi-role assignment like
"admin,billing-manager"(assignable viaORGANIZATION_MEMBER_ADD/member-update-role, which takerole: string[]and store it comma-joined — seeauth/roles.ts'shasAdminRole/canAssignRoledocstrings for the same failure mode already fixed there). For such a member,role === "admin"is false, so the endpoint falls through to the custom-role permission lookup instead of returningallCapabilitiesGranted()— the UI hides admin capabilities from a user the server would actually treat as a full admin. Not a privilege escalation (real enforcement is inAccessControl, unaffected), but a real, user-visible capability-gating bug matching this repo's established multi-role-correctness bug class (#4900, #4909, #4918, #4923).Fix: swap the manual
===check for the already-existing, already-testedhasAdminRole()helper (imported alongsideADMIN_ROLES, which this file already uses elsewhere innotifyAdminsOfJoinRequestwith the same comma-split pattern).Command a reviewer runs:
cd apps/mesh && bunx tsc --noEmit;bun test apps/mesh/src/auth/roles.test.ts(covershasAdminRole, including the"admin,billing-manager"multi-role case this fix now relies on).Locally run:
bun run fmt,cd apps/mesh && bunx tsc --noEmit,bun test apps/mesh/src/auth/roles.test.ts— all green. No new test added: the swapped-in helper is already exhaustively tested, and the route itself needs a live DB session to exercise (not unit-testable per TESTING.md). Full CI validates the rest.Summary by cubic
Fixes the my-capabilities endpoint to honor multi‑role owner/admin. Uses hasAdminRole so comma‑joined roles (e.g. "admin,billing-manager") get full capabilities, matching AccessControl and preventing incorrect UI gating.
Written for commit 61df2a3. Summary will update on new commits.