feat: implement configurable rate limiting with per-endpoint and per-user limits#2
Merged
Merged
Conversation
…user limits - Created centralized rate limit config (rateLimit.config.ts) with endpoint profiles - Rewrote rate limiter middleware with dual-tier burst + sustained windows - Per-user tracking for authenticated requests, per-IP for anonymous - Per-endpoint overrides for auth, login, register, security, generator, export, contracts - Env-var configurability via RATE_LIMIT_* environment variables - Preserved legacy slidingWindowRateLimiter factory for route-specific usage - Replaced express-rate-limit with config-driven in-house solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the previous basic rate limiting (fixed-window
express-rate-limit+ hardcoded sliding window) with a comprehensive, configurable, multi-tier rate limiting system that protects against abuse and DoS attacks.Changes
New file:
backend/src/config/rateLimit.config.tsauth/login(POST): 5 req/s burst, 20 req/min sustainedauth/register(POST): 3 req/s burst, 10 req/min sustained/certificates,/enrollments,/courses: 120 req/s burst, 1000 req/min/security: 10 req/s burst, 60 req/min/generator: 5 req/s burst, 30 req/min/contracts: 15 req/s burst, 100 req/minsetRateLimitEnvOverrides()Rewritten:
backend/src/middleware/rateLimiter.tsuserIdfor accurate quota enforcementRateLimit-Limit,RateLimit-Remaining,RateLimit-ResetX-RateLimit-Burst-*,X-RateLimit-Sustained-*NODE_ENV=testslidingWindowRateLimiterfactory for route-specific overridesModified:
backend/src/index.tsexpress-rate-limit+ oldapiRateLimiterwith newrateLimitermiddlewareconfig.rateLimiting.enabledModified:
backend/src/config/env.config.tsrateLimitingconfig section with env-var-backed settingsModified:
backend/.env.exampleRATE_LIMIT_*environment variables with documentationConfiguration via environment variables
RATE_LIMIT_ENABLEDRATE_LIMIT_BURST_MAXRATE_LIMIT_SUSTAINED_MAXRATE_LIMIT_AUTH_BURST_MAXRATE_LIMIT_AUTH_SUSTAINED_MAXRATE_LIMIT_ADMIN_BURST_MAXRATE_LIMIT_ADMIN_SUSTAINED_MAXRATE_LIMIT_LOGIN_BURST_MAXRATE_LIMIT_REGISTER_BURST_MAXTesting