feat: IP-based rate limiting using Bucket4j - #2
Open
aayushcodex17 wants to merge 1 commit into
Open
Conversation
- Added bucket4j-core 8.10.1 dependency - Created RateLimitingFilter (OncePerRequestFilter) with per-IP token buckets - Auth endpoints (/auth/login, /signup, /registerAsHotelManager): 5 req/min - General API endpoints: 60 req/min per IP - Webhooks (/webhook/**) bypass rate limiting for Stripe compatibility - Returns 429 with existing ApiResponse/ApiError format on limit exceeded - Adds X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Retry-After-Seconds headers - Handles X-Forwarded-For header for requests behind reverse proxy - Registered RateLimitingFilter before JWTAuthFilter in security chain Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
What
Adds per-IP rate limiting to protect the API from abuse and brute force attacks.
Implementation
bucket4j-core 8.10.1— token bucket algorithm, in-memory, no Redis requiredRateLimitingFilterextendsOncePerRequestFilter, runs beforeJWTAuthFilterBucketstored in aConcurrentHashMapRate Limits
/auth/login,/auth/signup,/auth/registerAsHotelManager/webhook/**Response on Limit Exceeded
Returns
HTTP 429 Too Many Requestsin the existingApiResponseformat:{ "timestamp": "2026-04-15T10:30:00", "data": null, "error": { "httpStatus": "TOO_MANY_REQUESTS", "message": "Too many requests. Please slow down and try again in 42 second(s)." } }Headers
X-RateLimit-LimitX-RateLimit-RemainingX-RateLimit-Retry-After-SecondsProxy Support
Extracts real client IP from
X-Forwarded-Forheader for deployments behind a reverse proxy or load balancer.Files Changed
pom.xml— addedbucket4j-coredependencyratelimit/RateLimitingFilter.java— new filtersecurity/WebSecurityConfig.java— registered filter beforeJWTAuthFilter