[PR #5317] [MERGED] chore(api-key): use same logic as createApiKey for authorization #5922

Closed
opened 2026-03-13 12:41:25 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5317
Author: @ping-maxwell
Created: 10/15/2025
Status: Merged
Merged: 10/15/2025
Merged by: @Bekacru

Base: canaryHead: fix/api-key-update-auth-logic


📝 Commits (2)

  • f8efc6e chore(api-key): use same logic as createApiKey for authorization
  • bdb69ba Merge branch 'canary' into fix/api-key-update-auth-logic

📊 Changes

2 files changed (+35 additions, -10 deletions)

View changed files

📝 packages/better-auth/src/plugins/api-key/api-key.test.ts (+24 -8)
📝 packages/better-auth/src/plugins/api-key/routes/update-api-key.ts (+11 -2)

📄 Description

The only logic of create-api-key for authorizing who can create the key was flawed, I just noticed the updateApiKey endpoint was using the same logic as our old, so just updated it and improved tests to be more solid


Summary by cubic

Aligns updateApiKey authorization with createApiKey to prevent client-side updates without a valid session. Blocks cross-user updates and standardizes 401 errors; tests updated to assert this behavior.

  • Bug Fixes
    • Require a session for requests with headers; no fallback to body.userId on client calls.
    • Reject updates when session userId differs from body.userId.
    • Return 401 UNAUTHORIZED with UNAUTHORIZED_SESSION; tests assert status and message.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5317 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 10/15/2025 **Status:** ✅ Merged **Merged:** 10/15/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/api-key-update-auth-logic` --- ### 📝 Commits (2) - [`f8efc6e`](https://github.com/better-auth/better-auth/commit/f8efc6e366aaa51103324db80071e9e3c6e45e1e) chore(api-key): use same logic as createApiKey for authorization - [`bdb69ba`](https://github.com/better-auth/better-auth/commit/bdb69ba5c63a8e981bcb4012808ee5ed4d857b01) Merge branch 'canary' into fix/api-key-update-auth-logic ### 📊 Changes **2 files changed** (+35 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/api-key/api-key.test.ts` (+24 -8) 📝 `packages/better-auth/src/plugins/api-key/routes/update-api-key.ts` (+11 -2) </details> ### 📄 Description The only logic of create-api-key for authorizing who can create the key was flawed, I just noticed the updateApiKey endpoint was using the same logic as our old, so just updated it and improved tests to be more solid <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Aligns updateApiKey authorization with createApiKey to prevent client-side updates without a valid session. Blocks cross-user updates and standardizes 401 errors; tests updated to assert this behavior. - **Bug Fixes** - Require a session for requests with headers; no fallback to body.userId on client calls. - Reject updates when session userId differs from body.userId. - Return 401 UNAUTHORIZED with UNAUTHORIZED_SESSION; tests assert status and message. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:41:25 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#5922