MilesUp
Back to MilesUp
MILESUP · FULL AUDIT REPORT · RAILS

Example subscription SaaS

App
B2B invoicing app (fictional)
Stack
Rails 7.1, Postgres, Sidekiq, Stripe
Built with
Cursor and Claude Code
Scope
Main repo, staging, CI config

Verdict

Refactor parts

The core domain model is sound, and most controllers follow Rails conventions. Authorization was added screen by screen instead of in one place, so some actions are unprotected. Fixing that, filtering the logs and adding tests for billing makes the app safe to put in front of enterprise customers. A rebuild is not needed.

Executive summary

  • One critical issue: any signed-in user can read another company's invoices by changing an id in the URL.
  • Two high issues: secrets are written to production logs, and the Stripe webhook can be replayed.
  • Design and tests: billing logic is copied across three places, and billing and permissions have no tests, so regressions will reach customers.
  • Estimated fix effort: about 3 working days for the critical and high findings, and 4 to 5 days for everything.
SeverityCountMeaning
CRITICAL1Exploitable now. Fix before the next release.
HIGH2Serious risk. Fix within two weeks.
MEDIUM4Quality or scale risk. Plan into the next month.

Findings

CRITICAL Invoices readable across companies

app/controllers/invoices_controller.rb:14 · InvoicesController#show · RAILS-AUTH-02 · OWASP A01:2025 · CWE-639

What: invoices are loaded with Invoice.find(params[:id]), with no scope to the current account.

Why it matters: any customer can read any other customer's invoices, including names, amounts and addresses. That is a reportable data breach in most jurisdictions.

Fix: scope every lookup to the account, and add a policy check that cannot be skipped.

- @invoice = Invoice.find(params[:id])
+ @invoice = current_account.invoices.find(params[:id])
+ authorize @invoice

Effort: 1 day, including a request spec for every invoice action.

HIGH API tokens and reset links in production logs

config/initializers/filter_parameter_logging.rb · RAILS-CFG-02 · OWASP A09:2025 · CWE-532

What: the generated filter list was replaced, so token, api_key and reset_password_token are logged in plain text and shipped to the log provider.

Why it matters: anyone with log access can take over accounts.

Fix: restore the default filters and add the app's own keys. Rotate the exposed tokens and purge the old logs.

Effort: half a day, plus token rotation.

HIGH Stripe webhook events can be replayed

app/controllers/webhooks/stripe_controller.rb · RAILS-JOB-02 · OWASP A08:2025 · CWE-294

What: the signature is verified, but event ids are not stored, so the same invoice.paid event can be processed twice.

Why it matters: customers can receive double credits, and accounting stops matching Stripe.

Fix: store processed event ids with a unique index, and make the Sidekiq job safe to run twice.

Effort: 1 day.

MEDIUM N+1 queries on the dashboard

DashboardController#index

Four N+1 patterns cause about 180 queries per page load on the staging data. Add includes and a counter cache.

MEDIUM Unsafe migration on a large table

db/migrate/20261002_add_status_to_invoices.rb

Adds a column with a default and an index in one step. On a large table this locks writes. Split it, and create the index concurrently.

MEDIUM Billing logic duplicated across controllers and callbacks

InvoicesController, Api::InvoicesController, Invoice#after_save

Invoice totals are calculated in three places, and the copies already disagree on tax rounding. Move the calculation into one service object with unit tests before adding new plans. This is the main tech debt in the app.

MEDIUM No tests for billing or permissions

spec/

The 41 existing specs cover models only. Add request specs for authorization and billing before changing either.

Risk register

RiskLikelihoodImpactRatingOwnerDue
One customer reads another's invoicesLikelySevereCRITICALEngineering leadDay 7
Account takeover from tokens in logsPossibleSevereHIGHEngineering leadDay 14
Double credits from replayed webhooksPossibleModerateHIGHBilling ownerDay 14
Billing regressions reach customersLikelyModerateMEDIUMEngineering leadDay 45
Writes blocked during a deployPossibleModerateMEDIUMEngineering leadNext migration

30/60/90-day roadmap

WhenWhatOutcome
Days 1–30Fix the critical and high findings with tests; rotate exposed tokens; add request specs for authorization and billing.Safe to put in front of enterprise customers. Re-check and letter.
Days 31–60Move billing into one service; fix the migration and N+1 queries; make Brakeman and bundler-audit block merges.Billing changes are safe; regressions are caught in CI.
Days 61–90MFA for admins, an audit log of admin actions and exports, and SSO if the first enterprise deal needs it.Ready for enterprise security reviews.

Fix plan and quote

PhaseScopeDaysFixed price
1Critical and high findings, with tests2–3$2,000
2Medium findings and CI checks (Brakeman, bundler-audit), plus a re-audit2$1,500
Fixes total4–5$3,500
With the $2,500 Full Audit, this is the $6,000 Audit + Fix Sprint.$6,000

Example figures. A real quote is fixed after the audit and is valid for 14 days.

Security questionnaire answers (excerpt)

Included in the Enterprise readiness review. Written for after the phase 1 fixes.

QuestionAnswerEvidence
How do you prevent one customer from accessing another's data?Every record lookup is scoped to the signed-in account and checked by a policy that cannot be skipped. Request specs cover every invoice action.RAILS-AUTH-01, RAILS-AUTH-02; re-check letter
Are secrets and credentials kept out of logs?Yes. Passwords, tokens and reset links are filtered before logging, and exposed tokens were rotated.RAILS-CFG-02
Is your code scanned for vulnerabilities?Yes. Brakeman and bundler-audit run on every pull request and block the merge on a failure.RAILS-OPS-02

What was checked

All 51 points on the Rails checklist, covering authorization, input handling, secrets, signs of AI-built code, architecture and code quality, migrations, performance, background jobs, payments, tests, dependencies and CI. Every finding above was confirmed by hand. Tool output that turned out to be harmless is listed in an appendix, which is left out of this sample.

How each point was checked: 40 by reading the code, 5 from scanner output confirmed by hand, 3 from your answers and 2 in an isolated test environment. Not checked: 1 (RAILS-PERF-04, the slowest endpoints, because no monitoring data was available). It is not counted as a pass.

Book a free 20-min call See the Rails audit