skip to content

On npm 12, with `min-release-age=7` in the project `.npmrc`, why does `npm audit fix` leave a package vulnerable and exit non-zero?

level: seniorimportance: nice to knowfreq 5%

answer

  1. a window counted in days
  2. the patch is too new
  3. kept, warned, non-zero exit
  4. a per-package exemption list
  5. the command line outranks the project file

basics

~20 s

min-release-age=7 lets npm install only versions published more than seven days ago. A patch released yesterday falls inside that window, so npm 12 keeps the vulnerable version, warns that the fix was blocked and exits non-zero.

solid answer

~40 s

`min-release-age` takes a number of days (unset by default) and makes npm build the tree only from versions published longer ago than that. `npm audit fix` is an install underneath, so it obeys the window: when the only patched version is newer than the cutoff, npm 12 leaves the package at its vulnerable version, warns that it was "left at a vulnerable version because a fix is newer than the release-age cutoff", and sets a non-zero exit code so the gap is not missed. The ways forward npm names are: add the package to `min-release-age-exclude` (new in npm 12), relax `min-release-age` or `before` for this run, since a command-line value outranks the project `.npmrc`, or wait until the patch ages past the window.

code

ini · 4 lines
ini
; project .npmrc, committed beside package.json
min-release-age=7
; let the urgent chrono-fmt patch through; its own dependencies still wait
min-release-age-exclude[]=chrono-fmt

go deeper

for a junior

Recall that min-release-age is a number of days, and npm will not install any version younger than that, even a security fix.

for a middle

Explain the trace: audit fix is an install, the install honours the window, so a patch that is too new is skipped and npm 12 warns and exits non-zero.

for a senior

Pick the narrowest way forward for an urgent patch, exempting just that package or relaxing the window for one run, and check whether its own new dependencies stay blocked.

for a principal

Own the trade-off between a release-age window and patch latency, including who may grant exemptions and how fast an urgent fix can get past the wait.

## What `min-release-age` does `min-release-age` is an npm config key holding a **number of days**. Unset by default, it tells npm to build the tree so that only versions available for more than that many days are installed. It is the relative counterpart of `before`, which takes an exact date. - It applies whenever npm resolves versions: `npm install`, `npm update` and `npm audit fix`, which runs a full install underneath. - If no version of a dependency is old enough to satisfy its range, the command errors instead of installing something younger. - When `before` and `min-release-age` are both set **in the same config source**, `before` wins, since an explicit date overrides a relative window. - **Across sources** the normal precedence applies, command line over environment over project over user over global, so a higher-priority source can relax or override a lower one. Whether a waiting period is the right supply-chain policy for a team is a separate question; this one is about what the npm setting does. ## Why `npm audit fix` stops short Take the trip planner, whose committed project `.npmrc` contains `min-release-age=7`: 1. `npm audit` reports `[email protected]` as vulnerable; the maintainer published `3.2.2` with the fix yesterday. 2. `npm audit fix` starts an install that would move `chrono-fmt` to `3.2.2`. 3. The release-age filter removes `3.2.2` from consideration because it is only one day old, and nothing else in range is fixed. 4. npm 12 keeps `3.2.1`, logs a warning naming the package as "left at a vulnerable version because a fix is newer than the release-age cutoff", and suggests adding it to `min-release-age-exclude` or relaxing `min-release-age` or `before`. 5. The command ends with a **non-zero exit code**, so a pipeline running it fails instead of reporting success with a known hole. ## What changed in npm 12 | Behaviour | Release | |---|---| | `min-release-age` config (days) | npm 11.10 | | `min-release-age-exclude` exemption list | npm 12.0.0 | | `npm audit fix` warns about a blocked fix and exits non-zero | npm 12.0.0 | On npm 12 a blocked fix is loud by design: the warning and the exit code together make sure a window meant to slow down brand-new releases never quietly keeps a known vulnerability. ## The ways forward 1. **Exempt the one package.** Add `min-release-age-exclude[]=chrono-fmt` to the project `.npmrc`. The setting takes package names or `minimatch` glob patterns such as `@transit/*`, and a matching package can always resolve to its newest version. 2. **Relax the window for one run.** Pass a smaller value on the command line, for example `npm audit fix --min-release-age=0`; the command line outranks the project file, and the committed setting stays as it was. 3. **Wait.** Once the patch is older than seven days, a plain `npm audit fix` installs it. Two details trip people up: - **Only the named package is exempt.** Its own dependencies still follow the window unless they also match a pattern. If `3.2.2` needs a brand-new release of one of its dependencies, that dependency stays blocked and the fix still fails. - **Exempting a package does not change which registry serves it.** The exclusion only lifts the age filter; the package comes from wherever npm would fetch it anyway. ## Choosing between them - Prefer the **exclusion** when the patch is urgent and the package is one you trust, and remove the entry once the version has aged. - Prefer a **one-run relaxation** when you want the committed policy untouched and a reviewer to see the forced fix in the lock diff. - Prefer **waiting** when the vulnerability is not reachable in your code and the window exists precisely to let new releases settle. Whichever you choose, the fix should still arrive as a reviewed change to `package-lock.json`, which `npm ci` then reproduces on every machine. If you add an exclusion, give it an owner and remove it once the patched version has aged past the window, or the exemption quietly outlives the emergency that justified it.

  • Does `min-release-age-exclude[]=chrono-fmt` also exempt chrono-fmt's own dependencies?
    No. Only the named package is exempt; its dependencies still follow the release-age window unless they match a pattern too. If the patched release needs a brand-new version of one of its own dependencies, that dependency stays blocked until you exclude it as well or it ages past the cutoff.
  • What happens when both `before` and `min-release-age` are set?
    Within one config source, `before` wins, because an explicit date overrides a relative window. Across sources the normal precedence applies, command line, environment, project, user, global, so a higher-priority source can relax or override a lower one. That is why a value passed on the command line can lift a window committed in the project `.npmrc` for a single run.

  • min-release-age only applies to new installs, never to npm audit fix.
  • On npm 12 a blocked fix still lets npm audit fix exit successfully.
  • Excluding a package also exempts every one of its dependencies.
  • min-release-age takes a date, the same way before does.
  • The only way past the window is deleting it from the project .npmrc.

Assumes npm 12: min-release-age exists since npm 11.10, while min-release-age-exclude and the blocked-fix warning with a non-zero exit arrived in npm 12.0.0.