Repository navigation
fix(backend): recover safely in Admin API authorization - #1382
Open
Dev-Zwaylo wants to merge 3 commits into
Open
Dev-Zwaylo wants to merge 3 commits into
Dev-Zwaylo wants to merge 3 commits into
Conversation
Centralize admin key validation: read ADMIN_API_KEY once per check, reject missing/empty/non-string keys and unset config, use constant-time comparison. Rejected requests have no side effects so retry with a rotated key never duplicates effects. Add tests for missing, malformed, rotated and interleaved-rotation cases.
|
@Dev-Zwaylo is attempting to deploy a commit to the ritik4ever's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch has not been deployed
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.
this pr closes #1110
Fixes the [RELIABILITY] Admin API authorization issue (SSB-2026-167).
Current behavior: adminAuth and /api/admin/auth compared the key with !==, so the comparison wasn't constant-time. Malformed values and an unset or empty ADMIN_API_KEY weren't handled explicitly.
Change:
New shared isValidAdminKey in backend/src/middleware/adminAuth.ts:
It reads ADMIN_API_KEY once per check, so a concurrent rotation is judged against either the old key or the new one, never a mix.
It rejects missing, empty and non-string keys, and rejects everything when no key is configured.
It compares keys with timingSafeEqual.
Both the adminAuth middleware and /api/admin/auth in backend/src/index.ts use it.
Retry path: a rejected request returns 401 before any handler runs, so it has no side effects. Retrying with the rotated key runs the handler exactly once, with no duplicated money-moving effects, events or stored state.
Tests: new adminAuth.test.ts covers missing, malformed, rotated and interleaved-rotation cases.
No documented behavior changes.