Repository navigation
fix(auth): never answer a user-key 429 with Retry-After: 0 - #11082
ayobamiseun wants to merge 1 commit into
Conversation
checkBootstrapUserApiKeyRateLimit built Retry-After straight from the Redis TTL with no floor. A TTL of 0 is not an error here — the guard twelve lines above accepts it deliberately as "the normal sub-second tail of an active fixed window", rather than fail-closing a valid under-limit request, and api/_user-api-key.test.mjs pins that acceptance. Combined with an over-limit counter it produced Retry-After: 0 on the refusal, telling a caller that was just rejected to come straight back into the same exhausted window. Both /api/bootstrap and /api/oauth/authorize reach this path. Every other meter floors the value: rateLimitHeaders in api/_api-key-rate-limit.js uses Math.max(1, ...), and the desktop-key meter reaches it through helpers that are themselves floored. This one was the outlier. Red proof: with the handler reverted, the new case fails.
|
@ayobamiseun is attempting to deploy a commit to the World Monitor Team on Vercel. A member of the Team first needs to authorize it. |
Strix Security Review✅ No open security findings. PR summary: This PR floors the `Retry-After` header on the bootstrap user-key rate-limit refusal at one second, so a caller refused while the fixed window is in its sub-second tail is no longer told to retry immediately, and adds a test for the over-limit plus zero-TTL combination. Review summaryReviewed the one production hunk ( Review 1 on this PR · Reviewed by Strix |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
[Medium impact] The PR appears safe to merge. SummaryFloors
Reviews (1) · Last reviewed commit: "fix(auth): never answer a user-key 429 w..." · Reviewed by Greptile |
auditbenchaibot
left a comment
There was a problem hiding this comment.
🤖 Automated review by Audit Bench Ai, not a personal review. It was posted through the GitHub account connected to Audit Bench Ai. Install the Audit Bench Ai GitHub App to have reviews posted by a separate bot account.
No actionable comments were generated in this review. 🎉
Merge risk: ⚪ Minimal · up to c66e86a
The change is a small, well-tested floor adjustment that prevents immediate retry loops and matches existing conventions elsewhere in the codebase.
Merge readiness: ⛔ Not ready to merge
Pre-merge checks: ✅ 9 · ❌ 1
❌ Failed checks: 1 error
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| CI checks | ❌ | 1 of 59 failing: Vercel. | Open the failing runs on GitHub and fix them before merging. |
✅ Passed checks: 9 passed
| Check name | Status | Explanation |
|---|---|---|
| Merge conflicts | ✅ | Merges cleanly into main. |
| Secrets | ✅ | No keys, passwords or tokens in the changed code. |
| Blocking issues | ✅ | No critical or high-severity issues in the changed lines. |
| Tests | ✅ | Tests were changed alongside the code. |
| PR size | ✅ | 26 lines changed. |
| Title check | ✅ | The title clearly states the bug fix and its specific target. |
| Description check | ✅ | The description provides comprehensive context, rationale, and verification details. |
| Linked issues check | ✅ | No issue links were referenced in the pull request description. |
| Out of scope changes check | ✅ | All changes are strictly limited to fixing the Retry-After header floor and adding corresponding test coverage. |
📝 Walkthrough
This pull request ensures that HTTP 429 rate limit responses in user API key validation always include a minimum Retry-After header value of 1 second rather than 0. Previously, when the Redis TTL fell into a sub-second tail, callers over the limit were told to retry immediately into the same exhausted window. The change aligns this endpoint with other rate meters across the codebase and adds a targeted unit test.
| File | Changes |
|---|---|
api/_user-api-key.js |
Floors the Retry-After header value to at least 1 second when returning a 429 response. |
api/_user-api-key.test.mjs |
Adds a unit test verifying that a 0 TTL over-limit state produces a Retry-After header of 1. |
ℹ️ Review info
- Commit:
c66e86a - Verdict: ✅ Pass
- Findings: none
- Review: local checks plus AI review of the changed lines
- Scope: Reviewed 2/2 selected files (of 2 total): 2 reviewed by AI, 0 from cache, 0 passed local checks with nothing risky enough to send to AI. Found 0 finding(s), No secrets found.
💬 Reply to any inline comment and Audit Bench Ai will recheck that code and answer in the thread. Mention @auditbench in the conversation to ask about the whole PR.
🛠️ Open the full report and fix with AI
Thanks for using Audit Bench Ai! Free pull request reviews for open source: paste any public PR at auditbenchai.com/scan.
Reviewed by Audit Bench Ai · Build fast. Check what ships. · Review any public PR free
Summary
checkBootstrapUserApiKeyRateLimitbuilt the refusal header straight from the Redis TTL:A TTL of
0is not an error on this path. The guard twelve lines above accepts it deliberately, with a comment calling it "the normal sub-second tail of an active fixed window (counter still exists, about to reset), so accept it rather than fail-closing a valid under-limit request with a spurious 503", andapi/_user-api-key.test.mjspins that acceptance separately.Combined with an over-limit counter, that produced
HTTP 429withRetry-After: 0: a client that was just refused is told to retry immediately, re-enters the same still-exhausted fixed window, and is refused again. Both/api/bootstrapand/api/oauth/authorizereach this path.Why this one and not the others
Every other meter in the codebase floors the value:
rateLimitHeadersinapi/_api-key-rate-limit.jsMath.max(1, opts.retryAfterSec)api/_desktop-key-meter.jssecondsUntilUtcMidnight/secondsUntilNextMinute, both already flooredapi/_user-api-key.jsSo this is one line bringing an outlier in line, not a new convention.
Out of scope on purpose:
api/_rate-limit.jsandserver/_shared/rate-limit.tsshare aMath.max(0, …)that can also reach zero on a one-second window. They are mirrors of each other with a mirrored comment, so changing them is a two-file convention decision rather than fixing drift. I left them alone.Tests
api/_user-api-key.test.mjsgains the missing combination. Both halves of the state were already pinned individually — the over-limit refusal at one case, thettl: 0acceptance at another — and only their intersection was uncovered.Red proof: with
api/_user-api-key.jsreverted to itsmainversion, the new case fails.Verification
api/_user-api-key,bootstrap-auth,bootstrap-cors,_rate-limit,_api-keynode suites — 189 pass, 0 failnpm run typecheck:api, Biome,git diff --check— cleanSummary by CodeRabbit