Skip to content

Allow optional dedicated rack attack cache - #459

Open
JPrevost wants to merge 1 commit into
mainfrom
use-656
Open

Allow optional dedicated rack attack cache#459
JPrevost wants to merge 1 commit into
mainfrom
use-656

Conversation

@JPrevost

@JPrevost JPrevost commented Aug 31, 2026

Copy link
Copy Markdown
Member

Why are these changes being introduced:

Relevant ticket(s):

How does this address that need:

  • Allows for using separate dedicated cache by checking ENV and using it if present.
  • In non-production ENV, it defaults back to simply using Rails.cache for simplicity.

Developer

Accessibility
  • ANDI or WAVE has been run in accordance to our guide.
  • This PR contains no changes to the view layer.
  • New issues flagged by ANDI or WAVE have been resolved.
  • New issues flagged by ANDI or WAVE have been ticketed (link in the Pull Request details above).
  • No new accessibility issues have been flagged.
New ENV
  • All new ENV is documented in README.
  • All new ENV has been added to Heroku Pipeline, Staging and Prod.
  • ENV has not changed.
Approval beyond code review
  • UXWS/stakeholder approval has been confirmed.
  • UXWS/stakeholder review will be completed retroactively.
  • UXWS/stakeholder review is not needed.
Additional context needed to review

E.g., if the PR includes updated dependencies and/or data
migration, or how to confirm the feature is working.

Code Reviewer

Code
  • I have confirmed that the code works as intended.
  • Any CodeClimate issues have been fixed or confirmed as
    added technical debt.
Documentation
  • The commit message is clear and follows our guidelines
    (not just this pull request message).
  • The documentation has been updated or is unnecessary.
  • New dependencies are appropriate or there were no changes.
Testing
  • There are appropriate tests covering any new functionality.
  • No additional test coverage is required.

@coveralls

coveralls commented Aug 31, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 33420910360

Coverage remained the same at 98.3%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1706
Covered Lines: 1677
Line Coverage: 98.3%
Coverage Strength: 82.0 hits per line

💛 - Coveralls

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The initializer’s ENV presence check treats an empty string as set, which can configure Rack::Attack with an invalid Redis URL and cause boot/runtime failures.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds support for using a dedicated Redis cache store for Rack::Attack throttle counters so that throttling activity doesn’t evict or interfere with the app’s primary result caching in production.

Changes:

  • Introduces RACK_ATTACK_REDIS_URL support to configure Rack::Attack with its own RedisCacheStore.
  • Falls back to Rails.cache when RACK_ATTACK_REDIS_URL is not set.
  • Documents the new environment variable in the README.
File summaries
File Description
README.md Documents the new RACK_ATTACK_REDIS_URL environment variable and intended behavior.
config/initializers/rack_attack.rb Adds conditional configuration to use a dedicated Redis cache store for Rack::Attack when configured.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread config/initializers/rack_attack.rb
Comment thread README.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new Redis cache configuration disables TLS certificate verification (VERIFY_NONE), which is a security risk and should be changed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread config/initializers/rack_attack.rb Outdated
Comment on lines +62 to +65
Rack::Attack.cache.store = ActiveSupport::Cache::RedisCacheStore.new(
url: rack_attack_redis_url,
ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these changes being introduced:

* In production environments, we want to ensure that throttling does not
  purge our result caching (or vice versa).

Relevant ticket(s):

* https://mitlibraries.atlassian.net/browse/USE-656

How does this address that need:

* Allows for using separate dedicated cache by checking ENV and using it
  if present.
* In non-production ENV, it defaults back to simply using Rails.cache
  for simplicity.
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.

5 participants