Skip to content

case study

An audit gate with exceptions that expire

My role: I built this in 2026 as a demonstration. It grew out of a build step on this site, which is my own project. It uses no client or employer material, and the source is public.

Scope and constraints

Ownership
A solo demonstration that grew out of a build step on my own site. Not client or employer work.
Scale
A command line tool with one source file, one command file, no dependencies and a test suite.
Constraints
An advisory with no fix must not block CI forever, and it must not be hidden forever either. The tool must not fetch anything itself.
Judgment calls
A fixed window for every exception, a named failure when one expires, and output that is the same on every run.

What was delivered and checked

  • 74 tests run with node --test and all pass. They run offline against hand-written fixtures.
  • Tests cover both report shapes, the failing severities, the last day and the day after an exception, unused exceptions, the config rules including the 180 day limit, the exact output text, and exit codes 0, 1 and 2.
  • The command line is tested as a child process, including a stand-in npm that exits 1 and prints a report.

What it is

A step for CI that runs after the install. It fails the build when npm audit reports a high or critical advisory, and it lets a team record an exception for an advisory that cannot be fixed yet. Each exception has an advisory id, a reason and an end date. When the date passes, the advisory fails the build again.

The problem

Sooner or later an advisory appears for which no patched release exists. The audit step then fails on every run. The usual responses are to lower the audit level, add || true or turn the step off, and the change is rarely reverted. The advisory stays hidden, including on the day a fix is published.

The path of one run

  1. Read reportReads the output of npm audit, either by running it or from a saved file. Both the npm 7 and later shape and the older npm 6 shape are read.
  2. Match exceptionsEvery high or critical advisory is matched to an exception by its advisory id.
  3. Check datesAn exception covers an advisory through its end date, inclusive. The day after, it no longer does.
  4. ReportPrints failures, expired exceptions, accepted advisories and unused exceptions, in a fixed order.
  5. Exit code0 when nothing fails, 1 when an advisory fails or an exception has expired, 2 for a usage or config error.
The gate only reads a report and a config file. It never changes either.
Illustration with invented sample data. The package names, advisory ids and dates are made up.

The end date

An exception covers an advisory through its end date, inclusive. The day after, the advisory fails again and the expired exception is printed with its reason.

Illustration with invented sample data. One exception on its last day and on the day after.

Decisions

  • A fixed window so an exception cannot become permanent

    An exception needs an end date no more than 180 days after the day the gate runs, and a reason of at least 20 characters. A config that breaks either rule is rejected. The cost is that someone has to renew a long-lived exception on purpose, which is the point.

  • An expired exception fails again and is named

    The day after the end date the advisory fails the build, and the report names the exception that ended and its reason, so the reviewer sees what was accepted and why. The cost is a red build on a day nobody chose.

  • An unused exception is reported

    An exception that matches no advisory at a failing severity is printed as unused. It is a warning and does not fail the build. The cost is a line of output that someone has to clean up.

  • The gate never fetches advisories

    It has no network code and no dependencies. It reads whatever npm audit prints and trusts the severity, title and id in it. The cost is that it depends on the format of that output, and that it is only as current as the audit it reads.

  • Deterministic output

    Findings and exceptions are sorted by id, duplicates are removed, and a --today option replaces the current date, so a run can be repeated exactly. The cost is one more option to know about.

  • Both npm shapes are normalised

    The npm 7 and later report and the older npm 6 report are turned into the same list before anything is judged, and an advisory reached through several parent packages is reported once, on the package that carries it. The cost is two parsers to keep correct.

Scope and limits

  • It runs on hand-written fixtures

    All 74 tests run offline against fixtures I wrote by hand to match the two report shapes. They were not captured from a live audit, so a change in the npm format would not be noticed until a real report failed to parse.

  • It does not check that a reason is true

    It checks that a reason exists and is long enough to be reviewed. Whether it is accurate is for the reviewer.

  • Only npm is supported

    There is no support for yarn, pnpm or other package managers. The audit scope is fixed to production dependencies, and Windows was not tested.

  • The id match depends on the report

    npm 6 reports usually carry a numeric id and no GHSA id, so on npm 6 an exception keyed by a GHSA id matches only when the report address contains it. The numeric id always matches.

Source and tests

The source and the tests are in the audit-gate repository, under the MIT licence. npm test runs the tests. The repository also has a GitHub Actions workflow that runs them on Node.js 20 and 22.

Stack

  • Node.js
  • JavaScript
  • Node test runner
  • GitHub Actions

More case studies

    Engineering notes: the decisions behind the work