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
This commit is contained in:
Dessalines 2022-03-29 15:46:03 +00:00 committed by GitHub
parent f6b543ae0f
commit e16821116e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 1 deletions

View file

@ -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: {

View file

@ -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();

View file

@ -16,6 +16,7 @@ pub(crate) enum RateLimitType {
Post,
Image,
Comment,
Search,
}
/// Rate limiting based on rate type and IP addr

View file

@ -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)]

View file

@ -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);

View file

@ -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::<Search>)),
)
.service(