fix(security): prevent privilege escalation via API key permission grants#4119
Open
0xcucumbersalad wants to merge 1 commit into
Open
fix(security): prevent privilege escalation via API key permission grants#41190xcucumbersalad wants to merge 1 commit into
0xcucumbersalad wants to merge 1 commit into
Conversation
…ants
API_KEY_CREATE and API_KEY_UPDATE accepted arbitrary permissions
(including wildcard `{ "self": ["*"] }`) with no validation. Better
Auth's apiKey.create/update also performs no permission scoping. A
regular user could create an all-powerful API key granting access to
every management tool — bypassing their actual role restrictions.
Add validateApiKeyPermissions() guard: owners and admins can grant any
permissions (they already bypass all checks at runtime), but regular
users cannot grant wildcard ("*") permissions on any resource. Applied
to both create and update API key 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
API_KEY_CREATE and API_KEY_UPDATE accepted arbitrary permissions with no validation. A regular
user-role member could create an API key with{ "self": ["*"] }— granting wildcard access to every management tool. Better Auth'sapiKey.create/apiKey.updateperforms no permission scoping.Attack
Returns an API key that can call any management tool — including
ORGANIZATION_MEMBER_UPDATE_ROLEto promote the attacker to owner.Fix
Add
validateApiKeyPermissions()inauth/roles.ts: owners and admins can grant any permissions (they already bypass all checks at runtime); regular users cannot grant wildcard"*"on any resource. Applied to both create and update handlers.Files changed
apps/mesh/src/auth/roles.tsvalidateApiKeyPermissions()apps/mesh/src/auth/roles.test.tsapps/mesh/src/tools/apiKeys/create.tsapiKey.create()apps/mesh/src/tools/apiKeys/update.tsapiKey.update()Test plan
bun run fmt— passesbun run lint— passes (0 errors)bun test apps/mesh/src/auth/roles.test.ts— 12 pass, 0 fail{ "self": ["*"] }gets error🤖 Generated with Claude Code
Summary by cubic
Prevents privilege escalation by validating API key permission grants. Regular users can no longer create or update API keys with wildcard "*" permissions; only owners and admins can.
validateApiKeyPermissionsinapps/mesh/src/auth/roles.ts.API_KEY_CREATEandAPI_KEY_UPDATEbefore calling Better AuthapiKey.create/apiKey.update.Written for commit 2d4ba6f. Summary will update on new commits.