Repository navigation
fix(auth): rate-limit reads that verify tokens or query the database - #114
Merged
Merged
Conversation
GET /oidc/userinfo and /oidc/logout verified RSA signatures, and session, account and consent reads held connections from the small database pool, all without a request budget. Every matched route is now budgeted except health probes and in-memory discovery, and userinfo gets its own budget so a relying party's claim lookups never block its code exchanges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PiquelChips
force-pushed
the
fix/rate-limit-reads
branch
from
October 14, 2026 09:51
13bc834 to
69fe838
Compare
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.
Most GET requests had no rate limit. Only sign-in, authorize and token requests were budgeted. So
GET /oidc/userinfoandGET /oidc/logout?id_token_hint=…verified RSA signatures without any limit, and session, account and consent reads (/session,/account/passkeys,/account/social-identities,/login/social/pending,/oauth/authorize/resume,/oauth/authorize/transaction/{id}) could tie up the 10-connection database pool without any limit either.Fix
Endpoint::rate_categoryno longer looks at the HTTP method. Every matched route now has a budget, except:/health/live,/health/ready), in a newEndpoint::Healthclass. piqueld polls them, and a throttled probe would take the service out of rotation. Readiness runs oneSELECT 1, which costs no more than the budget's own upsert would.Static assets still fall through to the fallback route without a
MatchedPath, so they stay unbudgeted as before.Budgets, per client IP, 120 requests a minute each:
tokenuserinfo(new)account/account/*,/session*,/config, now reads toologin/login/*, authorize, logout, and the other auth-origin routes (ceremonies, consent)Userinfo gets its own budget. Otherwise a relying party's userinfo calls would use up the budget for its code exchanges (if it shared
token) or for its users' sign-ins (if it sharedlogin). The method-independentrate_categoryalso lets themutationparameter go.Endpointstays the single classification that origin, CSRF and rate policy all read, and its doc comments and the README now describe the new policy.Tradeoff: the budget is itself a database upsert (
SecurityRepository::allow_request), and it runs even on requests that end up rejected. So it limits handler work (signature checks, multi-query lookups, the time each request holds a pool connection), not raw database round trips. Each budgeted read now costs one extra small write, and/config, which used to be served from memory, now pays one too, because it shares theAccountclass for its origin policy. Stopping high-volume floods still belongs at the edge.Testing
routes_doing_real_work_have_budgetsmaps real route paths to their budgets: health and discovery are free; userinfo, logout, session, account lists, pending link, resume and transaction are budgeted.reads_exhaust_their_own_budget: 120GET /oidc/userinforequests pass, the 121st gets 429 withRetry-After: 60, andGET /sessionfrom the same client still passes.just test -p auth-service,just test-database(all 56 pass, against a disposable PostgreSQL),just lint-rust,cargo fmt --all./health/readyreturned 204 for all 130 back-to-back requests.GET /sessionrequests gave 120 × 401 and then 429 withretry-after: 60.GET /oidc/userinfostill answered (401, no bearer token), so the exhaustedaccountbudget did not affect it. A later run of 130 userinfo requests gave 121 × 401 and then 9 × 429 withretry-after: 60./login/providerskept answering 200.Note
Written by Claude Opus 5.5 in Claude Code and reviewed by GPT-6.1 Sol (via T3 Code)
🤖 Generated with Claude Code