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

Limit requests for non 2xx response globally #291

Closed
severien opened this issue Oct 12, 2021 · 2 comments
Closed

Limit requests for non 2xx response globally #291

severien opened this issue Oct 12, 2021 · 2 comments

Comments

@severien
Copy link

It would be nice to define global rate limits for non 2xx responses.
Since the limits are tied to the routes it is not possible to define limits for requests that have response other than 2xx. As an example when requests are done for paths that generates a 404 response its not possible to rate limit these requests. This can pose a security risk, where a caller can DDoS on Not Found paths or try to scan your API to find valid paths.

I attempted calling the the limit inside an after_request function to apply a deduct_when function, but noticed that the __check_request_limit is tied to the view routes, so its not possible to call the limiter outside of the decorator scope.

My failed attempt to limit on 404:

    @app.after_request
    def limit_non_success_response(response):
        def deduction():
            return response.status_code >= 400

        global_limiter.limit(
            limit_value="2/minute",
            key_func=throttling_key,
            deduct_when=deduction
        )

        return response
@alisaifee
Copy link
Owner

This was brought up before in #201 I wonder if that solution works for you?

@alisaifee
Copy link
Owner

Closing due to inactivity

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

No branches or pull requests

2 participants