feat(callback): outbound rate-bucket on the IdP token exchange#26
Merged
Conversation
Closes T2.2 from misc/next-steps.md. Adds a defense-in-depth
outbound rate-limit on the proxy → IdP token-endpoint exchange
(the second leg of /callback). When wired, a flood of /callback
hits that slips past the per-IP limiter (distributed sources,
permissive XFF trust matrix) is bounded by the token bucket
before reaching the IdP — preventing a remote-traffic spike from
becoming the IdP's problem (and then cascading back as the
proxy's problem when the IdP starts dropping requests).
- golang.org/x/time/rate.Limiter, atomic Allow() (non-blocking).
Wait() would tie up handler goroutines on the IdP's behalf
and turn an IdP outage into a proxy outage.
- On deny: 503 temporarily_unavailable + error_code
idp_exchange_throttled + Retry-After: 1, increments
mcp_auth_idp_exchange_throttled_total. The 503 +
temporarily_unavailable shape matches RFC 6749 §4.1.2.1 for
AS overload.
- Limiter check runs BEFORE the SessionID replay claim so a
transiently-throttled legitimate user can retry the same
/callback URL without burning their claim slot — replay
defense (per-state) and throttling (global) are orthogonal,
placing throttle first keeps the UX safe under bursts.
- Default OFF: operators opt in by setting
IDP_EXCHANGE_RATE_PER_SEC > 0 (with optional
IDP_EXCHANGE_BURST, default 50). Per-replica scope —
operators sizing the env var multiply by replica count to
get the IdP-side ceiling.
- Tests: throttled (denies, metric +1, verify never runs);
no-limiter (back-compat, pre-T2.2 behavior unchanged); 5
config tests (default-disabled, custom rate+burst, negative
reject, non-number reject, burst-must-be->=1).
Docs: README env vars + observability metric entry,
docs/threat-model.md row 9 (IdP outage) extended with the rate-
bucket mitigation + per-replica note, docs/runbooks/idp-outage.md
gained a tuning playbook section.
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
Closes T2.2 from `misc/next-steps.md`. Adds a defense-in-depth outbound rate-limit on the proxy → IdP token-endpoint exchange (the second leg of `/callback`).
A flood of `/callback` hits that slips past the per-IP limiter (distributed sources, permissive XFF trust matrix) is bounded by the token bucket before reaching the IdP — preventing a remote-traffic spike from becoming the IdP's problem (and then cascading back as the proxy's problem when the IdP starts dropping requests).
Behavior
Tests
Docs
Test plan