Skip to content

fix(auth): rate-limit reads that verify tokens or query the database - #114

Merged
PiquelChips merged 1 commit into
mainfrom
fix/rate-limit-reads
Oct 14, 2026
Merged

PiquelChips merged 1 commit into
mainfrom
fix/rate-limit-reads

Conversation

@PiquelChips

@PiquelChips PiquelChips commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Most GET requests had no rate limit. Only sign-in, authorize and token requests were budgeted. So GET /oidc/userinfo and GET /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_category no longer looks at the HTTP method. Every matched route now has a budget, except:

  • Health probes (/health/live, /health/ready), in a new Endpoint::Health class. piqueld polls them, and a throttled probe would take the service out of rotation. Readiness runs one SELECT 1, which costs no more than the budget's own upsert would.
  • Discovery and JWKS. They are served from memory, cacheable, and clients fetch them often.

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:

Category Routes
token token, revoke
userinfo (new) userinfo
account /account/*, /session*, /config, now reads too
login /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 shared login). The method-independent rate_category also lets the mutation parameter go. Endpoint stays 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 the Account class for its origin policy. Stopping high-volume floods still belongs at the edge.

Testing

  • New routes_doing_real_work_have_budgets maps real route paths to their budgets: health and discovery are free; userinfo, logout, session, account lists, pending link, resume and transaction are budgeted.
  • New database test reads_exhaust_their_own_budget: 120 GET /oidc/userinfo requests pass, the 121st gets 429 with Retry-After: 60, and GET /session from 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.
  • On a piqueld preview:
    • /health/ready returned 204 for all 130 back-to-back requests.
    • 125 GET /session requests gave 120 × 401 and then 429 with retry-after: 60.
    • Right after that, GET /oidc/userinfo still answered (401, no bearer token), so the exhausted account budget did not affect it. A later run of 130 userinfo requests gave 121 × 401 and then 9 × 429 with retry-after: 60.
    • In these preview runs the cutoff landed within one request of 120 (121 in one run, 119 in another), and I haven't found why. The database test checks the exact 120/121 boundary.
    • Discovery, JWKS and /login/providers kept answering 200.
    • A Playwright run with a virtual passkey registered an account, loaded settings six times and unlocked settings with a passkey: 61 auth requests, none throttled. The auth logs show no errors.

Note

Written by Claude Opus 5.5 in Claude Code and reviewed by GPT-6.1 Sol (via T3 Code)

🤖 Generated with Claude Code

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 PiquelChips self-assigned this Oct 14, 2026
@PiquelChips PiquelChips added bug Something isn't working apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI labels Oct 14, 2026
@PiquelChips PiquelChips added this to the 0.1 milestone Oct 14, 2026
@PiquelChips
PiquelChips merged commit a8dd15a into main Oct 14, 2026
9 checks passed
@PiquelChips
PiquelChips deleted the fix/rate-limit-reads branch October 14, 2026 11:47
@github-project-automation github-project-automation Bot moved this to Needs Triage in sourceorigin.dev Oct 14, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in sourceorigin.dev Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apps/auth-service Origin Auth at auth.sourceorigin.dev, its settings and developer console, and the operator CLI bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant