Add per-IP sliding window rate limiting to public auth endpoints#286
Draft
Add per-IP sliding window rate limiting to public auth endpoints#286
Conversation
Member
|
@Schnitzel there is PR already: #283 but it's not merged yet |
Co-authored-by: Schnitzel <750999+Schnitzel@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Analyze public APIs for rate limiting implementation
Add per-IP sliding window rate limiting to public auth endpoints
Feb 19, 2026
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.
Public auth endpoints had no rate limiting, leaving them open to brute force, registration spam, SES cost abuse, and resource exhaustion via trial key generation.
Changes
app/middleware/rate_limit.py— NewRateLimitMiddlewareimplementing a thread-safe per-IP sliding window counter. Returns429withRetry-Afteron breach. Cleans up empty keys when the internal map exceeds 10k entries to bound memory use.Default limits:
/auth/login/auth/register/auth/validate-email/auth/sign-in/auth/generate-trial-accessapp/core/config.py— AddsRATE_LIMIT_ENABLEDboolean (env var, defaulttrue).app/main.py— RegistersRateLimitMiddlewareearly in the stack (after HTTPS redirect, before auth) when enabled.tests/test_rate_limit.py— Unit tests for IP extraction, sliding window allow/block logic, and per-IP/per-path isolation.Notes
Client IP is resolved from
X-Forwarded-For(first hop), falling back to the direct connection address. This assumes the upstream proxy strips client-supplied forwarding headers — consistent with the existing Lagoon deployment topology. The same assumption is already made byHTTPSRedirectMiddlewareforX-Forwarded-Proto.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
amazee-test-postgres/usr/bin/python python -m pytest tests/test_rate_limit.py -v(dns block)/usr/bin/python python -m pytest tests/test_cache_headers.py -v(dns block)/usr/bin/python python -m pytest tests/test_rate_limit.py::TestRateLimitMiddlewareDirect tests/test_rate_limit.py::TestRateLimitMiddlewareIntegration::test_default_rate_limits_cover_expected_endpoints tests/test_rate_limit.py::TestRateLimitMiddlewareIntegration::test_rate_limit_config_has_positive_values tests/test_rate_limit.py::TestRateLimitMiddlewareIntegration::test_login_endpoint_rate_limited_after_threshold -v(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.