Repository navigation
Limit requests per client with Rack::Attack - #59
Merged
Merged
Conversation
A client IP gets 8 requests a second on everything except assets, and 15 a minute each on signing in (sign-in, password reset, unlock and invitation links) and on searches, file downloads and data queries (CSVs, EML, visualizations). Over the limit a client gets 429 with Retry-After, and the refusal is logged with the path but not the query string. Counts are kept in Rails.cache, which is memcached in production, so all Puma workers share them; if memcached is down nothing is limited. The limits can be changed with RATE_LIMIT_PER_SECOND and RATE_LIMIT_PER_MINUTE, or switched off with RATE_LIMITING=off, without a deploy. They are off in the test environment except in the specs for them. Gemfile.lock needs regenerating for rack-attack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016AR3uoZS1uCC8hXmojk3K7
The memcached instance is shared with other apps, so a key like views/citations/1 could collide with another app's. The production cache store now uses the namespace "metadata", which covers everything written through Rails.cache: page fragments and the rate-limit counters. Entries already in memcached under the old unprefixed keys are no longer read, so the cache starts empty on the first deploy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016AR3uoZS1uCC8hXmojk3K7
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.
A client IP gets 8 requests a second on everything except assets, and 15 a
minute each on signing in (sign-in, password reset, unlock and invitation
links) and on searches, file downloads and data queries (CSVs, EML,
visualizations). Over the limit a client gets 429 with Retry-After, and the
refusal is logged with the path but not the query string.
Counts are kept in Rails.cache, which is memcached in production, so all
Puma workers share them; if memcached is down nothing is limited. The limits
can be changed with RATE_LIMIT_PER_SECOND and RATE_LIMIT_PER_MINUTE, or
switched off with RATE_LIMITING=off, without a deploy. They are off in the
test environment except in the specs for them.
Gemfile.lock needs regenerating for rack-attack.
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com