From: Dessalines Date: Tue, 29 Mar 2022 15:46:03 +0000 (+0000) Subject: Lowering search rate limit. Fixes #2153 (#2154) X-Git-Url: http://these/git/readmes/README.ja.md?a=commitdiff_plain;h=e16821116e2180ef4898f75589a65607fd7c53b3;p=lemmy.git Lowering search rate limit. Fixes #2153 (#2154) * Lowering search rate limit. Fixes #2153 * Adding a search rate limit. * Forgot to add the websocket search rate limit * Fix wrong op --- diff --git a/config/defaults.hjson b/config/defaults.hjson index 3458467d..18a4b219 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -36,6 +36,9 @@ comment: 6 # Interval length for comment limit, in seconds comment_per_second: 600 + search: 6 + # Interval length for search limit, in seconds + search_per_second: 600 } # Settings related to activitypub federation federation: { diff --git a/crates/utils/src/rate_limit/mod.rs b/crates/utils/src/rate_limit/mod.rs index 69bcbcec..f8acc3af 100644 --- a/crates/utils/src/rate_limit/mod.rs +++ b/crates/utils/src/rate_limit/mod.rs @@ -57,6 +57,10 @@ impl RateLimit { self.kind(RateLimitType::Comment) } + pub fn search(&self) -> RateLimited { + self.kind(RateLimitType::Search) + } + fn kind(&self, type_: RateLimitType) -> RateLimited { RateLimited { rate_limiter: self.rate_limiter.clone(), @@ -79,6 +83,7 @@ impl RateLimited { RateLimitType::Register => (rate_limit.register, rate_limit.register_per_second), RateLimitType::Image => (rate_limit.image, rate_limit.image_per_second), RateLimitType::Comment => (rate_limit.comment, rate_limit.comment_per_second), + RateLimitType::Search => (rate_limit.search, rate_limit.search_per_second), }; let mut limiter = self.rate_limiter.lock(); diff --git a/crates/utils/src/rate_limit/rate_limiter.rs b/crates/utils/src/rate_limit/rate_limiter.rs index 31d91036..258d7704 100644 --- a/crates/utils/src/rate_limit/rate_limiter.rs +++ b/crates/utils/src/rate_limit/rate_limiter.rs @@ -16,6 +16,7 @@ pub(crate) enum RateLimitType { Post, Image, Comment, + Search, } /// Rate limiting based on rate type and IP addr diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index ccda734d..fe4c1509 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -170,6 +170,11 @@ pub struct RateLimitConfig { /// Interval length for comment limit, in seconds #[default(600)] pub comment_per_second: i32, + #[default(6)] + pub search: i32, + /// Interval length for search limit, in seconds + #[default(600)] + pub search_per_second: i32, } #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)] diff --git a/crates/websocket/src/chat_server.rs b/crates/websocket/src/chat_server.rs index 4dafafd8..4328d2d3 100644 --- a/crates/websocket/src/chat_server.rs +++ b/crates/websocket/src/chat_server.rs @@ -493,6 +493,7 @@ impl ChatServer { let user_operation = UserOperation::from_str(op)?; let passed = match user_operation { UserOperation::GetCaptcha => rate_limiter.post().check(ip), + UserOperation::Search => rate_limiter.search().check(ip), _ => true, }; let fut = (message_handler)(context, msg.id, user_operation, data); diff --git a/src/api_routes.rs b/src/api_routes.rs index 1af9f028..7a3feb5c 100644 --- a/src/api_routes.rs +++ b/src/api_routes.rs @@ -29,7 +29,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { ) .service( web::resource("/search") - .wrap(rate_limit.message()) + .wrap(rate_limit.search()) .route(web::get().to(route_get::)), ) .service(