fix: refuse admin tokens under 32 characters and throttle wrong token attempts per source
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,7 @@ pub struct Limits {
|
||||
oidc_login_source: Keyed,
|
||||
oidc_callback_source: Keyed,
|
||||
audit_denial: Keyed,
|
||||
admin_token_failure: Keyed,
|
||||
pub argon2: Arc<Semaphore>,
|
||||
trusted_proxies: Vec<IpAddr>,
|
||||
calls: AtomicU64,
|
||||
@@ -75,6 +76,7 @@ impl Limits {
|
||||
oidc_callback_source: RateLimiter::keyed(config.oidc_callback_source),
|
||||
// one audit row per source per minute, so a flood cannot fill the audit table
|
||||
audit_denial: RateLimiter::keyed(per_minute(1, 1)),
|
||||
admin_token_failure: RateLimiter::keyed(per_minute(10, 5)),
|
||||
argon2: Arc::new(Semaphore::new(config.argon2_concurrency)),
|
||||
trusted_proxies,
|
||||
calls: AtomicU64::new(0),
|
||||
@@ -131,6 +133,7 @@ impl Limits {
|
||||
self.oidc_login_source.retain_recent();
|
||||
self.oidc_callback_source.retain_recent();
|
||||
self.audit_denial.retain_recent();
|
||||
self.admin_token_failure.retain_recent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +157,12 @@ impl Limits {
|
||||
self.oidc_callback_source.check_key(&source).is_ok()
|
||||
}
|
||||
|
||||
/// Counts one wrong admin token from `source`; false once that source has used up its budget.
|
||||
pub fn admin_token_failure(&self, source: IpAddr) -> bool {
|
||||
self.maintain();
|
||||
self.admin_token_failure.check_key(&source).is_ok()
|
||||
}
|
||||
|
||||
/// True at most once a minute per source: use it to decide whether a denial is audited.
|
||||
pub fn audit_denial(&self, source: IpAddr) -> bool {
|
||||
self.audit_denial.check_key(&source).is_ok()
|
||||
|
||||
Reference in New Issue
Block a user