5 min read

When the Audit Fails on a PR That Didn't Change Anything

A dependency audit can go red because the advisory database changed, not your code. Check whether main fails too, fix it there once, and rebase everything else.
black traffic light turned on during night time
Photo by Tsvetoslav Hristov on Unsplash

I opened my pull request list expecting two boring dependency bumps to merge. Both were red. One bumped a CI action, the other bumped a couple of crates in the lock file. Neither touched any code, and both failed the same check: the security audit.

The tempting reading is "this PR introduced a vulnerability". It hadn't. Nothing in either PR was the problem. The world had changed underneath the repository, and the PRs were just the first things to run CI after it did.

The problem: an audit fails on time, not on diffs

Most CI checks are a function of the code. Same commit in, same result out. A dependency audit like cargo audit is different. It checks your lock file against an advisory database that is updated every day. The same lock file can pass on Monday and fail on Friday, because on Thursday someone published an advisory for a crate you already ship.

That breaks the usual mental model of a red PR. When I looked at the failure, the advisory was for a URL-parsing crate pulled in transitively by the HTTP client. Neither PR had changed it. Then I checked the main branch: its last green CI run was from before the advisory was published. Main was broken too. It just hadn't run since.

So the useful question for any failing audit is not "what did this PR change?" but "would main fail this check right now?" If yes, the PR is innocent, and fixing it inside that PR is the wrong place to start.

The idea: fix it once, at the base, then let everything rebase

There are two bad instincts here. One is to make the audit non-blocking, or ignore the advisory, so the PRs go green. That hides a real issue to unblock unrelated work. The other is to fix the vulnerable crate separately in every open PR. That creates duplicate, conflicting lock file changes, and with bot-generated PRs it fights the bot.

Treat it as the PR's fault

  • Silence the advisory so the PR goes green
  • Or patch the crate in every open PR
  • Main stays vulnerable, or the PRs conflict with each other and with the bot

Treat it as the base's fault

  • Confirm main would fail too
  • Land one minimal fix on the base
  • Rebase the other PRs; they go green without changes
An audit failure that main shares belongs to main. Fix it there once.

The fix belongs to the base branch, once. What I did:

  1. Confirm the cause. Read the audit output for the crate, version and patched range. Check when main last ran CI and whether the advisory is newer than that.
  2. Make the smallest change that clears it. Here that was one patch-level bump of the vulnerable crate, plus one sibling crate whose minimum version the new release required. No other upgrades mixed in.
  3. Land it on the base. I put it on the lock-file-only PR, since it was already the same kind of change, and merged that once everything was green.
  4. Rebase the rest. The CI-only PR needed no edits. A rebase onto the new main was enough for its audit to pass.

One thing to know with bot PRs: once you push your own commit onto a Dependabot branch, the bot stops rebasing it automatically. That's fine for a PR you are about to merge, but don't do it to one you want the bot to keep maintaining.

A side quest: editing a lock file without the toolchain

The normal fix is one command, cargo update -p <crate>. On my machine, cargo didn't run. A package manager upgrade had renamed the binary that my toolchain's shims were symlinked to, so every proxy (cargo, rustc, rustfmt) pointed at a file that no longer existed. The toolchains themselves were fine. Only the links were dangling.

I didn't want a broken laptop to block a security fix, so I edited the lock file by hand. That's only safe if you check what the resolver would have checked:

  • the new version exists and isn't yanked;
  • its checksum, taken from the registry index rather than typed from memory;
  • its dependency requirements, compared with the old version's. This is where I found the sibling crate that also had to move up a patch version.

The crates.io sparse index serves all of that as one line of JSON per version, so the check is a single request. The path is bucketed by name length: one to three characters go under 1/, 2/ or 3/<first letter>/, and longer names under their first two and next two letters.

# e.g. a crate named "serde" lives at se/rd/serde
curl -s https://index.crates.io/<aa>/<bb>/<crate> \
  | jq -c 'select(.vers == "<new-version>")
           | {cksum, yanked, deps: [.deps[] | select(.kind == "normal") | {name, req}]}'

Then CI did the real verification: build, tests and the audit, on every target. Afterwards I fixed the toolchain properly by repointing the shims at the package manager's stable wrapper path rather than a versioned binary. I ran the build and tests locally to confirm the hand edit matched what the resolver would have produced. It did, and the lock file didn't change.

The lesson there is separate but related: a symlink into a package manager's versioned paths is a time bomb. Point it at the stable path the package manager promises to keep, not at the file it happens to install today.

Then ship it

A security fix in a dependency is a reason for a patch release, even when your own code didn't change. Anyone who pins your release is still shipping the vulnerable crate until you cut a new one. The release itself was routine: bump the version, update the image tags in the docs, add a changelog entry that names the advisory, merge, tag.

Trade-offs

  • Blocking on audits means unrelated PRs go red without warning. That's the point, but it means someone has to triage it quickly, or the red becomes noise people learn to ignore.
  • A scheduled audit on main would have caught this first. Running the audit nightly on the default branch, not just on PRs, separates "the world changed" from "this PR changed something" before anyone opens the PR list.
  • Hand-editing a lock file is a last resort. It worked because the change was two patch bumps with no new transitive dependencies. Anything bigger, fix the toolchain first.

Takeaway

When a dependency audit fails on a PR that didn't touch dependencies, ask whether main would fail too. If it would, the fix belongs on main, once. Every other PR just needs a rebase.