Skip to content

ci(audit): gate npm audit through an allowlist-aware script - #384

Merged
CameronBrooks11 merged 8 commits into
mainfrom
ci/npm-audit-gate
Oct 14, 2026
Merged

CameronBrooks11 merged 8 commits into
mainfrom
ci/npm-audit-gate

Conversation

@CameronBrooks11

@CameronBrooks11 CameronBrooks11 commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

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 latest braces on npm (npm view braces dist-tags → latest: 3.0.3). npm's suggested fix is downgrading stylelint to 7.7.0.

npm has no per-advisory ignore, so this takes the route dependency-policy.md has prescribed since #337: a post-processor over npm-audit.json, mirroring cargo_audit_gate.py.

Changes

  • scripts/ci/npm_audit_gate.py:
    • Blocks on a high/critical advisory not waived by --ignore <GHSA-ID>, and on any severity it does not recognise. Reports moderate/low/info without blocking.
    • Counts each advisory once from the via objects; string via entries are the same advisory propagated up the tree. The 7 "high" packages in chore(deps): lock file maintenance #380's report are one advisory.
    • Fails closed on a missing or malformed report, and on any auditReportVersion other than 2.
    • Every package npm flags at high/critical (or an unknown severity) must trace through its via links to a parsed advisory at least as severe as itself; an ignored one counts. This stays in force while braces is 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.js addAdvisory), so a real report always satisfies it. A hidden advisory no more severe than one already reachable from the same package cannot be detected.
    • On an id collision, keeps the advisory that would block.
    • Warns when an --ignore matches nothing, so the entry gets removed once braces is 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; braces added 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 includes scripts/**/*.py. Before, a PR touching only a gate script, or export_openapi.py/generate_schema.py (which backend-ci.yml runs), skipped the backend job.

Why accepting braces is safe here

The DoS needs an attacker-supplied brace pattern. In fiberpath_gui/package-lock.json, braces, micromatch, fast-glob and globby are reached only through stylelint, which expands src/**/*.css (npm run lint:css). Dropping the dependent, as @vitest/ui was dropped for flatted in v0.5.4, is not an option: stylelint 17.16.0 still depends on the same chain.

Verification

The gate against the real reports:

Report --ignore braces Result
#380 run 38427831685 yes rc 0: 1 advisory, accepted
#380 run 38427831685 no rc 1: braces blocks
pre-#380 main, scheduled run 38277199756 yes rc 1: devalue ×3 and source-map-js block (fixed by #380)
npm 11.19.0 registry error (--registry http://127.0.0.1:9) — rc 1: not auditReportVersion 2

Hand-built malformed reports, each run with --ignore braces as in CI, against the gate at c4074d6 (first version), ff6a5fb (count cross-check), 541e813 (severity-blind trace) and this head. The row-* reports are single-shape cases (row-no-via holds only a braces package, with its advisory outside via). The hole-* reports carry five packages of the braces chain plus one hidden critical. The chain-* reports put a hidden critical on, or link one into, the ignored chain.

Report c4074d6 ff6a5fb 541e813 now Check that fails it now
row-capitalised: severity "High" 0 1 1 1 unrecognised severity blocks
row-no-severity 0 1 1 1 unrecognised severity blocks
row-no-via: advisory outside via 0 1 1 1 trace
row-via-string: via is a string 0 1 1 1 trace
row-id-collision: no-id low + no-id critical 0 1 1 1 collision keeps the blocking advisory
hole-outside-via 0 0 1 1 trace
hole-via-string: via names a missing package 0 0 1 1 trace
hole-id-collision 0 0 1 1 collision keeps the blocking advisory
chain-hidden-critical: critical on micromatch, advisory outside via 0 0 0 1 trace, severity-aware
chain-critical-link: critical package linking into micromatch 0 0 0 1 trace, severity-aware

The chain-* rows are the round-3 fixtures open-hidden-critical-on-chain-pkg and open-hidden-critical-plus-chain-link. Across 51 report files, each run with and without the braces ignore (102 runs), these two are the only results that differ between 541e813 and 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 check and ruff format --check are clean; pytest tests/ci passes 54 tests. uv run mypy does not cover scripts/ or tests/ (its packages are 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=1000 so every failing test is listed:

any ignore accepts all          -> test_ignored_advisory_does_not_hide_another_critical test_ignore_does_not_cover_another_advisory test_id_collision_keeps_the_blocking_advisory
missing vulnerabilities passes  -> test_missing_vulnerabilities_fails_closed
no stale-ignore warning         -> test_stale_ignore_warns_but_passes
warn on every ignore            -> test_ignore_accepts_listed_advisory
id ignores GHSA url             -> test_advisory_id_from_url test_ignore_accepts_listed_advisory test_via_cycle_is_traced_without_recursing_forever test_main_passes_ignore_flags
any version accepted            -> test_other_report_versions_fail_closed[1] [3] [None]
unknown severity passes         -> test_unrecognised_severity_blocks[High] [None] []
critical filed non-blocking     -> test_blocks_on_critical test_ignored_advisory_does_not_hide_another_critical test_id_collision_keeps_the_blocking_advisory
high filed non-blocking         -> test_blocks_on_high test_ignore_does_not_cover_another_advisory test_main_passes_ignore_flags
blocking returns 0              -> 9 tests
no trace check                  -> test_untraced_package_fails_closed_while_braces_ignored[entry0..3] test_high_package_with_only_a_moderate_advisory_fails_closed test_critical_on_ignored_chain_package_fails_closed test_critical_linked_into_ignored_high_chain_fails_closed test_critical_linked_only_to_moderate_package_fails_closed
collision keeps first           -> test_id_collision_keeps_the_blocking_advisory
trace ignores string links      -> test_ignore_accepts_listed_advisory test_via_cycle_is_traced_without_recursing_forever test_main_passes_ignore_flags
string link always explains     -> test_critical_on_ignored_chain_package_fails_closed test_critical_linked_into_ignored_high_chain_fails_closed test_critical_linked_only_to_moderate_package_fails_closed
trace accepts any severity      -> test_high_package_with_only_a_moderate_advisory_fails_closed test_critical_on_ignored_chain_package_fails_closed test_critical_linked_into_ignored_high_chain_fails_closed test_critical_linked_only_to_moderate_package_fails_closed
trace severity-blind            -> test_critical_on_ignored_chain_package_fails_closed test_critical_linked_into_ignored_high_chain_fails_closed
package need ignores severity   -> test_critical_on_ignored_chain_package_fails_closed test_critical_linked_into_ignored_high_chain_fails_closed
no cycle guard                  -> test_via_cycle_is_traced_without_recursing_forever
trace skips unknown pkg sev     -> test_untraced_package_fails_closed_while_braces_ignored[entry3]

Known limits, not addressed: the trace is recursive, so a via chain about 1,000 packages deep raises RecursionError (rc 1, a false red); the deepest chain in either real report is 7. An --ignore is keyed by advisory id, so if GHSA-vfj7-8cjw-p6xm were extended to a second package it would be waived there too.

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.
@CameronBrooks11
CameronBrooks11 merged commit 643bd78 into main Oct 14, 2026
21 checks passed
@CameronBrooks11
CameronBrooks11 deleted the ci/npm-audit-gate branch October 14, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant