[SEC-002] Aggregate auth throttle runs before verification cache; sprayer can lock out a key's holder #245
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
SEC-002 — Aggregate throttle can deny a key to its legitimate holder
Security/Authorization/GatewayGrpcAuthorizationInterceptor.cs:125-143;Security/Authorization/ApiKeyFailureLimiter.cs:161-206, 307-325.Description.
failureLimiter.Checkruns beforeapiKeyVerifier.VerifyAsync, so it also runs beforeCachingApiKeyVerifier's cache lookup. Once a key id's cross-peer aggregate is overApiKeyFailureAggregateLimit(30 per 60 s), every request presenting that key id from any peer — including the legitimate holder, whose verification is already cached — is refused unless it wins the single probe slot perApiKeyFailureProbeIntervalSeconds(5 s). The slot goes to whichever request arrives first, and a failed probe re-arms it (RecordInto, lines 319-323). Key ids are not secret (docs/Authorization.mdline 99 says so).Failure scenario. An attacker who knows key id
otopcuasends bad secrets from three or more connections (see SEC-001; three source IPs also work). Thirty failures trip the aggregate. The attacker keeps sending at a high rate; the legitimate client at 50 RPC/s wins the 5-second probe only in proportion to its share of arrivals. When it does win,Resetclears the aggregate, and the attacker re-trips it within milliseconds. The legitimate client seesResourceExhaustedon nearly every call for as long as the spray continues. The class remark that the limiter "can never deny a key to the holder of the correct secret" does not hold.Suggested fix. Let proven-good traffic bypass the valve: consult the verification cache before the limiter (a cache hit costs no store read, which is the only thing the limiter protects), and/or exempt a remote IP that has a recent successful verification for that key id from the aggregate layer. Keep the limiter in front of cache misses only.
Test idea. Prime a successful verification from
HolderPeer; record 30 failures for the same key id from other peers; assert the holder's next call (inside the cache TTL and inside the probe interval) succeeds. Today it throwsResourceExhausted.Source:
code-reviews/2026-12-02-perf-bugs/README.mdandcode-reviews/2026-12-02-perf-bugs/PLAN.md(commitf200bda6on local branchdocs/review-2026-12-02-perf-bugs, not yet pushed). Reviewed at54367e74.Merged to
mainat68043411(pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA.Cached valid verification bypasses the limiter; success clears only the caller's own counter (SEC-003).