Skip to content

Limit requests per client with Rack::Attack - #59

Merged
kf8a merged 3 commits into
masterfrom
feature/rack-rate-limits
Nov 8, 2026
Merged

kf8a merged 3 commits into
masterfrom
feature/rack-rate-limits

Conversation

@kf8a

@kf8a kf8a commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

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 and others added 3 commits November 7, 2026 23:05
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
@kf8a
kf8a merged commit 32df4f6 into master Nov 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants