Repository navigation
ci(audit): gate npm audit through an allowlist-aware script - #384
Merged
Merged
Conversation
npm has no per-advisory ignore, so --audit-level=high cannot accept an advisory that has no fixed release. braces <= 3.0.3 (GHSA-vfj7-8cjw-p6xm) is one: 3.0.3 is the latest published version, and it is the only finding left in the npm audit of the 2026-10-13 lock file maintenance PR (#380). scripts/ci/npm_audit_gate.py reads the npm audit JSON, counts each advisory once rather than per package it propagates through, blocks on high/critical not waived by --ignore, warns on an --ignore that no longer matches, and fails closed on a missing or malformed report. The dependency policy records why braces is accepted: a dev-only dependency of stylelint, which expands glob patterns written in this repo.
The gate trusted any report whose 'vulnerabilities' was a dict. An advisory with a capitalised or missing severity was filed as "below threshold", and a report whose advisories sat outside 'via' parsed as zero advisories; both printed "Gate passed" with exit 0. Because the workflow swallows npm's exit code, nothing else would have caught it. The gate now fails unless auditReportVersion is 2, blocks on any severity other than moderate/low/info, and fails when npm's own high/critical package count is non-zero but no high/critical advisory was parsed. The test fixtures carry the real v2 shape, and the registry-error fixture is what npm 11 actually writes.
The policy blocks dev dependencies the same as runtime ones, so "dev only" cannot be why braces is accepted. Lead with the actual reason: the DoS needs an attacker-supplied pattern, and the only caller expands src/**/*.css from this repo. Record why the dependent cannot be dropped the way @vitest/ui was for flatted in v0.5.4: CSS lint runs in CI and pre-commit, and stylelint 17.16.0 still depends on the same chain.
The backend paths filter listed tests/** but not scripts/, so a PR touching only scripts/ci/cargo_audit_gate.py or npm_audit_gate.py skipped ruff and the tests/ci suite that covers them. Dependency Audit still runs the gate for real, but that only catches a gate that errors, not one that passes a report it should fail.
The count cross-check from the previous commit only ran when no advisory was ignored, and the braces ignore always matches, so in CI it never ran: a critical package whose advisory sat outside 'via', or whose 'via' string named a missing package, passed with rc 0. An id collision also let a low advisory shadow a critical one. Every package npm flags at high/critical, or at a severity the gate does not recognise, must now trace through its 'via' links to a parsed high/critical advisory, ignored or not. On an id collision the blocking advisory is kept. The trace replaces the metadata count, so metadata is no longer read. New tests cover a second critical alongside the ignored braces, the untraced shapes with braces ignored, the collision, a high package backed only by a moderate advisory, and a via cycle.
backend-ci.yml runs scripts/export_openapi.py and scripts/generate_schema.py, which the scripts/ci/*.py filter still left out: a PR touching only one of them skipped the job that executes it.
The trace accepted any blocking advisory at the end of a package's via chain. A string link into the ignored braces chain therefore accounted for a package of any severity: a new critical advisory on micromatch, placed outside 'via', passed with rc 0 because micromatch still links to the high braces advisory. A package must now reach an advisory at least as severe as itself. npm sets a package's severity to the highest of its advisories, and a dependency link inherits its source's severity (arborist 9.9.1, vuln.js addAdvisory; metavuln-calculator advisory.js), so a real report always satisfies this. Both real CI reports still pass with their blockers waived. A hidden advisory no more severe than one already reachable from the same package remains undetectable, and the docstring now says so; the policy row describes the new rule. Tests pin the two holes, a critical package linked only to a moderate one, and the absence of a stale-ignore warning when the ignore matches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The npm half of Dependency Audit cannot go green on its own. After lock file maintenance (#380), the only npm finding is
braces<= 3.0.3, GHSA-vfj7-8cjw-p6xm (high, CVSS 7.5). The advisory lists no patched version, and 3.0.3 is the latestbraceson npm (npm view braces dist-tags→latest: 3.0.3). npm's suggested fix is downgradingstylelintto 7.7.0.npm has no per-advisory ignore, so this takes the route
dependency-policy.mdhas prescribed since #337: a post-processor overnpm-audit.json, mirroringcargo_audit_gate.py.Changes
scripts/ci/npm_audit_gate.py:--ignore <GHSA-ID>, and on any severity it does not recognise. Reports moderate/low/info without blocking.viaobjects; stringviaentries are the same advisory propagated up the tree. The 7 "high" packages in chore(deps): lock file maintenance #380's report are one advisory.auditReportVersionother than 2.vialinks to a parsed advisory at least as severe as itself; an ignored one counts. This stays in force whilebracesis ignored. npm sets a package's severity to the highest of its advisories, and a dependency link inherits its source's severity (arborist 9.9.1,vuln.jsaddAdvisory), so a real report always satisfies it. A hidden advisory no more severe than one already reachable from the same package cannot be detected.--ignorematches nothing, so the entry gets removed oncebracesis patched.dependency-audit.yml:npm audit --json > npm-audit.json || true, then the gate with--ignore GHSA-vfj7-8cjw-p6xm.dependency-policy.md: Node row, allowlist mechanics and Required Tooling updated;bracesadded to the accepted advisories with its reasoning and re-check trigger.ci-cd.md: one line updated.ci-check.yml: the backend path filter now includesscripts/**/*.py. Before, a PR touching only a gate script, orexport_openapi.py/generate_schema.py(whichbackend-ci.ymlruns), skipped the backend job.Why accepting
bracesis safe hereThe DoS needs an attacker-supplied brace pattern. In
fiberpath_gui/package-lock.json,braces,micromatch,fast-globandglobbyare reached only throughstylelint, which expandssrc/**/*.css(npm run lint:css). Dropping the dependent, as@vitest/uiwas dropped forflattedin v0.5.4, is not an option:stylelint17.16.0 still depends on the same chain.Verification
The gate against the real reports:
--ignorebracesmain, scheduled run 38277199756--registry http://127.0.0.1:9)auditReportVersion2Hand-built malformed reports, each run with
--ignorebraces as in CI, against the gate atc4074d6(first version),ff6a5fb(count cross-check),541e813(severity-blind trace) and this head. Therow-*reports are single-shape cases (row-no-viaholds only abracespackage, with its advisory outsidevia). Thehole-*reports carry five packages of thebraceschain plus one hidden critical. Thechain-*reports put a hidden critical on, or link one into, the ignored chain.c4074d6ff6a5fb541e813row-capitalised: severity"High"row-no-severityrow-no-via: advisory outsideviarow-via-string:viais a stringrow-id-collision: no-id low + no-id criticalhole-outside-viahole-via-string:vianames a missing packagehole-id-collisionchain-hidden-critical: critical onmicromatch, advisory outsideviachain-critical-link: critical package linking intomicromatchThe
chain-*rows are the round-3 fixturesopen-hidden-critical-on-chain-pkgandopen-hidden-critical-plus-chain-link. Across 51 report files, each run with and without thebracesignore (102 runs), these two are the only results that differ between541e813and this head. The pre-#380 report, ten flagged packages with mixed high and moderate advisories, passes the trace once its five blockers are waived.uv run ruff checkandruff format --checkare clean;pytest tests/cipasses 54 tests.uv run mypydoes not coverscripts/ortests/(itspackagesare the three shipped packages), the same as for the cargo gate.Mutations, each anchor matched exactly once, the file hash checked to confirm the mutation applied,
--maxfail=1000so every failing test is listed:Known limits, not addressed: the trace is recursive, so a
viachain about 1,000 packages deep raisesRecursionError(rc 1, a false red); the deepest chain in either real report is 7. An--ignoreis keyed by advisory id, so if GHSA-vfj7-8cjw-p6xm were extended to a second package it would be waived there too.