Class FailedAttemptThrottle
Per-key failed-attempt throttle (review item 4.5). After failures within
the key is locked out for , defeating online guessing.
A success clears the counter, so a legitimate caller with a valid credential never accumulates state.
This is the API-key analogue of the dashboard's LoginThrottle (review item 2.6): the same
failure-count-and-lockout semantics and the same per-entry lock discipline (see the concurrency note in
). It gates the ACTUAL authentication surface — every API request carries a
key, so the throttle keys on the client IP and counts key-auth failures across all endpoints, not just a
single path prefix (which was the 4.5 defect: a path-limited request-count gate that key-guessing simply
routed around).
Pure and clock-injectable so lockout timing is unit-testable without waiting.
Known limitation (F3): because a success clears the key's counter, principals that share
one key (NAT / corporate egress / a single reverse-proxy IP when TrustProxyHeaders is off) can
let a legitimate user's success reset an attacker's failure count. Key on the real per-client IP
(enable TrustProxyHeaders behind a proxy) to avoid the shared-bucket weakening.
public sealed class FailedAttemptThrottle
Inheritance
Properties
LockoutDuration
public TimeSpan LockoutDuration { get; }
MaxAttempts
public int MaxAttempts { get; }
Window
public TimeSpan Window { get; }
Methods
RecordFailure(string)
Record a failed attempt; may transition the key into lockout.
public void RecordFailure(string key)
RecordSuccess(string)
Clear any failure/lockout state for key after a success.
public void RecordSuccess(string key)