Stack

How to security test a Rails app

Updated

Rails apps break at three points: a controller action with no before_action authorization, a find that does not go through current_user, and a permit list that includes :admin or :account_id. Test each controller action anonymously, then with another tenant's record id.

Where this class of bug actually lives in a Rails app

  • Missing before_action. Authorization lives in a callback you list per controller. skip_before_action for one action, added for a good reason, removes it for that action only — and that is the one that leaks.
  • Model.find(params[:id]). Global lookup across all tenants. current_user.invoices.find(...) is the safe form.
  • Permitted parameters. params.require(:user).permit(:name, :email, :admin) is a privilege escalation with a tidy name.
  • Mass-assignment through nested attributes. accepts_nested_attributes_for lets a request create or modify associated records you never intended to expose.

What to try first

  1. Map every route with rails routes and request each one with no session cookie.
  2. Swap a record id between two accounts and compare with a nonexistent id, as in the Django case.
  3. Send admin=true and account_id=<other> in each update form body.
  4. Check for an unscoped destroy — a DELETE with another tenant's id is the same bug with worse consequences.

A reproduction you can keep

Rails makes the id swap trivial. Run it against a read and a write:

Cross-tenant read, then the same id on a destructive route
# read
curl -sS -i https://staging.example.com/invoices/1003 -H 'Cookie: _session=***'

# destructive, same id — check whether it 200s before you run it in prod
curl -sS -i -X DELETE https://staging.example.com/invoices/1003 -H 'Cookie: _session=***'

# vulnerable: 200 and another account's invoice, then a successful delete
# fixed: 404 on both, identical to a random id

What "fixed" has to look like

Every lookup must be scoped through the current user or account, so the foreign id returns 404 and the delete is a no-op. Test both verbs: a scoped show with an unscoped destroy is a common half-fix.

Where people get this wrong

  • protect_from_forgery stops CSRF, not IDOR. Most Rails IDORs pass CSRF checks because they come from the app's own session.
  • A Pundit or CanCanCan policy that exists but is never called is documentation, not enforcement.
  • Turbo and Hotwire fetch fragments that are often rendered by an action nobody thought of as an endpoint.

What Offense does here

Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.

Questions this page answers

Does Rails protect against IDOR by default?

No. find(params[:id]) is a global lookup. Scoping through current_user is a convention you have to follow in every action.

Is strong params enough to stop mass assignment?

Only if the permit list is narrow. A permitted :admin or :account_id is the vulnerability itself.

Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.