# Rails Code Audit: A Practical Checklist for CTOs and Founders

> A Rails code audit checklist for CTOs: what to check, how to rank findings, what tools to run, and how to turn an audit into a 60/90-day plan you can act on.

- URL: https://railsdev.io/blog/rails-code-audit
- Published: 2026-11-11
- Author: Hendra Nicholas (Rails Full-Stack Developer & AI Engineer)

---

A Rails code audit is a structured review of your application — security, data integrity, performance, tests and deployment — that ends in a written, ranked plan rather than a verbal opinion. Done well, it tells you what to fix first and what it costs. Done badly, it is a generic "best practices" printout nobody acts on.

This is the checklist I use for Rails audits, organised so you can run the first pass yourself and know when you need outside eyes.

## What an audit is (and isn't)

An audit answers three questions: how much risk is in this codebase, where is it concentrated, and what should happen in the next 30, 60 and 90 days. It is not a rewrite proposal, it is not a security pen-test (though it covers the basics), and it is not a code style review.

The output that matters is a document ranked by impact and cost to fix. Everything else is supporting evidence for that document.

## Step 1: Security and secrets

Run the automated scanners ([Brakeman](https://brakemanscanner.org/) and [`bundler-audit`](https://github.com/rubysec/bundler-audit)) first; they are cheap and catch a surprising amount:

```bash
bin/brakeman --no-pager
bundle exec bundler-audit check --update
```

Then check what the scanners can't know:

- [ ] **Secrets handling**: no credentials in the repo (search for `secret_key_base`, `API_KEY`, `password` in tracked files), `config/master.key` out of git, production secrets in environment variables or Rails credentials.
- [ ] **Dependency risk**: `bundle outdated`, `bundle-audit` clean or every exception documented, no gems unmaintained for 2+ years without a reason.
- [ ] **Authentication and authorisation**: Devise/Rodauth config current, `protect_from_forgery` on, strong parameters everywhere, authorization checks (Pundit/CanCanCan) on every mutating action — not just the obvious ones.
- [ ] **Active Storage / uploads**: direct uploads validated server-side, no user-controlled paths, malware scanning if the product accepts files.
- [ ] **CORS and headers**: no wildcard CORS on authenticated endpoints; CSP, HSTS and `X-Content-Type-Options` set at the edge.

If you want the deeper story on the November 2026 advisories, my post on the [Rails security update](/blog/rails-security-update) covers the specific CVEs to check for.

## Step 2: Data integrity

Money and user data live or die here:

- [ ] **Constraints in the database**, not just validations: foreign keys, unique indexes, check constraints. Rails validations are advisory; the database is not.
- [ ] **N+1 queries**: query log clean under realistic data volume (`bullet` gem in development, rack-mini-profiler in production).
- [ ] **Missing indexes** on columns used in `WHERE`, `ORDER BY` and joins — especially polymorphic and JSON-path queries.
- [ ] **Dangerous migrations**: check for `add_column` with a default on huge tables, `change_column` rewrites and missing `disable_ddl_transaction!` where it matters.
- [ ] **Data reconciliation**: counters, cached aggregates and denormalised columns have a way to be verified and rebuilt.

## Step 3: Background jobs and reliability

- [ ] **Jobs are idempotent**: a retried job must not double-charge, double-send or corrupt state. Sidekiq's and Solid Queue's retry semantics make "at least once" the guarantee.
- [ ] **Dead-letter visibility**: failed jobs land somewhere a human sees them (error tracker or an admin view), not in a silent void.
- [ ] **Job timeouts and worker counts** match the workload; queue latency is measured, not assumed.
- [ ] **Deploys are reversible**: one-command rollback and a rehearsed path.

Solid Queue deserves a specific look — see [Solid Queue in Rails 8](/blog/solid-queue-rails) for the production pitfalls to test.

## Step 4: Tests and change velocity

- [ ] **The money paths are covered**: auth, billing, anything that writes to the database has request or model specs.
- [ ] **CI runs green on every PR** and blocks merge when red.
- [ ] **Flaky tests are fixed or quarantined**, not re-run until green.
- [ ] **Test data is realistic** in size and shape; tests against empty tables hide performance bugs.

If coverage is thin, the first 30 days of the plan look the same every time: tests around billing and auth before any refactoring.

## Step 5: Architecture and dependencies

- [ ] **Rails and Ruby versions are supported** (Rails 8.x with Ruby 3.4+/4.0; anything on 7.0 and below needs the [upgrade guide](/blog/rails-8-1-upgrade)).
- [ ] **No bespoke framework inside the app**: thin controllers, fat models, POROs for business logic. Service objects are fine; a custom DI container in a 5,000-line app is a smell.
- [ ] **Gem audit**: what's installed vs what's actually used (`bundle gem` or a simple grep of requires), especially abandoned "convenience" gems.
- [ ] **Front-end hygiene**: one rendering approach per screen (Hotwire or React), no mixed half-migrations. See my [Hotwire vs React](/blog/hotwire-vs-react) comparison if that's the decision in front of you.

## Step 6: Ranking the findings

Score each finding on two axes: **impact** (security, data loss, revenue, customer trust) and **cost to fix** (hours, risk of regression, dependency churn). Then sort:

1. **Critical (fix now)**: exposed secrets, missing authz, SQL injection risk, unpatched CVEs, data-loss migrations.
2. **High (this sprint)**: N+1 in hot paths, missing DB constraints on money tables, silent job failures.
3. **Medium (30/60 days)**: upgrade work, test coverage on critical paths, deploy pipeline.
4. **Low (backlog)**: style, deprecation warnings, nice-to-have refactors.

A useful forcing function: if a finding would make the next hire uncomfortable, it goes in the first two buckets.

## Step 7: Turning the audit into a plan

The report ends with a 60/90-day plan, for example:

- **Days 1–30**: patch CVE exposure, rotate any leaked secrets, add missing authz checks, install the safety-net tests (billing, auth), fix the worst N+1s.
- **Days 31–60**: DB constraints and indexes, job idempotency pass, CI hardening.
- **Days 61–90**: Rails/Ruby upgrade path, dependency cleanup, front-end consolidation.

If the team executing the plan is not confident in the riskiest changes, that's when outside help pays for itself — I do exactly this kind of engagement as [Rails consulting](/services/ruby-on-rails-consulting). If you'd rather I run the audit, [send me a short brief](/#contact).

## Conclusion

An audit is worth doing only if it ends in an order: what is broken, what it costs you, and what happens in the next 30, 60 and 90 days. Run the checklist yourself if you have the headspace; if you want a ranked, written report from the outside, [send me a short brief](/#contact).

## Frequently asked questions

### How long does a Rails code audit take?

Typically one to two weeks for a single application, depending on codebase size and how much of the toolchain (CI, deploys, error tracking) you can share.

### Can we run the audit ourselves?

Yes, with this checklist, `brakeman`, `bundler-audit` and a slow week. The gap is usually attribution: insiders normalise what is objectively risky. A focused outside review catches what "that's just how it is" hides.

### What does a Rails code audit cost?

I don't publish rate cards; scope follows from the checklist above and the size of the app. If you send me the repo size, Rails version and the two scariest areas, I can give you a fixed figure on a discovery call.

### Is this the same as a penetration test?

No. A pen-test attacks the running system from outside. An audit reviews the codebase and process. They complement each other; most teams should do the audit first.

### What if you find the app needs a rewrite?

Then the report says so — with the evidence, and with the migration path. In my experience full rewrites are right far less often than they are proposed.

### Do you sign an NDA?

Yes, and it's built into how I work: read-only repo access, no data exfiltration, findings delivered to the named recipients only.
