BE-16: Implement Redis-backed API rate limiting to prevent DoS attacks - #929
Merged
chinweobtagaz merged 1 commit intoJul 30, 2026
Conversation
Add a RedisRateLimiter middleware for actix-web that tracks request counts per client IP using Redis INCR + EXPIRE, ensuring state is shared across all server workers. - Added rate_limiter.rs: generic Redis-backed middleware with configurable per-window limits and sliding window via INCR/EXPIRE - Applied 5 req/min limit to /v1/auth (login, register, refresh, logout) - Applied 30 req/min limit to /v1/games - Added env config: REDIS_AUTH_RATE_LIMIT, REDIS_AUTH_RATE_LIMIT_WINDOW, REDIS_GAME_RATE_LIMIT, REDIS_GAME_RATE_LIMIT_WINDOW - Kept existing actix-governor middleware for per-second burst protection - Includes 4 unit tests: under-limit, exceeded, headers, independent IPs Closes OpenKnight-Foundation#865
|
@emmyafolly123-coder Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Overview
This PR adds a Redis-backed rate limiting middleware for actix-web that tracks request counts per client IP using Redis
INCR+EXPIRE. Unlike the existing in-memoryactix-governor(which provides per-second burst protection per worker), the Redis-backed limiter shares state across all server workers, making it suitable for sliding-window limits like "5 requests per minute" on auth endpoints.Closes #865
Changes
Redis Rate Limiter Middleware
backend/modules/api/src/rate_limiter.rs—RedisRateLimiteractix-webTransform/Servicemiddlewaredeadpool-redisconnection pool for non-blocking Redis accessINCR+EXPIRE(auto-set on first request)X-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-ResetheadersApplied Limits
/v1/auth(login, register, refresh, logout)/v1/games(create, join, move, etc.)actix-governorEnvironment Configuration
REDIS_AUTH_RATE_LIMIT(default: 5)REDIS_AUTH_RATE_LIMIT_WINDOW(default: 60)REDIS_GAME_RATE_LIMIT(default: 30)REDIS_GAME_RATE_LIMIT_WINDOW(default: 60)Dependencies
deadpool-redis = "0.14"added tobackend/modules/api/Cargo.tomlVerification Results