[SEC-001] gRPC auth failure-limiter partitions on peer incl. ephemeral port, resets per connection #244
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-001 — Failure-limiter partition includes the ephemeral source port
Security/Authorization/GatewayGrpcAuthorizationInterceptor.cs:174-179;Security/Authorization/ApiKeyFailureLimiter.cs:148-159, 404-409; contrastSecurity/Authorization/MetricsAuthorization.cs:66-68.Description.
ResolveThrottlePartitionpassescontext.Peerstraight intoApiKeyThrottlePartition. In Grpc.AspNetCore that string isipv4:<address>:<port>(the repo's own test fixtures useipv4:127.0.0.1:5000), and the port is the client's ephemeral source port. The limiter uses the string verbatim as the partition key and as the_peerKeyIdskey. The "address that produced the failures" is therefore really "the TCP connection that produced them". The/metricshandler does it correctly withConnection.RemoteIpAddress(no port), so the two auth surfaces disagree.Failure scenario. An attacker sends 9 bad secrets for
mxgw_operator01_*, closes the channel, opens a new one (new source port) and repeats. No(peer, key id)partition ever reachesApiKeyFailureLimit(10). The per-address cap of 32 key-id partitions (MaxKeyIdPartitionsPerPeer) is equally per-connection. Junk-shaped tokens land on the peer-only fallback partition, which is also fresh per connection, so junk spraying is never throttled at all (no key id means no aggregate either). Each connection also mints a tracked partition, pushing the map to its cap and forcing the O(n)EvictIfOverCapacityscan on every recorded failure.Suggested fix. Derive the partition from the remote IP only (
context.GetHttpContext().Connection.RemoteIpAddress, or strip the trailing:portfromPeer, handling the bracketedipv6:[..]:portform). Share one helper withMetricsAuthenticationHandler.Test idea. Interceptor test: 9 failures from
ipv4:203.0.113.7:40001, then 9 fromipv4:203.0.113.7:40002; assert the 11th failure overall isResourceExhausted. Today it isUnauthenticated.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.Limiter keys on client IP without port (gRPC and
/metrics).