The audit gate we switched off
Our dashboard ran npm audit before every commit. Within a month I'd narrowed it twice and then turned it off. Why pre-commit is the wrong place for it, and where it belongs.
For a while, our merchant dashboard ran npm audit in a Git pre-commit hook. Every commit, by every developer, was checked against the npm advisory database. It sounds like the most security-conscious setup possible. It didn’t last, and I was the one who took it apart, in three steps.
What happened
--audit-level=high. The hook failed on any advisory, including low-severity ones in build tools. People couldn’t commit a CSS fix because of a moderate issue in a test dependency. Limiting it to high and critical cut the noise.--omit=dev. It still failed on high-severity issues in development-only packages, which never ship to users. Skipping dev dependencies cut it further.- Commented out. It still blocked unrelated work whenever a new advisory was published for a production package that had no fix yet. A developer fixing a typo can’t fix a vulnerability in a library they don’t maintain.
Why it failed
The gate checked the wrong thing at the wrong time. npm audit doesn’t check your change. It checks the whole dependency tree against a database that changes daily. So a commit that touched nothing could pass in the morning and fail in the afternoon. A check whose result doesn’t depend on your change shouldn’t decide whether you can make it.
And a gate that blocks people for reasons they can’t fix gets bypassed with --no-verify, or switched off. Ours was switched off.
Where it belongs
- Scheduled, not per-commit. Dependabot alerts or a daily CI job audit the tree on their own clock, and open a ticket or PR. That’s where “a new advisory exists” belongs.
- In CI on dependency changes. When a PR changes
package.jsonor the lockfile, audit it there. Now the check is about the change. - Production dependencies, high severity, with an exceptions list. Each exception says why it’s accepted and when it expires, so “no fix available yet” is recorded rather than silently ignored.
What I learned
- A gate has to be about the change it’s guarding. Otherwise it’s a lottery.
- Gates that block people for things they can’t fix get removed. Then you have less protection than a gentler check would have given you.
- Turning a check off should leave something in its place. The honest lesson for me: I removed the hook, and should have moved the audit into CI the same day.