skip to content

In a Rails 8.1 app, what do the generated `bin/rubocop` and `bin/bundler-audit` scripts run, and how do you handle a gem advisory that does not apply?

level: seniorimportance: should knowfreq 30%

answer

  1. binstubs that pin a config file
  2. rubocop-rails-omakase via inherit_gem
  3. ruby-advisory-db, checked locally
  4. ignore: list in config/bundler-audit.yml
  5. check --update keeps the config

basics

~10 s

bin/rubocop runs RuboCop with an explicit --config .rubocop.yml that inherits rubocop-rails-omakase; bin/bundler-audit checks Gemfile.lock against ruby-advisory-db using config/bundler-audit.yml, whose ignore: list holds advisory IDs you have reviewed and accepted.

solid answer

~40 s

`bin/rubocop` loads the bundle and prepends `--config .rubocop.yml`, and that file inherits `rubocop-rails-omakase`, a deliberately small style set with most departments disabled. `bin/bundler-audit` boots Bundler and runs bundler-audit's `check`, adding `--config config/bundler-audit.yml` when called with no arguments or with `check`. The check compares `Gemfile.lock` with a local copy of ruby-advisory-db, also flags insecure `http://` or `git://` sources, and exits 1 on any finding, which fails CI. To handle an advisory, upgrade the gem first; if the vulnerable code path truly is not used, add the CVE or GHSA ID under `ignore:` in `config/bundler-audit.yml` with a comment saying why. Refresh the database with `bin/bundler-audit check --update`: a bare `--update` skips the config, so the ignore list is not applied.

code

yaml · 6 lines
yaml
# config/bundler-audit.yml
# Audit all gems listed in the Gemfile for known security problems by running bin/bundler-audit.
# CVEs that are not relevant to the application can be enumerated on the ignore list below.

ignore:
  - CVE-THAT-DOES-NOT-APPLY

go deeper

for a junior

Recall what each script checks: bin/rubocop for style with the omakase config, bin/bundler-audit for vulnerable gem versions in Gemfile.lock.

for a middle

Explain how each binstub pins its config, where the advisory database lives and why a non-zero exit fails CI.

for a senior

Show triage judgement: upgrade first, ignore only with a reason and an owner, keep the local database fresh, and avoid the bare --update form that drops the config.

for a principal

Set the policy across apps: who reviews ignore entries, how long one may live, and how dependency advisories feed planned upgrades.

## Two binstubs, two jobs Rails 8.1's `rails new` writes several quality and security scripts into `bin/`. Two of them belong to the generated app itself rather than to CI configuration: - **`bin/rubocop`**: style checking with RuboCop. - **`bin/bundler-audit`**: checking the locked gems for known vulnerabilities, new in Rails 8.1 along with `config/bundler-audit.yml`. Both are thin wrappers. Their value is that they pin the configuration file, so a developer's laptop, the GitHub workflow and `bin/ci` all run the same check. (Brakeman, the code scanner, gets its own `bin/brakeman` and is a separate subject.) ## `bin/rubocop` The generated script is only a few lines long: 1. `require "bundler/setup"` so the bundled RuboCop version runs, not a global one. 2. `ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__))`, an explicit config path; the template's comment says this "increases performance slightly while avoiding config confusion". 3. `load Gem.bin_path("rubocop", "rubocop")` to hand over to RuboCop's own executable. The `.rubocop.yml` that `rails new` writes contains `inherit_gem: { rubocop-rails-omakase: rubocop.yml }`. That gem loads the `rubocop-rails` and `rubocop-performance` plugins but **disables most departments** (Lint, Metrics, Naming, and Rails and Performance as departments) and then turns on a curated set of individual cops, mostly Layout and Style plus a few Rails and Performance ones. It is a formatting baseline, not a strict linter. The GitHub workflow runs it as `bin/rubocop -f github` so offences show up as annotations. ## `bin/bundler-audit` The script requires `config/boot`, then runs `Bundler::Audit::CLI.start`. Before that, it appends `--config config/bundler-audit.yml`, but **only when ARGV is empty or contains `check`**. What the `check` command does: - If no advisory database exists locally, it downloads **ruby-advisory-db** (by default under `~/.local/share/ruby-advisory-db`, or wherever `BUNDLER_AUDIT_DB` points). With `--update` it refreshes an existing copy first. - It reads `Gemfile.lock` and reports every locked gem version that matches an advisory. - It reports insecure sources: `http://` gem servers and `git://` or `http://` git remotes, unless they are internal hosts. - It **exits with status 1** if anything was found, which fails a CI step or a `bin/ci` run. ## Triaging an advisory | Situation | Action | |---|---| | A patched version exists | `bundle update <gem>` and commit the new `Gemfile.lock` | | The patch is blocked by another dependency | upgrade the blocker, or record a time-boxed ignore | | The vulnerable code path is unused by the app | add the ID under `ignore:` with a comment and a review date | The ignore list is matched against each advisory's **identifiers**: its CVE ID, OSVDB ID or GHSA ID. The generated file ships with a placeholder entry to show the shape. Note that passing `--ignore` on the command line **replaces** the file's list for that run instead of adding to it. ## The traps 1. **`bin/bundler-audit --update` reads the wrong config.** ARGV is non-empty and does not contain `check`, so the binstub adds no `--config`; Thor still dispatches to the default `check` command, which then looks for `.bundler-audit.yml` in the app root. The reviewed ignores in `config/bundler-audit.yml` are not applied. Use `bin/bundler-audit check --update`. 2. **A stale local database.** Without `--update`, a laptop keeps checking against the copy it downloaded weeks ago; CI on a fresh runner downloads a current one. A gem can pass locally and fail in CI. 3. **Ignoring instead of upgrading.** An ignore list without reasons becomes permanent. Treat each entry as a decision with an owner. 4. **Confusing the tools.** bundler-audit checks dependencies against published advisories; it does not read your code. SQL injection or unsafe redirects in your own code are what Brakeman looks for. ## Where the generated app runs them The generated `.github/workflows/ci.yml` has a `scan_ruby` job that runs `bin/brakeman --no-pager` and `bin/bundler-audit`, and a `lint` job that runs `bin/rubocop -f github` with a RuboCop cache. Because every place calls the binstub rather than the gem's own executable, the pinned configuration is applied the same way in CI and on a laptop. Apps generated with `--skip-rubocop` or `--skip-bundler-audit` get neither the script nor the matching workflow steps.

  • What does `bin/rails app:update` do about these files when upgrading an older app to 8.1?
    It adds `bin/bundler-audit` and `config/bundler-audit.yml` only if the bundler-audit gem is installed; otherwise it skips them, as the 8.1 changelog records. You add the gem to the development and test group first, then rerun the update to get the binstub and config.
  • Why does the binstub require `config/boot` before starting bundler-audit?
    `config/boot` sets `BUNDLE_GEMFILE` to the app's Gemfile and runs `bundler/setup`, so the bundled bundler-audit version runs and the audit reads the app's own `Gemfile.lock`, regardless of the directory or global gems on the machine.

  • bin/bundler-audit scans the app's code for SQL injection.
  • bundler-audit asks rubygems.org about every gem live on each run.
  • Passing --ignore on the command line adds to the config file's list.
  • rubocop-rails-omakase turns on every Rails and Performance cop.
  • bin/bundler-audit --update refreshes the database and still applies the ignore list.

Assumes Rails 8.1.4; bin/bundler-audit and config/bundler-audit.yml are new in 8.1, and --skip-bundler-audit removes both.