Security for a Rails shop: updates, dependencies and the attacks that actually happen
TL;DR
Difficulty: Advanced
A Rails shop stays secure through a routine, not a one off project.
- Check every month that Ruby, Rails and Solidus are still supported. Rails gives each series two years of security fixes, Solidus 18 months.
- Patch critical and high fixes within 14 days, the rest monthly, and measure your mean time to patch.
- Run bundler audit, a JavaScript audit and Brakeman on every build and weekly on a schedule, and still read the advisories: copied storefront code and operating system packages slip past every scanner.
- Keep the Rails defaults against CSRF, XSS, SQL injection and mass assignment on, and test your authorisation rules.
- Rate limit login, password reset and payment, check that the IP address you limit by is real, add a content security policy, lock the admin down and practise rotating secrets.
- When card testers abuse the checkout, refund fast, alert on decline spikes and write the incident down.
What to read first
Nothing in a shop's own code has to change for it to become vulnerable. Frameworks publish new flaws, versions fall out of support, and scripts abuse features that work exactly as built. This chapter sets out the monthly routine that keeps a Rails and Solidus shop secure, with the real advisories of 2026, the code, and one invented card testing night worked through to the euro.
Security is a routine, not a project
A shop that went live safely in 2024 is not safe in 2027 by default. Nothing in its own code has to change for it to become vulnerable. The frameworks it runs on publish new flaws, the versions it runs fall out of support, and attackers find new ways to abuse features that work exactly as designed. Security for a Rails shop is therefore not a project you finish. It is a routine you run, every month, for as long as the shop exists.
This chapter is about that routine. It covers the three ways a small shop actually gets hurt: a known flaw in a dependency, a flaw in the shop's own code, and the abuse of a working feature such as the payment step. For each I show what to run, what to read and what to change, with the code. The example is the invented shop of this series, Shannonside Home in Limerick (shannonsidehome.example): about 1,400 products, 110,000 sessions and 1,980 orders a month, running Ruby on Rails and Solidus on two application servers and one managed PostgreSQL database, deployed with Kamal. Niamh owns it. Callum, the developer, looks after operations part time.
Where this chapter touches the law (data protection and the EU Cyber Resilience Act), it is general information, not legal advice. Every date and version below was read from its official source on 23 November 2026, and I give the source each time, because these dates move.
This chapter assumes you have read how to know your shop is broken before your customers tell you, because several defences here end in an alert. A later chapter in this series covers upgrading Rails and Solidus without fear. Here the focus is staying patched inside the versions you have, and knowing when that stops being possible.
Example: three ways Shannonside can get hurt
Take three events, all invented for this series, and all of a kind that happens to real shops.
- A flaw in a dependency. The Rails team publishes a security release. Until Callum deploys it, anyone who reads the advisory knows how to attack every Rails shop that has not updated. Shannonside did nothing wrong, it just has not updated yet.
- A flaw in Shannonside's own code. Two years ago Callum wrote a small search filter that builds an SQL string from what the customer typed. It works. It is also an open door, because a crafted search term can read other tables.
- The abuse of a working feature. On a Saturday night a script sends 2,460 payment attempts through the checkout in two and a half hours to find out which stolen card numbers still work. Every part of the checkout behaves exactly as built.
The first is solved by patching, the second by reading your own code with tools and reviews, the third by limits and monitoring. The rest of this chapter takes them in that order, because that is the order in which they are least expensive to prevent.
Most attacks on a small shop are automated, and size does not protect you
The first objection I hear is "who would attack a homeware shop in Limerick?" Nobody, in person. The attacks that reach small shops are run by scripts that try every shop they can find. They do not choose a target, they find one that has not patched or not limited.
The most precise recent figures on patching come from next door. The UK government's Cyber security breaches survey 2025/2026, published on 30 April 2026, found that 43% of businesses identified a breach or attack in the previous 12 months, 42% of micro and 46% of small businesses among them1. The same survey found that only 34% of businesses had a policy to apply software security updates within 14 days1. That second number is the one that matters for this chapter, because 14 days is exactly the deadline set by Cyber Essentials, the UK government's certification scheme. Its requirements, version 3.3 of April 2026, say that software must be "licensed and supported", removed when it becomes unsupported, and updated within 14 days of release when the update fixes a vulnerability the vendor rates critical or high risk, or one with a CVSS v3 base score of 7 or above2. The Common Vulnerability Scoring System (CVSS) is the standard 0 to 10 severity score that most advisories carry.
So the bar is not secret and not high: run supported versions, and install the serious fixes within two weeks. Two thirds of businesses do not have even that as a rule.
Example: what "14 days" means for Shannonside
Say a high severity Rails fix is published on a Wednesday. Fourteen days later is the Wednesday two weeks on. If Callum's routine runs only on the first Tuesday of every month, and the fix appears the day after that Tuesday, it waits 27 days for the next run. That is almost twice the Cyber Essentials limit. A monthly routine alone is therefore not enough. It needs a second, faster lane for critical and high fixes, which is exactly what the routine below has.
What "supported" means for Ruby, Rails and Solidus
Every piece of software in a Rails shop has a support window. Inside it, the maintainers publish fixes. Outside it, a new flaw stays open in your version for good, and the only fix is an upgrade. So the first security question is not "are we patched?" but "are we on versions that still get patches?"
Rails publishes its maintenance policy. Each minor release series (8.0, 8.1 and so on) gets bug fixes for one year and security fixes for two years after its first release3. On the Rails maintenance page, read on 23 November 2026, the supported series for security fixes were 8.1, until 10 October 2027, and 8.0, until 7 November 20264. Everything older is out. The page is blunt about what that means: when a series is no longer supported, "it's your own responsibility to deal with bugs and security issues"4.
Ruby publishes its branches page. On the same day it listed Ruby 4.0 and 3.4 in normal maintenance, Ruby 3.3 in what it calls legacy maintenance, with an expected end of life on 31 March 2027, and Ruby 3.2 as end of life since 1 April 20265.
Solidus has its own security policy: each version gets security patches for 18 months (540 days) after its first release. The table on the Solidus security page listed v4.8 (supported until 1 April 2028), v4.7 (until 8 October 2027) and v4.6 (until 3 March 2027) as supported, and v4.5 as end of life since 14 August 20266.
| Component | Supported series on 23 November 2026 | End of security support | Source |
|---|---|---|---|
| Rails | 8.1 | 10 October 2027 | Rails maintenance page |
| Rails | 8.0 | 7 November 2026 | Rails maintenance page |
| Ruby | 4.0, 3.4 | not yet announced | Ruby branches page |
| Ruby | 3.3 | 31 March 2027 (expected) | Ruby branches page |
| Solidus | 4.8 | 1 April 2028 | Solidus security policy |
| Solidus | 4.7 | 8 October 2027 | Solidus security policy |
| Solidus | 4.6 | 3 March 2027 | Solidus security policy |
Notice how close some of these dates sit to this chapter's publication on 16 March 2027. A shop that was fully supported at Christmas can be out of support on two fronts by Easter without anyone touching it.
Example: Shannonside's applications on 16 March 2027
Callum adds an end of life check to the routine and runs it for the first time, not only for the shop but for everything Shannonside runs. The main shop is current, on Rails 8.1 and Solidus 4.8.1, as in the earlier chapters of this series. The check also finds a second application nobody had thought about for years: an old wholesale ordering app for trade customers, still running, and sharing the credentials of the customer database. The wholesale app and its versions are invented for this example. The dates are the official ones above.
| Application | Component | Runs | Security support | Status on 16 March 2027 |
|---|---|---|---|---|
| Main shop | Rails | 8.1 | until 10 October 2027 | supported |
| Main shop | Solidus | 4.8 | until 1 April 2028 | supported |
| Wholesale app | Ruby | 3.3 | until 31 March 2027 (expected) | 15 days left |
| Wholesale app | Rails | 7.1 | ended: the 7.1 series started on 5 October 2023, so the two year rule ended it in October 2025 | out of support |
| Wholesale app | Solidus | 4.5 | ended 14 August 2026 | out of support |
The first release of Rails 7.1 was 7.1.0 on 5 October 2023, and its last release was 7.1.6 on 28 October 2025, according to RubyGems7. Two years after the first release is October 2025, which matches. So the wholesale app has been running an unsupported Rails for about five months and an unsupported Solidus for seven. Nothing broke, which is exactly why nobody noticed. And because it shares the customer database credentials, a flaw in the forgotten app is a flaw in the shop's data.
What did the wholesale app miss? The next section answers that with real advisories. The fix, upgrading one step at a time, is the subject of a later chapter in this series. The point here is that the end of life check belongs in the monthly routine, not in someone's memory.
Security releases arrive in batches, so plan for them
A security release is a new version that contains only security fixes. Rails marks them with a fourth version digit: 8.1.4.1 is the security release on top of 8.1.4. According to the Rails security policy, fixes are prepared for all supported releases, held back until an agreed date, and then published together with an announcement8. Solidus works the same way: fixes are prepared for every supported version and published on the same day as the advisory, the mailing list post and the new gems6.
The real pattern in 2026 shows why a routine needs slack. I counted the advisories each project published on GitHub in 2026, up to 23 November910.
Three things stand out. First, the batches are uneven: ten low severity fixes in March, then a single critical one in July, then 21 at once in November. Second, Solidus published 21 advisories in nine weeks between September and November, after none since 2022. Third, the two projects published within a day of each other in November, so a shop running both had 31 advisories to read in one week.
Example: what Shannonside's wholesale app missed in 2026
For the main shop on Rails 8.1 and Solidus 4.8, the 2026 advisories meant patch releases and nothing more: the November Rails security release and Solidus 4.8.1, each a small update through the routine below. The wholesale app runs Rails 7.1 and Solidus 4.5, both out of support. Here is what that meant for three of the 2026 advisories, taken straight from the advisory texts.
The critical Rails advisory of 29 July 2026 (CVE-2026-66066) describes a flaw in Active Storage image variants: an attacker who can upload a crafted image may read arbitrary files from the server, including the process environment with secret_key_base and other credentials11. Fixed versions were published for 7.2, 8.0 and 8.1. The affected range starts below 7.2, so Rails 7.1 is affected and has no fixed version at all. The advisory also notes that the libvips library on the server must be at least version 8.13, which no gem update can deliver.
The Solidus advisory about arbitrary payment amounts (GHSA-c2fq-w6qj-3hj4) says two API endpoints let a caller set a payment to any amount, which could let a shop ship orders it was never fully paid for12. It was fixed in 4.6.3 and 4.7.1. For versions below 4.6, the patched version field is empty: the only help is the workaround the advisory describes, which includes making sure Spree::Config[:require_payment_to_ship] is true.
The Solidus advisory about account enumeration on the password reset page (GHSA-mhwq-2v9w-r659) says in bold that "Upgrading the Solidus gem does not fix existing stores", because the storefront code was copied into each application when it was generated13. Every shop has to patch its own UserPasswordsController, whatever version it runs, the main shop included.
So for the wholesale app, Callum works through three different kinds of fix: one that needs an upgrade (Rails 7.1 has no patch), one that needs a configuration workaround until the upgrade, and one that needs a code change in Shannonside's own repository, which no version bump would ever have delivered.
Callum also triages reachability. Trade customers cannot upload images in the wholesale app, only staff can, so the Active Storage flaw needs a staff account to exploit. That lowers the urgency from "tonight" to "this week". It does not remove the need to fix it: staff accounts get phished too, and the file read would expose the customer database credentials the app shares with the shop. Until the upgrade, Callum gives the wholesale app its own database user with access only to the tables it needs, and puts it behind the same network restriction as the admin.
The monthly routine, and the fast lane next to it
Here is the routine I recommend for a shop of Shannonside's size. It has a fixed monthly run and a fast lane for anything critical or high that is reachable in the shop. Everything goes through the same test gate and the same deploy, because a security fix that breaks the checkout is its own incident.
Where do the announcements come from? Rails asks everyone to subscribe to the Rails Security Announcements section of its forum, which it describes as "very low traffic"8. Solidus recommends GitHub's alerts for vulnerable dependencies or its security mailing list6. Ruby publishes its security news on the Ruby website. Subscribing takes ten minutes and is the single most useful thing on this page.
The rebuild step matters more than it looks. A Kamal deploy ships a Docker image, and that image contains operating system packages such as libvips, OpenSSL and the PostgreSQL client. The July Rails advisory needed a newer libvips, and no Ruby tool would have told Callum. Rebuilding the image from an updated base image every month, not only when the Gemfile changes, keeps those packages current. The deploy itself is covered in the Kamal chapter of this series.
For the Ruby side, the Rails security guide gives one precise instruction: update a vulnerable gem with bundle update --conservative gem_name, which updates that gem without pulling every other gem forward14. That keeps a security fix small enough to review.
I put every release, a security fix included, through a test gate and a release register. The test gate means nothing deploys unless the full suite passes. The register records what changed, why and when, which is also the evidence you need later, as the article on release registers and security testing per release explains.
Example: Callum's time budget for the routine
All figures are invented for Shannonside. A normal monthly run looks like this.
| Step | Minutes |
|---|---|
| Read announcements and Dependabot alerts, triage | 30 |
Update branch: bundle update --conservative, JavaScript updates, image rebuild | 40 |
| Audits and Brakeman in continuous integration, read the results | 15 |
| Full test suite, review failures | 35 |
| Deploy, smoke test, release register entry | 20 |
| End of life check | 10 |
| Total | 150 |
Two and a half hours a month, or 30 hours a year. At an internal cost of €52 an hour for Callum's time, that is €1,560 a year. Fast lane runs come on top. In 2026 there would have been four of them (the July critical, the high ones in October and twice in November), at about two hours each, so another €416. About €1,976 a year in total, before any upgrade project.
Measure how long you stay exposed
You cannot manage what you never measure. The one number I would track for patching is the mean time to patch: on average, how many days pass between an advisory being published and the fix running in production.
Here is the mean time to patch in days, is the number of advisories that applied to the shop in the period, is the date the fix for advisory went live, and is the date advisory was published. The idea of a mean is explained in Foundations: mean. Track the worst single case as well, because one advisory left open for three months matters more than a good average.
Example: Shannonside's mean time to patch after the routine starts
Callum records six advisories that applied to Shannonside in the first quarter of the new routine. They are invented, labelled A to F, with the days between publication and deployment.
| Advisory | Severity | Lane | Days to deploy |
|---|---|---|---|
| A | high | fast | 2 |
| B | medium | monthly | 13 |
| C | low | monthly | 13 |
| D | critical | fast | 1 |
| E | medium | monthly | 22 |
| F | low | monthly | 22 |
So days. More useful is the split by lane: the two serious ones took 1 and 2 days, well inside the 14 day bar, while medium and low ones waited up to 22 days for the monthly run. That is an informed choice, and it is written down, which is what an insurer or a payment provider will ask about.
Dependency auditing: bundler audit, Dependabot and the JavaScript side
A Rails shop does not only run Rails. Shannonside's Gemfile.lock lists well over a hundred gems, most of them pulled in by other gems. Any of them can carry a flaw. Reading every advisory by hand does not scale, so tools compare your locked versions against databases of known flaws.
The bundler-audit gem checks Gemfile.lock for gem versions with known vulnerabilities and for insecure gem sources (http:// and git://), using the community ruby advisory database. Its README notes that the check itself "does not require a network connection", and that bundle-audit check --update refreshes the database first, which is what you want in continuous integration15. Rails 8.1 ships it in new applications: a bin/bundler-audit script, a config/bundler-audit.yml file with an ignore list for advisories that do not apply, and a step in the generated continuous integration workflow16. For an older application, add the gem and copy the same two files.
The JavaScript side needs its own audit. With importmap, Rails generates a bin/importmap audit step16. With npm, npm audit sends a description of your dependencies to the registry and reports known vulnerabilities, and --audit-level sets the lowest severity that fails the run17. The npm documentation adds a warning worth repeating about npm audit fix --force: it may install major versions outside your stated ranges, and "If you don't have a clear idea of what you want to do, it is strongly recommended that you do not use this option!"17
GitHub's Dependabot opens pull requests for outdated or vulnerable dependencies. It is configured in .github/dependabot.yml. Two options keep it useful for a shop: groups, which bundle related updates into one pull request, and a cooldown, which waits a few days before proposing a brand new version. The documentation says the default cooldown is three days and that it does not apply to security updates18, which is the right way round: a new version waits, a security fix does not.
# .github/dependabot.yml
version: 2
updates:
- package-ecosystem: "bundler"
directory: "/"
schedule:
interval: "weekly"
cooldown:
default-days: 7 # new versions wait a week, security fixes do not
groups:
rails:
patterns: ["rails", "action*", "active*", "railties"]
solidus:
patterns: ["solidus*"]
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
The rails group keeps all the Rails component gems (actionpack, activerecord and so on) in one pull request, because they are released together and must move together.
Example: the three blind spots of every scanner
In its first year of auditing, Callum finds that the scanners catch most problems but miss three kinds, all real and all described above.
- Copied code. The Solidus storefront is generated into the application, so its controllers are Shannonside's code, not a gem. The password reset and guest token advisories of autumn 2026 did not appear in any gem audit, because no gem version was wrong1319. Only reading the advisory found them.
- Operating system packages. libvips, OpenSSL and the database client live in the Docker image, not in
Gemfile.lock. Only the monthly image rebuild, and reading the advisory, covers them. - Unsupported versions. A scanner says "update to 7.2.3.2 or later". It does not say that this is a minor version jump with its own upgrade work. Only the end of life check turns that into a plan.
That is why the routine starts with reading, not with running a tool.
Brakeman reads your own code
Dependency audits only look at other people's code. Brakeman looks at yours. Its README describes it as "a static analysis tool which checks Ruby on Rails applications for security vulnerabilities"20. Static analysis means it reads the source without running it, so it can warn about an SQL string built from request parameters long before anyone sends a malicious one. Rails 8.1 generates a bin/brakeman script in new applications and puts it into the continuous integration workflow by default16.
Every warning carries a confidence level, high, medium or weak, which Brakeman describes as "a rough estimate of how certain the tool is that a given warning is actually a problem"20. False positives happen. Brakeman's way to handle them is an ignore file at config/brakeman.ignore, created interactively with brakeman -I, with a note for each entry20. The note matters: an ignore without a reason is a vulnerability you have decided to forget.
Example: the search filter Brakeman flags
Here is the invented filter from the start of this chapter, in Shannonside's own code.
# app/models/spree/product_decorator.rb (before)
def self.name_contains(term)
where("spree_products.name ILIKE '%#{term}%'") # term comes from params[:q]
end
Brakeman reports an SQL injection warning with high confidence on this line, because a request parameter is interpolated into an SQL fragment. A search for x%' OR 1=1 -- would change the query's meaning. The fix uses a placeholder, so the database treats the term as data, and sanitize_sql_like, which escapes the % and _ characters that have a special meaning inside LIKE patterns21. The fixed method:
# app/models/spree/product_decorator.rb (after)
def self.name_contains(term)
pattern = "%#{sanitize_sql_like(term.to_s)}%"
where("spree_products.name ILIKE ?", pattern)
end
The rewritten line has no interpolation into SQL, Brakeman's warning disappears, and a test proves that a search for 100% finds products named "100% linen" and nothing else.
One continuous integration step for all of it
The audits are only worth something if they run without anyone remembering to. This GitHub Actions workflow runs them on every pull request, on every push to the main branch, and once a week on a schedule. The schedule is the important part: a new advisory can turn yesterday's green build red without a single commit.
# .github/workflows/security.yml
name: Security
on:
pull_request:
push:
branches: [ main ]
schedule:
- cron: "0 6 * * 1" # every Monday at 6am UTC, catches new advisories
jobs:
scan_ruby:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Known vulnerabilities in gems
run: bin/bundler-audit check --update
- name: Static analysis of the shop's own code
run: bin/brakeman --no-pager --exit-on-warn
scan_js:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Known vulnerabilities in JavaScript packages
run: bin/importmap audit # with npm instead: npm audit --audit-level=high
The job layout follows the workflow that Rails 8.1 generates for new applications, which runs bin/brakeman --no-pager, bin/bundler-audit and bin/importmap audit in the same way16. If your shop uses Kamal's pre build hook as its test gate, as the Kamal chapter describes, run the same three commands there too, so a laptop deploy cannot skip them.
Example: what the tools found in Shannonside's first year
The numbers are invented. Callum logs every finding for a year and marks whether it was a real issue for Shannonside or not applicable (a false positive, or a flaw in code the shop never reaches).
Of 32 findings, 23 were real. The gem audit found the most, which is why it runs on every build. But 4 of the 23 real issues came from reading advisories, and no tool would ever have reported them. Brakeman found fewer real issues than false positives, which is normal for a mature codebase, and its two real ones (the search filter above and an unescaped admin note) were both in code Callum wrote himself.
The classics from the Rails security guide still matter
The Rails security guide is long and worth reading once in full14. Rails protects you by default against most of the classic attacks, as long as you do not switch the protection off. Here are the five that matter most in a shop, each with the way it fails in practice. The Solidus advisories of 2026 are useful here, because they show the same mistakes in a mature, reviewed codebase.
Cross site request forgery
Cross site request forgery (CSRF) tricks a logged in user's browser into sending a request to your shop from another site. Rails defends with a token in every form, and the guide confirms forgery protection is on by default in new applications14. It fails when someone adds skip_forgery_protection to a controller to make a form or webhook work and forgets to scope it. In a shop, payment provider webhooks legitimately skip the token, so they must verify the provider's signature instead. Stripe calls this out explicitly: verify webhook signatures22.
Cross site scripting
Cross site scripting (XSS) gets an attacker's script to run in someone else's browser on your domain. Rails escapes everything a view prints by default. It fails at raw, html_safe and any helper that returns unescaped HTML. The Solidus advisory GHSA-x943-j5hw-mr2w of October 2026 is a textbook case: the product description helper rendered the description as raw HTML, so a script stored in a description ran for every visitor, and the advisory describes a demonstrated account takeover through it23. Planting it needed a back office account. That is still a real risk, because a phished staff password is a common way in.
SQL injection
SQL injection was the example above. Active Record protects every query built with hashes and placeholders. It fails wherever a string is interpolated into SQL, in where, order, pluck or find_by_sql. Brakeman finds most of these.
Mass assignment
Mass assignment means accepting a whole hash of attributes from a request and writing it to a model. Rails' strong parameters require you to list the permitted attributes. It fails at permit!, which allows everything. The Solidus advisory GHSA-q5w8-wf94-jc29 of November 2026 describes exactly this: the admin base controller used permit! as a fallback, so an admin could set attributes the forms never showed, such as deleted_at or foreign keys24. The payment amount advisory above was also a permitted attributes problem12.
Secrets in the repository
Rails keeps secrets in config/credentials.yml.enc, encrypted with config/master.key or the RAILS_MASTER_KEY environment variable. The encrypted file can live in version control "as long as the master key is kept safe"14. It fails when the master key, or a raw API key, lands in a commit, a log or a chat message. The filter_parameters list that Rails generates (password, email, token, secret, cvv and others) keeps such values out of the logs16; extend it rather than shorten it.
Authorisation, the one the framework cannot do for you
The OWASP Top 10, the Open Worldwide Application Security Project's list of the most critical web application risks, puts broken access control first in its 2025 edition25. It is also the largest group among the Solidus advisories of 2026: a back office user able to make themselves an administrator (GHSA-rw5f-4cm4-pc4m), a customer able to cancel another customer's returns, a shipment transfer without an authorisation check1026. No framework default helps here, because only you know who may do what. The defence is a test for every rule: "a customer cannot see another customer's order", "a user manager cannot assign the admin role". I write those tests first, which is the whole idea of test driven development in Rails.
Example: Shannonside's checklist against the classics
Callum turns the five classics plus authorisation into checks that run on every build or every month.
| Risk | Check | How often |
|---|---|---|
| CSRF | grep for skip_forgery_protection, each hit verifies a signature | every build |
| XSS | Brakeman, plus grep for raw and html_safe in views | every build |
| SQL injection | Brakeman | every build |
| Mass assignment | grep for permit!, plus Brakeman | every build |
| Secrets | secret scanning on the repository, filter_parameters reviewed | monthly |
| Authorisation | one request spec per rule, including the Solidus roles in use | every build |
Hardening the logins
Two kinds of login matter in a shop: customers and staff. Customers need sensible rules that do not cost conversions. Staff need much stricter ones, because a staff account can change prices, refund orders and export customer data.
Most Solidus shops authenticate with the solidus_auth_devise extension. Its Spree::User model enables the Devise modules for database authentication, registration, password recovery, remember me, tracking, validation and encryption, plus confirmation when configured. Lockable, the Devise module that locks an account after failed attempts, is not among them27. Without it, or a rate limit, nothing slows down a script guessing passwords.
For the password rules themselves, the clearest modern reference is NIST Special Publication 800 63B, revision 4, from the US National Institute of Standards and Technology. It was written for US government systems, but its password rules are widely used as good practice. It requires a minimum of 15 characters for passwords used on their own and at least eight when they are part of multi factor authentication, says systems "SHALL NOT impose other composition rules" such as mixing character types, and "SHALL NOT require subscribers to change passwords periodically"28. It requires checking new passwords against a blocklist of common and compromised values, and limiting failed attempts on an account28.
The Rails security guide adds a point that shops often miss: the forgotten password page must not reveal whether an email address has an account, because that lets an attacker build a list of customers to attack14. That is precisely what the Solidus advisory GHSA-mhwq-2v9w-r659 fixed in the storefront's password reset13.
Example: Shannonside's login rules
Callum sets these rules. The numbers are his choices for this example.
- Customers: at least 12 characters, checked against a list of breached passwords, no composition rules, no forced changes. The 12 is a compromise below NIST's 15 for a single factor, chosen so that checkout sign ups do not suffer, and written down as a decision.
- Customers: 10 failed logins per email in 20 minutes, then a pause. The same generic message ("email or password not correct") whether the account exists or not.
- Staff: multi factor authentication (MFA) for every back office account, a separate login from the storefront, 15 character passwords, and the admin reachable only from the office and Callum's network (see the admin section below).
- Password reset: the same message for every address, whether known or not, with the storefront patch from the Solidus advisory applied.
Rate limiting: Rails rate_limit and Rack::Attack
A rate limit says "this client may do this action at most N times in this period". It is the least expensive defence against password guessing, card testing and sign up spam, and since Rails 7.2 it is built into Rails.
The rate_limit method takes to: (the maximum number of requests) and within: (the period), and counts per IP address unless you pass your own by:. Requests over the limit raise ActionController::TooManyRequests, which Rails answers with status 429 unless you pass with:. Several limits on one controller need a name: each29. The counters live in the Rails cache store. That detail matters for Shannonside: with two application servers, the cache must be shared between them, or each server counts separately and the real limit doubles. A database backed Solid Cache, covered in the chapter on the Rails 8 Solid libraries, is shared, so it works.
# app/controllers/checkouts_controller.rb (excerpt, Solidus starter storefront)
class CheckoutsController < CheckoutBaseController
# The payment step is where card testing happens. @order is loaded by
# CheckoutBaseController#load_order, which runs before these filters.
rate_limit to: 3, within: 10.minutes, only: :update,
if: -> { params[:state] == "payment" },
by: -> { @order.number },
with: -> { redirect_to checkout_state_path("payment"), alert: "Too many payment attempts. Please wait a few minutes." },
name: "payment per order"
rate_limit to: 10, within: 1.hour, only: :update,
if: -> { params[:state] == "payment" },
name: "payment per ip"
# ... the generated actions stay as they are
end
# app/controllers/user_sessions_controller.rb (excerpt)
class UserSessionsController < Devise::SessionsController
rate_limit to: 10, within: 20.minutes, only: :create,
by: -> { params.dig(:spree_user, :email).to_s.strip.downcase },
name: "logins per email"
rate_limit to: 30, within: 20.minutes, only: :create, name: "logins per ip"
end
The payment limits key on the order number first, because a card tester can rotate IP addresses far more easily than it can afford a new order for every card. The login limit keys on the normalised email, so a botnet spreading its attempts across thousands of addresses still hits the per email limit.
Rack::Attack is the other common tool. It is Rack middleware, so it runs before routing and before any controller, and it adds safelists, blocklists and the Fail2Ban style "block after repeated bad requests" filter30. Its README makes the same warning about storage: an in memory store is "mostly ineffective" with several processes, because each counts on its own30. Use rate_limit for rules that need the controller's knowledge (the order, the state), and Rack::Attack for broad rules at the door. A full set of Rack::Attack rules for a Solidus shop, including how to treat verified AI agents, is in good bots, bad bots.
The address you limit by must be the real one
A per IP limit is only as good as request.remote_ip. Behind a proxy, Rails reads the client address from forwarding headers. If it reads the proxy's address instead, every customer shares one address, and the limit throttles the whole shop at once. If it trusts a header the client can set, an attacker chooses their own address and walks past the limit.
Both have happened. Kamal's proxy documentation says that with SSL switched on, kamal proxy stops forwarding the X-Forwarded-For and X-Forwarded-Proto headers unless forward_headers: true is set, which it recommends only "If you are behind a trusted proxy"31. And the Rails advisory CVE-2026-126083 of November 2026 describes how, in Rails 8.1.0 to 8.1.4 with Rack 3, a client supplied Forwarded header could spoof request.remote_ip, and so possibly bypass access controls and rate limits that count by client address, the default by: of rate_limit included32.
Example: checking the address before trusting the limit
Callum logs request.remote_ip for one hour of normal traffic on Shannonside. The numbers are invented.
| What he sees | What it means | What he does |
|---|---|---|
| 1,840 requests from 1 address, 172.18.0.2 | Rails sees the proxy, not customers | fix forwarding first, or every limit is shop wide |
| 1,840 requests from 410 addresses | Rails sees real clients | per IP limits work |
On Shannonside the first row appears after a change to the proxy setup. A limit of 10 payment attempts per IP per hour would then have blocked every customer after the tenth payment of the hour. Callum fixes the forwarding, reruns the check, sees the second row, and only then enables the per IP limits. It is a five minute check that saves a self inflicted outage.
A content security policy limits what a script can do
A content security policy (CSP) is a response header that tells the browser which sources of scripts, styles, frames and connections a page may use. If an attacker manages to inject a script tag that loads from their own server, a strict policy makes the browser refuse to run it. It is the second line of defence behind output escaping, and it matters most on the checkout, where a skimming script would read what customers type. The article on PCI DSS explains why the scripts on your payment page are part of your card security obligations.
Rails generates config/initializers/content_security_policy.rb in every new application, fully commented out16. The guide recommends nonces instead of 'unsafe-inline': a nonce is a random value Rails adds to each allowed inline script and to the header, so only those scripts run14. It also supports a report only mode, which reports violations without blocking anything, for moving an existing shop over safely14. Stripe publishes the exact hosts its scripts need: for Stripe.js, https://js.stripe.com and https://*.js.stripe.com for scripts and frames, https://hooks.stripe.com as a frame source for payment methods with redirects such as 3D Secure, and https://api.stripe.com for connections22.
# config/initializers/content_security_policy.rb
Rails.application.configure do
config.content_security_policy do |policy|
policy.default_src :self
policy.base_uri :self
policy.form_action :self
policy.frame_ancestors :none # nobody may frame the shop
policy.object_src :none
policy.font_src :self, :data
policy.img_src :self, :data, "https://*.stripe.com"
policy.style_src :self
policy.script_src :self, "https://js.stripe.com", "https://*.js.stripe.com"
policy.frame_src "https://js.stripe.com", "https://*.js.stripe.com", "https://hooks.stripe.com"
policy.connect_src :self, "https://api.stripe.com"
policy.report_uri "/csp_reports"
end
# A fresh nonce per request for the few inline scripts that remain.
config.content_security_policy_nonce_generator = ->(request) { SecureRandom.base64(16) }
config.content_security_policy_nonce_directives = %w[script-src]
# Start in report only mode; switch to false once the reports are clean.
config.content_security_policy_report_only = true
end
Two notes. First, the guide warns that a random nonce per request changes the ETag on every response and so breaks conditional GET caching. The session ID is the alternative it offers14. For a shop with full page caching on product pages, read that passage before choosing. Second, analytics and marketing tags need their own hosts in the policy. On my own site those scripts only load after consent, and the policy lists them anyway, so they work when consent is given.
Example: Shannonside moves from report only to enforced
The numbers are invented. Callum runs the policy in report only mode for two weeks and counts the reports by cause.
| Cause | Reports | Action |
|---|---|---|
| Browser extensions injecting their own scripts | 1,212 | ignore, they are the customer's own software |
| An inline script in the newsletter sign up snippet | 96 | move into a JavaScript file |
| An old embedded video on a buying guide page | 32 | add the video host to frame_src |
| Total | 1,340 |
After the two fixes, a third week brings only extension reports. Callum sets content_security_policy_report_only to false and deploys. From then on, a new script added to a page without a policy change shows up in the reports within hours, which is exactly the early warning the payment page needs.
Protecting the admin
The Solidus admin can change prices, issue refunds, export customers and create staff accounts. It deserves more protection than the storefront, and the Rails security guide's section on admin interfaces gives the menu: roles that limit what each person can do, separate login credentials for the admin, and limiting the admin to certain source IP addresses, which the guide describes as not watertight but a great barrier14.
The 2026 Solidus advisories show why roles must be tested, not assumed. One of them let a user with only the user management permission set make themselves a full administrator26. Least privilege, giving each person only the role they need, limits the damage of a phished password. Patching limits the damage of a flawed role.
Example: Shannonside's admin, before and after
| Control | Before | After |
|---|---|---|
| Who has the admin role | Niamh, Callum and two customer service staff | Niamh and Callum only |
| Customer service | admin role | a custom role with orders, returns and customers, no settings or users |
| Sign in | same login form as customers | separate admin login with MFA |
| Network | open to the internet | only the office address and Callum's VPN, enforced in a Rack::Attack blocklist for /admin |
| Review | never | quarterly list of staff accounts and roles, leavers removed the same day |
Two customer service staff losing the admin role changes nothing in their daily work, and it removes two of the four accounts that could export every customer's address.
Secrets and their rotation
A secret is anything that grants access: secret_key_base, the Rails master key, the database password, the Stripe and PayPal API keys, the 3PL warehouse's SFTP password, the Google Ads and Meta tokens. In a Kamal deploy they reach the servers through .kamal/secrets, as the Kamal chapter shows.
Rotation means replacing a secret with a new one and retiring the old. Stripe recommends doing it periodically for a practical reason: periodic rotation "confirms that you know where each key is used and that your team can replace a key on short notice"33. Stripe also recommends restricted API keys with only the permissions a component needs, and never putting secret keys in source code33.
The July 2026 Rails advisory shows when rotation stops being routine. After a possible file read, it says: "treat every secret readable by the application process as potentially exposed and change it", listing secret_key_base, the master key and everything it decrypts, storage credentials, database credentials and every third party token11. It adds that changing secret_key_base expires all active sessions, and that an exposed secret must not be kept as a fallback11. A shop that has never rotated anything learns how during an incident, which is the worst time.
Rails can rotate cookie settings so that old cookies still read while new ones are written in the new format, through config.action_dispatch.cookies_rotations14. That is for planned changes. After an exposure, the advisory is clear that old secrets go immediately.
Example: Shannonside's yearly rotation drill
Callum runs a planned drill every January. The times are invented.
| Secret | How | Minutes | Customer impact |
|---|---|---|---|
| Stripe secret key | roll the key in the dashboard, update .kamal/secrets, deploy | 15 | none |
| PayPal credentials | new credentials, update, deploy | 15 | none |
| Database password | new password at the managed database, update, deploy | 20 | none with a rolling deploy |
| 3PL SFTP password | agree a time with the warehouse, change both sides | 25 | none |
| Google Ads and Meta tokens | reauthorise, update | 20 | none |
secret_key_base | new value in credentials, deploy | 15 | every customer and staff member logged out once |
About two hours in total. The secret_key_base step is run at 6am on a Sunday, the quietest hour, and only every second year unless there is a reason. The real output of the drill is a written list of where every secret lives, which is what Callum needs at 2am when an advisory says "change everything".
Card testing: when the checkout works exactly as built
Stripe defines card testing as fraud "where someone tries to determine whether stolen card information is valid so that they can use it to make purchases"34. A script runs many small payments through a shop to find which stolen cards still work. The shop is not the target, it is the tool. The consequences still land on the shop: disputes when some test payments succeed, a high decline rate that makes card issuers treat all your payments as riskier, possible extra fees, and strain on your servers34. Stripe lists the signs: a spike in failed or blocked payments, a spike in API requests failing with status 402, and many small payments "with nonsensical customer names and emails"34.
Stripe's checklist for an active attack has four steps: identify the activity, refund the fraudulent payments to avoid disputes, add mitigations, and monitor whether they work34. It recommends a combination of mitigations rather than one, and says plainly that "simple firewall rules or filters based on a single heuristic such as IP addresses are usually not sufficient"34. The combination it describes includes CAPTCHA on every request that can validate a card, limiting access to the payment form, rate limits on the payment and checkout flow, and Radar rules on velocity where your plan includes them34.
Example: the Saturday night attack on Shannonside
Everything in this example is invented. In the early hours of Sunday 7 February 2027 a script attacks Shannonside's checkout. It creates guest orders for the lowest priced product, a set of tea lights at €4.95, and cycles through stolen cards on the payment step. Here are the payment attempts in half hour buckets.
Across the night there are 2,460 attempts, 2,376 declined and 84 successful. Outside the attack window, between midnight and 1.30am and after 4.30am, 11 payments succeed, all normal customer orders. Inside the window, from 1.30am to 4.30am, 2,448 attempts bring 73 successes, every one a €4.95 tea light order with a nonsense name. The decline rate in the window is
a decline share of , or 97%, against Shannonside's normal decline rate of about 4% (also invented). The 73 test charges total 73 × €4.95 = €361.35.
What did it cost? The expected cost of an attack has three parts: fees that are not returned when a payment is refunded, disputes on test charges that are not refunded in time, and staff time.
Here is the cost of the attack, the number of successful test charges, the fee per payment that is not returned on a refund, the number of test charges not refunded before the cardholder notices, the probability that such a charge becomes a dispute, the cost of one dispute (the dispute fee plus the lost payment), the staff hours spent, and the cost of one staff hour. The idea of weighting a cost by its probability is explained in Foundations: expected value.
With invented values for Shannonside's provider and staff ( = €0.25, = €20 + €4.95 = €24.95, = 0.3, = 6, = €52), there are two cases. If Niamh refunds all 73 test charges on Sunday morning, :
If nobody notices until the disputes arrive, :
So falls from €876.66 to €330.25 when Niamh refunds fast, and it also keeps the dispute count down, which matters more in the long run than the money, because card schemes put merchants with high fraud and dispute rates into monitoring programmes34. The decline spike may also make issuers more cautious with Shannonside's genuine customers for a while, a cost no formula here captures.
Example: what changed after the attack
Callum and Niamh write a short postmortem on the Monday and make five changes.
- Alert. A business alert fires when more than 25% of payment attempts in 15 minutes are declined, with at least 20 attempts. It would have woken Callum at 1.45am instead of Niamh finding it at 9am. How to build such alerts is in the monitoring chapter.
- Rate limits. The two
rate_limitrules shown above: three payment attempts per order in ten minutes, ten per IP address in an hour. In the attack, 2,448 attempts came through about 410 guest orders, roughly six cards per order. With the per order limit the script would have needed about 816 orders to try the same number of cards, and each new order is work the per IP limit also counts. - Challenge. A CAPTCHA on the payment step after the first failed payment in a session, so a real customer who mistypes once is not punished.
- Provider rules. Velocity rules at the payment provider, which see attempts across all its merchants, not only Shannonside's.
- Data. The 73 test orders are flagged in the order data, with the same rule that already excludes the roughly 40 test and staff orders a year, so they do not inflate the revenue figures. Stripe makes the same point: card testing revenue "might look like good, new customers in your data"34.
None of these alone would stop a determined attacker. Together they make Shannonside a poor tool, and card testers move on to shops that are easier.
When an attack becomes a data breach
A card testing attack uses stolen cards that belong to other people's customers. It usually exposes no personal data held by Shannonside. Other incidents in this chapter would: the guest token flaw in the Solidus storefront could let an attacker read guest orders with names, emails, addresses and phone numbers19, and the July Rails flaw could expose credentials to the whole database11.
The General Data Protection Regulation (GDPR) requires a controller to keep personal data secure with measures appropriate to the risk, which explicitly includes "a process for regularly testing, assessing and evaluating the effectiveness" of those measures (Article 32)35. A monthly routine with a written record is exactly that. When a personal data breach does happen, Article 33 requires notifying the supervisory authority without undue delay and, where feasible, within 72 hours of becoming aware of it, unless it is unlikely to result in a risk to people's rights and freedoms35. In Ireland that authority is the Data Protection Commission (DPC), which explains on its breach notification page how and when to notify36. Whatever you decide, write down the facts and your reasoning: Article 33 also requires a record of every breach, reported or not35.
Example: three incidents, three decisions
| Incident at Shannonside (invented) | Personal data affected? | Report to the DPC? |
|---|---|---|
| Card testing night, stolen cards from elsewhere | no data held by Shannonside exposed | no report, but record the incident and the reasoning |
| Guest token flaw found unpatched, logs show no exploitation | possible, but no evidence of access | usually no report after a documented check of the logs, and record it |
| Logs show guest orders read through the flaw | yes: names, addresses, phone numbers | yes, within 72 hours, and consider telling the customers |
The middle row is why logs matter: without them, "no evidence of access" is a guess. The decision belongs to Niamh as the controller, with legal advice if the case is unclear.
The Cyber Resilience Act, if you also sell software
The EU Cyber Resilience Act (CRA), Regulation (EU) 2024/2847, sets security rules for products with digital elements placed on the EU market: hardware and software sold as products, including the software that runs them. According to its Article 71, most of it applies from 11 December 2027, the reporting obligations of Article 14 from 11 September 2026, and the chapter on conformity assessment bodies from 11 June 202637. Under Article 14, a manufacturer must send an early warning of an actively exploited vulnerability in its product "within 24 hours" of becoming aware of it37.
Does it apply to a shop? Recital 12 of the regulation answers the main question: "websites that do not support the functionality of a product with digital elements" are not in its scope37. Shannonside's shop website is not a product under the CRA. It becomes relevant when a shop also makes software or connected products available on the EU market: a paid app, a downloadable plugin, a smart lamp with firmware. The full picture of who must prepare, and how, is in the article on the Cyber Resilience Act.
Example: what is in and out for Shannonside
| What Shannonside does | In CRA scope? |
|---|---|
| Runs its Solidus shop for customers in Ireland and the rest of the EU | no, a website that supports no product |
| Sells third party smart bulbs to EU customers | mainly the manufacturer's and importer's duties. A reseller has its own, more limited duties as a distributor |
| Sells its own room planning app to EU customers | yes, Shannonside would be the manufacturer |
The routine in this chapter, with its advisories, time to patch and release register, is a good part of what a manufacturer under the CRA needs anyway. The 24 hour clock is not.
OWASP ASVS as the yardstick
A routine tells you how to keep a shop patched. It does not tell you whether the shop was built securely in the first place. For that, the OWASP Application Security Verification Standard (ASVS) is the checklist I build web applications to. Its current version is 5.0.0, published on 30 May 202538. It sets out what a secure application must do, chapter by chapter, at three levels of depth. OWASP ASVS explained covers the levels, the chapters and how they are used.
Example: mapping Shannonside's routine to ASVS
Callum takes the sections of this chapter and asks, for each, which ASVS chapter it serves and whether the evidence exists.
| This chapter | ASVS area | Evidence Shannonside keeps |
|---|---|---|
| Patching and end of life | components and dependencies | release register, time to patch table |
| Brakeman and the classics | encoding, injection, validation | CI history, ignore file with reasons |
| Login rules and rate limits | authentication | configuration and request specs |
| Admin protection and roles | access control | role list, quarterly review notes |
| CSP | web frontend security | policy file, report history |
| Secrets rotation | secret management | rotation log |
The gaps that remain, such as security logging detail, become next quarter's work.
My view
Most of the security of a small Rails shop comes from three habits, not from products. First, stay on supported versions, and check the end of life dates every month, because the expensive surprise is not a new flaw but discovering you have been outside support for half a year. Second, read the advisories as well as running the scanners, because in 2026 the advisories that needed a shop's own code changed were invisible to every tool. Third, put limits and alerts on the few actions where money moves: login, password reset, payment and the admin.
I would not buy a security product before these three are in place. A web application firewall or a bot management service can help a shop that is already patched and limited. It cannot make up for a forgotten Rails 7.1 app in 2027.
And I would budget for it honestly: about 30 hours a year for the routine at Shannonside's size, plus the fast lane, plus a real upgrade every year or two. That is far less than one bad night with an unpatched flaw, and it is the part of running a shop that no customer ever sees until it is missing.
Conclusion
A Rails shop stays secure year after year through a routine: subscribe to the Rails, Ruby and Solidus announcements, patch serious flaws within 14 days and the rest monthly, and check every month that Ruby, Rails and Solidus are still supported. Run bundler audit, a JavaScript audit and Brakeman on every build and once a week on a schedule, and read the advisories too, because copied storefront code and operating system packages slip past every scanner. Keep the Rails defaults against CSRF, XSS, SQL injection and mass assignment switched on, and test your authorisation rules, because broken access control is now the top risk. Put rate limits on login, password reset and payment, check that the address you limit by is real, add a content security policy in report only mode first, lock the admin down, and practise rotating your secrets before an advisory forces you to. When the checkout is abused anyway, refund fast, alert on decline spikes, and write the incident down, because the record is both your evidence and your next improvement.
