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

Apply Rate Limiting to Critical Routes Using SlowAPI #62

Open
LEVIII007 opened this issue Oct 22, 2024 · 0 comments · May be fixed by #63
Open

Apply Rate Limiting to Critical Routes Using SlowAPI #62

LEVIII007 opened this issue Oct 22, 2024 · 0 comments · May be fixed by #63

Comments

@LEVIII007
Copy link

We need to apply rate limiting to specific critical routes in our FastAPI application to prevent potential abuse or exploitation. The rate limiter should be configured using SlowAPI and applied selectively on routes that handle sensitive actions like authentication and token generation.

Task Details:

Global Initialization of SlowAPI:

Initialize the SlowAPI rate limiter instance globally in main.py.
Set up a global exception handler for rate limiting to return appropriate error messages (e.g., status code 429 for "Too Many Requests").
Apply Rate Limiting to Critical Routes:

Import the limiter instance in specific router files where rate limiting is needed.

Add rate limiting on:

/auth/create-access-token: Limit to 2 requests per second.
/auth/refresh-token: Limit to 2 requests per second.
/user/create: Limit to 10 requests per second.
Review other routes that handle sensitive actions and determine if they need rate limiting.
Testing:

Ensure that the rate limiting works as expected for these routes.
Verify that the system returns appropriate error messages when the rate limit is exceeded.

Why This Is Important:

Prevent potential abuse of sensitive endpoints like token generation.
Ensure the application remains responsive by mitigating overload due to excessive requests.

@LEVIII007 LEVIII007 linked a pull request Oct 22, 2024 that will close this issue
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 a pull request may close this issue.

1 participant