Repository navigation
feat(api-keys): reveal API keys behind the super password - #33
Merged
Merged
Conversation
better-auth stores only a hash of each API key, so a key that was not copied at creation is lost for good. New keys now also get an encrypted copy (AES-256-GCM via encryptedText) in a separate apikey_secret table, and user.revealApiKey returns it to the owner. Revealing needs a browser session and an open super session, even for users without a super password, and is never available to API keys. Each reveal is written to the audit log. Keys created before this change have no stored copy and show a disabled reveal button. Co-Authored-By: Claude Opus 5.5 <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
encryptedText, AES-256-GCM) in a newapikey_secrettable (migration0206), kept outside better-auth'sapikeytable.user.revealApiKeymutation returns the key to its owner. It requires a browser session and an open super session (even for users without a super password, like Traefik TLS files), is classifieddangerous, checks the key's owner and organization, and writes arevealentry to the audit log.user.getexposes arevealableflag per key; the new-key dialog text now mentions that the key can be revealed again.Test plan
__test__/users/api-key-reveal.test.ts: reveal works inside a super session and is audited; denied without a super session, for API-key sessions, for other users' keys, for keys of another organization; old keys return a clear NOT_FOUNDsuper-session-procedure-accesstest listsuser.revealApiKeyas dangeroustsc --noEmitfor apps/dokploy and packages/server, biome check on changed files*.real.test.tsand the load-flaky Telegram alert test failed; the latter passes on its own🤖 Generated with Claude Code