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

[FEAT] Enforce Global API Rate Limiting for Enhanced Security and Performance #1304

Open
5 tasks
NnatuanyaFrankOguguo opened this issue Feb 28, 2025 · 0 comments
Labels
Approved - 1st Mentor Set when at least one mentor has approved approved feature

Comments

@NnatuanyaFrankOguguo
Copy link

Description

Implement API rate limiting using NestJS's ThrottlerModule to restrict the number of requests a client can make within a given time frame. This will improve security and overall stability of the API by preventing abuse and reducing the risk of DoS attacks.

Acceptance Criteria

  • The project is configured to use the NestJS ThrottlerModule.
  • Global or endpoint-level rate limits are enforced (e.g., 100 requests per minute per client).
  • Appropriate error responses (e.g., HTTP 429 Too Many Requests) are returned when limits are exceeded.
  • Unit and integration tests are added to verify the rate limiting behavior.
  • Documentation is updated to explain the rate limiting policy and configuration.

Purpose

Adding rate limiting will help protect the API from malicious or excessive use, ensuring fair usage for all clients and improving the overall reliability and scalability of the application.

Requirements

  • Install the NestJS Throttler package:
    - npm install @nestjs/throttler
  • Configure the ThrottlerModule in the root module (e.g., in app.module.ts) with sensible defaults (e.g., 100 requests per minute).
  • Optionally, allow for custom limits on specific controllers or routes via decorators.
  • Update tests to simulate request bursts and verify that excess requests receive a 429 response.
  • Update API documentation to include rate limiting details.

Expected Outcome

Clients making excessive requests will receive an HTTP 429 status code with an appropriate message. For normal usage, the API will continue to operate without noticeable delay. Overall, this feature will contribute to improved API resilience and user fairness.

Additional Context

Rate limiting is a widely recognized best practice for APIs in production environments. Implementing this feature will help the HNG Boilerplate project scale more safely and securely, while also providing a better baseline for developers contributing to the project.

@TheCodeGhinux TheCodeGhinux added Approved - 1st Mentor Set when at least one mentor has approved approved labels Feb 28, 2025
@NnatuanyaFrankOguguo NnatuanyaFrankOguguo changed the title [FEAT] Enforce Global API Rate Limiting for Enhanced Security and Performance [FEAT] [in progress] Enforce Global API Rate Limiting for Enhanced Security and Performance Feb 28, 2025
@NnatuanyaFrankOguguo NnatuanyaFrankOguguo changed the title [FEAT] [in progress] Enforce Global API Rate Limiting for Enhanced Security and Performance [FEAT] Enforce Global API Rate Limiting for Enhanced Security and Performance Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved - 1st Mentor Set when at least one mentor has approved approved feature
Projects
None yet
Development

No branches or pull requests

2 participants