From 3c2edd2910d0bdf947644dd0bb486799ac42b0c9 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Sat, 11 Jan 2025 15:51:18 +0100 Subject: [PATCH] Do not rate limit trusted IPs (#1078) --- crates/jmap/src/auth/rate_limit.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/jmap/src/auth/rate_limit.rs b/crates/jmap/src/auth/rate_limit.rs index 4859b5bd..c017a058 100644 --- a/crates/jmap/src/auth/rate_limit.rs +++ b/crates/jmap/src/auth/rate_limit.rs @@ -93,19 +93,20 @@ impl RateLimiter for Server { async fn is_http_anonymous_request_allowed(&self, addr: &IpAddr) -> trc::Result<()> { if let Some(rate) = &self.core.jmap.rate_anonymous { - if self - .core - .storage - .lookup - .is_rate_allowed( - KV_RATE_LIMIT_HTTP_ANONYMOUS, - &ip_to_bytes(addr), - rate, - false, - ) - .await - .caused_by(trc::location!())? - .is_some() + if !self.is_ip_allowed(addr) + && self + .core + .storage + .lookup + .is_rate_allowed( + KV_RATE_LIMIT_HTTP_ANONYMOUS, + &ip_to_bytes(addr), + rate, + false, + ) + .await + .caused_by(trc::location!())? + .is_some() { return Err(trc::LimitEvent::TooManyRequests.into_err()); }