Repository navigation
feat(rate-limit): exempt admins and raise default limits #612
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
recommended rate limit per minute for login endpoints to prevent brute force💡 Result:
There is no single "correct" rate limit for all login endpoints; the optimal configuration must be tailored to your application's expected user behavior and threat model [1][2][3]. However, authoritative security guidance from sources like OWASP recommends a layered, multi-dimensional approach rather than relying on a single IP-based limit [4][5][2]. Recommended Strategies and Best Practices: 1. Use Layered Buckets (Independent Limits) To effectively stop both targeted brute force and distributed credential stuffing, you must implement independent rate-limiting buckets that are checked separately [4][5]. If a request hits either threshold, it should be rejected [4][5]. * Per-Username Bucket: Limits attempts against any specific account, regardless of the source IP. This defends against distributed attacks where an attacker rotates through many IPs to target one account [4][5]. * Per-IP (or Per-IP+ASN) Bucket: Limits total login attempts originating from a single source (e.g., an IP address). This defends against credential-stuffing sweeps that attempt many different usernames from one location [4][5]. 2. Typical Starting Thresholds While you should tune these based on your specific traffic patterns, common starting points from industry examples include: * Per-IP: Often set between 5–10 attempts per minute [6][2][7]. Some implementations allow for a small burst (e.g., 20) to accommodate legitimate users [8][7]. * Per-Username: Often more conservative, such as 5 attempts per hour, depending on the sensitivity of the service [2][9]. * Adjustment: Start with conservative limits and gradually relax them after monitoring for false positives [6][9]. 3. Implementation Guidelines * Use Edge-Level Filtering: Perform rate limiting at the network edge (CDN, WAF, or load balancer) whenever possible [8][2][7]. This is the most efficient method because it blocks malicious traffic before it consumes application resources (like database connections or PHP workers) [8][2][7]. * Use Appropriate Algorithms: Prefer token-bucket or sliding-window algorithms [5][9][3]. Avoid simple fixed-window counters, which can be easily bypassed by bursting at the window boundary [5][3]. * State Management: In distributed or serverless environments, ensure your rate-limiting state is stored in a shared, high-performance data store like Redis [10]. In-memory counters will fail to protect against distributed attacks in multi-instance deployments [10]. * Consistent Responses: Return a generic 429 Too Many Requests status code [4][10][5]. Avoid including specific diagnostic details (such as which bucket was tripped or the number of remaining attempts) as this helps attackers refine their tools [4][5]. * Supplemental Defenses: Rate limiting alone is insufficient against sophisticated botnets [2][3]. Complement it with bot detection (device fingerprinting), CAPTCHA challenges for suspicious traffic, account lockout policies, and phishing-resistant authentication methods like passkeys [1][8][5][2][11]. Always monitor your authentication logs to distinguish between legitimate user frustration (e.g., mistyping a password) and actual attack traffic, and adjust your thresholds accordingly [6][2][12].
Citations:
🏁 Script executed:
sed -n '1,220p' openrag/api/middleware/rate_limit.pyRepository: linagora/openrag
Length of output: 4283
Tighten
/auth/*throttlingThe
/auth/*bucket is keyed by client IP for unauthenticated requests, so 60/min leaves a high ceiling for credential-stuffing from shared egress IPs. Add a separate failed-login sub-limit, or lower this default if brute-force resistance matters here.🤖 Prompt for AI Agents