Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate limit websocket joins. #2165

Merged
merged 4 commits into from
Mar 27, 2022
Merged

Rate limit websocket joins. #2165

merged 4 commits into from
Mar 27, 2022

Conversation

dessalines
Copy link
Member

No description provided.

crates/utils/src/rate_limit/mod.rs Show resolved Hide resolved
}
actix::fut::ready(())
})
.wait(ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't wait on the check future like this, check doesn't need to be a async

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also put rate limiting in the StreamHandler. Only limiting connect doesn't get you much, since connect is called once per session, and not on every message

@dessalines dessalines requested a review from asonix March 26, 2022 23:57
@@ -98,6 +105,8 @@ impl Handler<WsMessage> for WsSession {
/// WebSocket message handler
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WsSession {
fn handle(&mut self, result: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
self.rate_limit_check(ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the check fails you should return early

@@ -57,6 +61,9 @@ impl Actor for WsSession {
// before processing any other events.
// across all routes within application
let addr = ctx.address();

self.rate_limit_check(ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the check fails you should return early

Copy link
Collaborator

@asonix asonix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meant to request changes, oops

@dessalines dessalines merged commit f2a0841 into main Mar 27, 2022
UserOperation::GetCaptcha => rate_limiter.post().check(ip).await,
_ => rate_limiter.message().check(ip).await,
UserOperation::GetCaptcha => rate_limiter.post().check(ip),
_ => rate_limiter.message().check(ip),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that we are checking the message rate limit twice in a row. Should be removed (also in line 488), so that only specific rate limits (register, post etc) are checked here, in addition to message rate limit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a new PR to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants