fix: add brute-force and rate-limit protection to login endpoints#515
fix: add brute-force and rate-limit protection to login endpoints#515JavaProgswing wants to merge 1 commit into
Conversation
|
@JavaProgswing is attempting to deploy a commit to the 007's projects Team on Vercel. A member of the Team first needs to authorize it. |
Thanks for creating a PR for your Issue!
|
| get_remote_address, | ||
| app=app, | ||
| default_limits=["200 per day", "50 per hour"], | ||
| storage_uri="memory://" |
There was a problem hiding this comment.
In-memory rate-limit storage bypassed under multi-worker deployments
storage_uri="memory://" gives each gunicorn worker an independent counter, so an attacker gets 5 login attempts per worker rather than 5 total — effectively defeating the brute-force protection this PR was added to provide.
| storage_uri="memory://" | |
| storage_uri=os.environ.get("RATELIMIT_STORAGE_URI", "memory://") |
Prompt to fix with AI
Copy this prompt into your AI coding assistant to fix this issue.
In app.py at line 37, `storage_uri="memory://"` causes each gunicorn worker to maintain independent rate-limit counters, so the 5 POST/15min brute-force limit is multiplied by the number of workers. Fix: change line 37 to `storage_uri=os.environ.get("RATELIMIT_STORAGE_URI", "memory://")` and configure a Redis URI (e.g. `redis://localhost:6379`) in the environment for production deployments. This ensures all workers share one counter.
|
|
||
| @app.errorhandler(429) | ||
| def ratelimit_handler(e): | ||
| return render_template("404.html", error_message=f"Too many requests. {e.description}"), 429 |
There was a problem hiding this comment.
Confidence Score: 2/5 - Changes NeededNot safe to merge — while this PR takes a meaningful step toward brute-force and rate-limit protection on login endpoints, two significant issues undermine its effectiveness in production. The use of Key Findings:
Files requiring special attention
|
Fixes #497