[SEC-002] Aggregate auth throttle runs before verification cache; sprayer can lock out a key's holder #245

Closed
opened 2026-12-02 16:07:34 -05:00 by dohertj2 · 1 comment
Owner

SEC-002 — Aggregate throttle can deny a key to its legitimate holder

  • Severity: High · Category: Bug (availability) · Confidence: Confirmed
  • Location: Security/Authorization/GatewayGrpcAuthorizationInterceptor.cs:125-143; Security/Authorization/ApiKeyFailureLimiter.cs:161-206, 307-325.

Description. failureLimiter.Check runs before apiKeyVerifier.VerifyAsync, so it also runs before CachingApiKeyVerifier's cache lookup. Once a key id's cross-peer aggregate is over ApiKeyFailureAggregateLimit (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 per ApiKeyFailureProbeIntervalSeconds (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.md line 99 says so).

Failure scenario. An attacker who knows key id otopcua sends 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, Reset clears the aggregate, and the attacker re-trips it within milliseconds. The legitimate client sees ResourceExhausted on 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 throws ResourceExhausted.


Source: code-reviews/2026-12-02-perf-bugs/README.md and code-reviews/2026-12-02-perf-bugs/PLAN.md (commit f200bda6 on local branch docs/review-2026-12-02-perf-bugs, not yet pushed). Reviewed at 54367e74.

## SEC-002 — Aggregate throttle can deny a key to its legitimate holder - **Severity:** High · **Category:** Bug (availability) · **Confidence:** Confirmed - **Location:** `Security/Authorization/GatewayGrpcAuthorizationInterceptor.cs:125-143`; `Security/Authorization/ApiKeyFailureLimiter.cs:161-206, 307-325`. **Description.** `failureLimiter.Check` runs before `apiKeyVerifier.VerifyAsync`, so it also runs before `CachingApiKeyVerifier`'s cache lookup. Once a key id's cross-peer aggregate is over `ApiKeyFailureAggregateLimit` (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 per `ApiKeyFailureProbeIntervalSeconds` (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.md` line 99 says so). **Failure scenario.** An attacker who knows key id `otopcua` sends 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, `Reset` clears the aggregate, and the attacker re-trips it within milliseconds. The legitimate client sees `ResourceExhausted` on 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 throws `ResourceExhausted`. --- Source: `code-reviews/2026-12-02-perf-bugs/README.md` and `code-reviews/2026-12-02-perf-bugs/PLAN.md` (commit `f200bda6` on local branch `docs/review-2026-12-02-perf-bugs`, not yet pushed). Reviewed at `54367e74`.
dohertj2 added the area:gatewayarea:authpriority:p0type:bugtype:review-finding labels 2026-12-02 16:07:34 -05:00
Author
Owner

Merged to main at 68043411 (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).

Merged to `main` at `68043411` (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).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/mxaccessgw#245