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

Idiomatic way of conditionally parsing json? #1067

Closed
vmalloc opened this issue Sep 2, 2019 · 4 comments

Comments

@vmalloc
Copy link
Contributor

commented Sep 2, 2019

Currently trying to implement something like this:

fn route(data: web::Json<SomeData>) -> HttpResponse {
    if !is_user_authenticated(...) {
        return HttpResponse::Unauthorized().body("!!!");
   }
   // Work with data
}

Is prone to DoS attacks, because the server reads the request (even if it can be very big), deserializes it, and only then checks if the request is allowed.
What is the idiomatic way of achieving the same thing, only checking the authentication first?

@fafhrd91

This comment has been minimized.

Copy link
Member

commented Sep 2, 2019

Move authentication to middleware or extractor

@vmalloc

This comment has been minimized.

Copy link
Contributor Author

commented Sep 2, 2019

Can I count on the order of extraction for that matter?

@fafhrd91

This comment has been minimized.

Copy link
Member

commented Sep 2, 2019

You can

@fafhrd91 fafhrd91 closed this Sep 2, 2019

@vmalloc

This comment has been minimized.

Copy link
Contributor Author

commented Sep 2, 2019

Thanks for the quick reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.