Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(ci): allowlist unfixable js-yaml DoS in the npm-audit release gate (#4651)

LearningCircuitec5efd30be09
diff --git a/.github/scripts/npm_audit_allowlist.py b/.github/scripts/npm_audit_allowlist.py
new file mode 100644
index 0000000000..ea487ddcfd
--- /dev/null
+++ b/.github/scripts/npm_audit_allowlist.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python3
+"""Filter ``npm audit --json`` output against an allowlist of advisories.
+
+Reads ``npm audit --json`` on stdin. Exits non-zero (1) if any
+moderate-or-higher vulnerability is NOT fully explained by allowlisted
+advisories, otherwise 0.
+
+npm reports a parent package as vulnerable when it (transitively) depends on
+a vulnerable child; the parent's ``via`` then contains a *string* reference to
+the child rather than an advisory object. We resolve those ``via`` chains so a
+package that is vulnerable *only* because of an allowlisted advisory is itself
+treated as handled — otherwise allowlisting one leaf (e.g. js-yaml) would still
+leave its dozen parents (lhci/*, jest/*) failing the gate.
+
+The allowlist is supplied via the ``AUDIT_ALLOWLIST`` env var as a
+space-separated list of GHSA IDs. Keep it tight and justified in the workflow
+that sets it — only advisories with **no available fix** in **dev/test-only**
+tooling belong here.
+"""
+
+import json
+import os
+import sys
+
+ALLOW = set(os.environ.get("AUDIT_ALLOWLIST", "").split())
+SEVERITIES = {"moderate", "high", "critical"}
+
+
+def main() -> int:
+ raw = sys.stdin.read().strip()
+ if not raw:
+ print(
+ "::error::empty npm audit output (audit did not run?)",
+ file=sys.stderr,
+ )
+ return 1
+ try:
+ data = json.loads(raw)
+ except json.JSONDecodeError as exc:
+ print(
+ f"::error::could not parse npm audit JSON: {exc}", file=sys.stderr
+ )
+ return 1
+
+ # A genuine npm audit report always carries these keys (an empty/clean
+ # audit still has "vulnerabilities": {}). Their absence means the audit
+ # did NOT actually run — e.g. a registry/network error returns valid JSON
+ # like {"message": ..., "error": ...} and npm exits non-zero, which the
+ # caller's `|| true` swallows. Fail safe (gate red) rather than pass a
+ # green gate on an audit that never happened.
+ if "vulnerabilities" not in data or "auditReportVersion" not in data:
+ print(
+ "::error::npm audit did not return a valid report (audit failed "
+ f"to run?): {data.get('message', 'unknown error')}",
+ file=sys.stderr,
+ )
+ return 1
+
+ vulns = data.get("vulnerabilities") or {}
+ if not isinstance(vulns, dict):
+ print(
+ "::error::npm audit 'vulnerabilities' is not an object — "
+ "treating as a failed audit",
+ file=sys.stderr,
+ )
+ return 1
+
+ def reachable_ghsas(name, seen):
+ """All advisory GHSAs reachable from a package's via-chain."""
+ if name in seen:
+ return set()
+ seen.add(name)
+ found = set()
+ for via in (vulns.get(name) or {}).get("via", []):
+ if isinstance(via, dict) and "GHSA-" in (via.get("url") or ""):
+ # Take only the GHSA token, not any trailing path/query the
+ # URL might carry (e.g. .../GHSA-xxxx/foo?bar).
+ tail = via["url"].split("GHSA-", 1)[1]
+ found.add("GHSA-" + tail.split("/")[0].split("?")[0])
+ elif isinstance(via, str):
+ found |= reachable_ghsas(via, seen)
+ return found
+
+ unhandled = 0
+ for name, info in vulns.items():
+ if info.get("severity") not in SEVERITIES:
+ continue
+ ghsas = reachable_ghsas(name, set())
+ if ghsas and ghsas <= ALLOW:
+ print(f" allowlisted: {name} ({info['severity']}) {sorted(ghsas)}")
+ else:
+ unhandled += 1
+ detail = sorted(ghsas - ALLOW) if ghsas else "no-GHSA"
+ print(f" UNHANDLED: {name} ({info['severity']}) {detail}")
+
+ suffix = "y" if unhandled == 1 else "ies"
+ print(f" -> {unhandled} non-allowlisted moderate+ vulnerabilit{suffix}")
+ return 1 if unhandled else 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/.github/workflows/npm-audit.yml b/.github/workflows/npm-audit.yml
index 5b105f81fa..34fe6a0969 100644
--- a/.github/workflows/npm-audit.yml
+++ b/.github/workflows/npm-audit.yml
@@ -29,8 +29,17 @@ jobs:
node-version: '24'
- name: Run npm audit on all package.json locations
+ env:
+ # Advisories with NO upstream fix, accepted ONLY because they live in
+ # dev/test-only tooling that never ships to users. Keep tight + justified:
+ # GHSA-h67p-54hq-rp68 — js-yaml 3.x DoS, pulled transitively by
+ # @lhci/utils (accessibility_tests) & @istanbuljs/load-nyc-config
+ # (infrastructure_tests); both pin js-yaml ^3, no patched 3.x exists.
+ # Dev-only, parses trusted local config. (dismissed alerts #97/#7893)
+ AUDIT_ALLOWLIST: "GHSA-h67p-54hq-rp68"
run: |
FAILED=false
+ FILTER="${GITHUB_WORKSPACE}/.github/scripts/npm_audit_allowlist.py"
# Audit root and every test directory that contains a package.json
DIRS=(
.
@@ -54,12 +63,19 @@ jobs:
FAILED=true
continue
fi
- (cd "${dir}" && npm audit --audit-level=moderate) || FAILED=true
+ # Audit, then filter out allowlisted (no-fix, dev-only) advisories.
+ # `|| true` is on the assignment (not inside $()) so npm's non-zero
+ # exit is swallowed without the SC2015 `A && B || C` idiom; an
+ # empty/error capture still fails safe in the filter.
+ audit_json="$(cd "${dir}" && npm audit --audit-level=moderate --json 2>/dev/null)" || true
+ if ! printf '%s' "${audit_json}" | python3 "${FILTER}"; then
+ FAILED=true
+ fi
done
if [[ "$FAILED" == "true" ]]; then
- echo "❌ npm audit found moderate or higher severity vulnerabilities"
- echo "Run 'npm audit fix' locally to resolve issues"
+ echo "❌ npm audit found non-allowlisted moderate or higher severity vulnerabilities"
+ echo "Fix: bump the dep / 'npm audit fix'; or if no fix exists and it is dev-only, add the advisory to AUDIT_ALLOWLIST with justification."
exit 1
else
- echo "✅ No moderate or higher severity vulnerabilities found"
+ echo "✅ No non-allowlisted moderate or higher severity vulnerabilities found"
fi
diff --git a/tests/ci/test_npm_audit_allowlist.py b/tests/ci/test_npm_audit_allowlist.py
new file mode 100644
index 0000000000..ece300648e
--- /dev/null
+++ b/tests/ci/test_npm_audit_allowlist.py
@@ -0,0 +1,192 @@
+"""Tests for .github/scripts/npm_audit_allowlist.py — the npm-audit release-gate
+allowlist filter.
+
+This script is a security gate: it must (1) FAIL (exit 1) on any non-allowlisted
+moderate-or-higher vulnerability, (2) resolve npm's transitive ``via`` chains so
+a parent flagged only because of an allowlisted leaf is itself handled, and
+(3) FAIL SAFE on any input that is not a genuine npm audit report (a
+registry/network error returns valid JSON with no report, and npm's non-zero
+exit is swallowed by the workflow's ``|| true``). These tests pin all three.
+
+Run via subprocess to exercise the real exit-code contract the workflow relies
+on, and because the allowlist is read from the environment at import time.
+"""
+
+import json
+import os
+import subprocess
+import sys
+from pathlib import Path
+
+import pytest
+
+SCRIPT = (
+ Path(__file__).resolve().parents[2]
+ / ".github"
+ / "scripts"
+ / "npm_audit_allowlist.py"
+)
+
+ALLOW = "GHSA-aaaa-aaaa-aaaa" # the single allowlisted advisory under test
+
+
+def run(payload, allowlist=ALLOW):
+ """Run the filter with *payload* (str or dict) on stdin; return exit code."""
+ stdin = payload if isinstance(payload, str) else json.dumps(payload)
+ proc = subprocess.run(
+ [sys.executable, str(SCRIPT)],
+ input=stdin,
+ capture_output=True,
+ text=True,
+ env={**os.environ, "AUDIT_ALLOWLIST": allowlist},
+ )
+ return proc.returncode
+
+
+def report(vulns):
+ """Wrap a vulnerabilities map in a minimal valid npm v7+ audit report."""
+ return {"auditReportVersion": 2, "vulnerabilities": vulns, "metadata": {}}
+
+
+def advisory(ghsa, severity="moderate"):
+ return {
+ "severity": severity,
+ "via": [{"url": f"https://github.com/advisories/{ghsa}"}],
+ }
+
+
+# --------------------------------------------------------------------------
+# Passes the gate (exit 0)
+# --------------------------------------------------------------------------
+
+
+def test_clean_report_passes():
+ assert run(report({})) == 0
+
+
+def test_allowlisted_leaf_passes():
+ assert run(report({"js-yaml": advisory(ALLOW)})) == 0
+
+
+def test_via_chain_parent_passes():
+ # Parent is vulnerable ONLY because its via-string points to the
+ # allowlisted leaf — must resolve and pass.
+ payload = report(
+ {
+ "@lhci/utils": {"severity": "moderate", "via": ["js-yaml"]},
+ "js-yaml": advisory(ALLOW),
+ }
+ )
+ assert run(payload) == 0
+
+
+def test_low_severity_only_passes():
+ # Below the moderate threshold — ignored, like `npm audit --audit-level`.
+ assert run(report({"x": advisory("GHSA-bbbb-bbbb-bbbb", "low")})) == 0
+
+
+# --------------------------------------------------------------------------
+# Fails the gate (exit 1) — real vulnerabilities
+# --------------------------------------------------------------------------
+
+
+def test_non_allowlisted_moderate_fails():
+ assert run(report({"evil": advisory("GHSA-bbbb-bbbb-bbbb")})) == 1
+
+
[email protected]("sev", ["high", "critical"])
+def test_high_and_critical_fail(sev):
+ assert run(report({"evil": advisory("GHSA-bbbb-bbbb-bbbb", sev)})) == 1
+
+
+def test_coattail_mixed_via_fails():
+ # A package reachable via BOTH the allowlisted leaf AND a separate
+ # non-allowlisted advisory must NOT be laundered through the allowlist.
+ payload = report(
+ {
+ "evil": {
+ "severity": "moderate",
+ "via": [
+ {
+ "url": "https://github.com/advisories/GHSA-bbbb-bbbb-bbbb"
+ },
+ "js-yaml",
+ ],
+ },
+ "js-yaml": advisory(ALLOW),
+ }
+ )
+ assert run(payload) == 1
+
+
+def test_cve_only_no_ghsa_fails():
+ # An advisory with no GHSA cannot be matched against a GHSA allowlist —
+ # fail safe rather than silently drop it.
+ payload = report(
+ {
+ "x": {
+ "severity": "high",
+ "via": [{"url": "https://nvd.nist.gov/CVE-1"}],
+ }
+ }
+ )
+ assert run(payload) == 1
+
+
+def test_empty_allowlist_fails_even_on_listed_advisory():
+ assert run(report({"js-yaml": advisory(ALLOW)}), allowlist="") == 1
+
+
+# --------------------------------------------------------------------------
+# Fail SAFE on non-report / malformed input (gate red, never silently green)
+# --------------------------------------------------------------------------
+
+
+def test_registry_error_object_fails():
+ # The real fail-open case: npm registry/network error returns valid JSON
+ # with no report, and `|| true` swallows npm's non-zero exit.
+ err = {"message": "request failed, reason: ETIMEDOUT", "error": {}}
+ assert run(err) == 1
+
+
+def test_report_missing_audit_version_fails():
+ assert run({"message": "err", "vulnerabilities": {}}) == 1
+
+
+def test_report_missing_vulnerabilities_fails():
+ assert run({"auditReportVersion": 2}) == 1
+
+
+def test_non_dict_vulnerabilities_fails():
+ assert run({"auditReportVersion": 2, "vulnerabilities": ["x"]}) == 1
+
+
+def test_empty_stdin_fails():
+ assert run("") == 1
+
+
+def test_malformed_json_fails():
+ assert run("not json at all") == 1
+
+
+# --------------------------------------------------------------------------
+# GHSA extraction robustness
+# --------------------------------------------------------------------------
+
+
+def test_ghsa_url_with_trailing_path_is_parsed_cleanly():
+ # A URL carrying a trailing path/query must extract just the GHSA token,
+ # so it still matches the allowlist exactly (no over- or under-match).
+ payload = report(
+ {
+ "js-yaml": {
+ "severity": "moderate",
+ "via": [
+ {
+ "url": f"https://github.com/advisories/{ALLOW}/extra?ref=x"
+ }
+ ],
+ }
+ }
+ )
+ assert run(payload) == 0