-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(security): advisory early-warning correlation and audit provenance records #7354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
79d6625
feat(security): advisory early-warning scan and audit provenance records
Dongni-Yang 1b53bb7
docs(security): add SPDX header to advisory early-warning doc
Dongni-Yang 9759ce2
Merge remote-tracking branch 'origin/main' into dongniy/7338-audit-pr…
Dongni-Yang c52ee04
Merge remote-tracking branch 'upstream/main' into dongniy/7338-audit-…
Dongni-Yang 05bcaf5
refactor(security): split out the scheduled early-warning workflow
Dongni-Yang 20f2e8a
fix(security): fail closed on incomplete WeChat audit reports
apurvvkumaria 7b2a512
test(security): cover malformed WeChat audit output
apurvvkumaria 01b56a8
merge(security): integrate audit provenance with exceptions
apurvvkumaria 61adf66
Merge remote-tracking branch 'origin/main' into codex/pr7354-provenan…
apurvvkumaria fd99f88
Merge branch 'main' into dongniy/7338-audit-provenance
cv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| <!-- SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. --> | ||
| <!-- SPDX-License-Identifier: Apache-2.0 --> | ||
|
|
||
| # Advisory Early Warning and Audit Provenance | ||
|
|
||
| Status: correlation module, scan CLI, and audit provenance implemented. | ||
| Scheduled operation and the response policy are a separate follow-up, gated on | ||
| product/security-owner sign-off recorded on issue #7338 (evidence from #7276). | ||
|
|
||
| Public upstream GitHub Security Advisories are often published weeks before the | ||
| global reviewed ecosystem record that `npm audit` enforces. For | ||
| `fast-uri` (GHSA-4c8g-83qw-93j6) the upstream repository advisory appeared on | ||
| June 29 while the reviewed record propagated on July 21, so the same vulnerable | ||
| version audited clean at 18:46 UTC and reported High at 20:09 UTC. This page | ||
| documents the early-warning correlation that narrows that gap and the | ||
| provenance every audit now records so such timelines are provable from retained | ||
| artifacts. | ||
|
|
||
| The correlation draws on all three types of the global advisory database, which | ||
| contribute differently: | ||
|
|
||
| - reviewed records are the corpus `npm audit` enforces — a match here means | ||
| package-level enforcement is imminent or already active, and the signal | ||
| confirms the reviewed gate will catch it; | ||
| - unreviewed records are NVD-sourced and often appear before curation reaches | ||
| the reviewed feed — they usually lack a verified npm mapping, so they flow | ||
| through the ambiguous, informational-only path and provide the earlier | ||
| heads-up; | ||
| - malware records name npm packages published as malware — a match against the | ||
| reviewed inventory correlates like any other record and is equally | ||
| non-blocking. | ||
|
|
||
| Polling upstream *repository* advisories directly (the earliest public signal, | ||
| e.g. `fastify/fast-uri`'s own advisory) needs a package-to-repository map and | ||
| is the planned extension; the correlation module already accepts that record | ||
| shape unchanged. | ||
|
|
||
| ## How the early-warning correlation works | ||
|
|
||
| - `scripts/lib/advisory-early-warning.mts` correlates GitHub Security Advisory | ||
| JSON (repository-level and global records share the shape) with the reviewed | ||
| npm inventory and emits structured signals: | ||
| `{advisoryId, package, vulnerableRange, matchedVersions, source, confidence, action}`. | ||
| - The inventory is derived from `ci/reviewed-npm-audit.json`: every committed | ||
| archive package spec plus the installed packages of each locked graph's | ||
| `package-lock.json`. | ||
| - Confidence is encoded, never guessed: only an exact npm ecosystem + | ||
| package-name + parseable semver-range match yields `confidence: "exact"` and | ||
| `action: "investigate"`. Name collisions from non-npm (CPE-derived) records | ||
| and unparseable ranges yield `confidence: "ambiguous"` and | ||
| `action: "informational"`. Ambiguous matches never block or mutate a release. | ||
| - The reviewed npm audit gate (`scripts/audit-reviewed-npm-graph.mts`, enforced | ||
| in CI) remains enabled and authoritative for exact npm package/version-range | ||
| decisions. The early-warning path only triggers investigation and rescanning. | ||
|
|
||
| `scripts/advisory-early-warning-scan.mts` is the CLI over the module. | ||
| It reads only local files and exits 0 whether or not signals are found. | ||
| It does not modify input files or external state. | ||
| With `--output`, it writes the requested local signals file: | ||
|
|
||
| ```sh | ||
| # List inventory package names (one per line), the input for advisory queries. | ||
| node --experimental-strip-types scripts/advisory-early-warning-scan.mts \ | ||
| --list-packages | ||
|
|
||
| # Correlate fetched advisory records with the inventory. | ||
| node --experimental-strip-types scripts/advisory-early-warning-scan.mts \ | ||
| --advisories advisories.json --output signals.json | ||
| ``` | ||
|
|
||
| Advisory records come from the GitHub `/advisories` API — all three types, | ||
| paginated, filtered by `affects=` batches of the inventory package names. | ||
|
|
||
| Running this correlation on a schedule and routing signals to an alert | ||
| destination is deliberately not wired up yet: #7338 requires product/security | ||
| owners to define the supported historical-image scope, rescan ownership, alert | ||
| destination, and response expectations first. A follow-up adds the scheduled | ||
| workflow once that sign-off is recorded on the issue. | ||
|
|
||
| ## Provenance recorded per audit | ||
|
|
||
| Each reviewed npm audit report now has a `*.provenance.json` sidecar | ||
| (`coverage/reviewed-npm-audit/` artifacts, and `npm-audit.provenance.json` for | ||
| the WeChat locked runtime graph audit) recording: | ||
|
|
||
| - scanner identity: `npm audit`, npm version, Node.js version; | ||
| - the configured registry, with URL credentials removed, plus the derived bulk | ||
| advisory endpoint npm posts the dependency graph to (npm >= 7 has no | ||
| quick-audit fallback: on request failure npm reports no advisory data, and | ||
| the note records this); | ||
| - run start and finish timestamps (ISO 8601); | ||
| - the audited graph label and committed package specs; | ||
| - the raw machine-readable report path (`rawReportPath`, by convention | ||
| relative to the directory containing the sidecar); | ||
| - the GHSA advisory ids extracted from the report; and | ||
| - a `failure` marker when the audit attempt itself failed, so the sidecar | ||
| still records the attempt. | ||
|
|
||
| Comparing the `advisoryIds` of consecutive retained runs identifies the last | ||
| comparable non-detection and the first detection of a newly surfaced advisory, | ||
| even when an unrelated finding failed the earlier run. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/usr/bin/env -S node --experimental-strip-types | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| // CLI entry for the advisory early-warning path (#7338). Correlates public | ||
| // GitHub Security Advisory JSON with the reviewed npm inventory derived from | ||
| // ci/reviewed-npm-audit.json (committed package specs plus the locked-graph | ||
| // package-locks) and prints structured, NON-blocking signals. Signals never | ||
| // fail the process: enforcement stays with the reviewed npm audit gate. | ||
| // | ||
| // Usage: | ||
| // advisory-early-warning-scan.mts --list-packages | ||
| // advisory-early-warning-scan.mts --advisories <advisories.json> [--output <signals.json>] | ||
|
|
||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath, pathToFileURL } from "node:url"; | ||
| import { | ||
| type AdvisorySignal, | ||
| correlateAdvisories, | ||
| type InventoryEntry, | ||
| parseInventoryFromAuditConfig, | ||
| parseInventoryFromPackageLock, | ||
| } from "./lib/advisory-early-warning.mts"; | ||
|
|
||
| const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); | ||
| const CONFIG_RELATIVE_PATH = path.join("ci", "reviewed-npm-audit.json"); | ||
|
|
||
| function loadReviewedInventory(): InventoryEntry[] { | ||
| const config = JSON.parse( | ||
| fs.readFileSync(path.join(REPO_ROOT, CONFIG_RELATIVE_PATH), "utf-8"), | ||
| ) as Record<string, unknown>; | ||
| const inventory = parseInventoryFromAuditConfig(config, CONFIG_RELATIVE_PATH); | ||
| const lockedGraphs = Array.isArray(config.lockedGraphs) ? config.lockedGraphs : []; | ||
| for (const graph of lockedGraphs) { | ||
| const directory = (graph as Record<string, unknown> | null)?.directory; | ||
| if (typeof directory !== "string" || directory.length === 0) continue; | ||
| const lockRelativePath = path.join(directory, "package-lock.json"); | ||
| const lockPath = path.join(REPO_ROOT, lockRelativePath); | ||
| if (!fs.existsSync(lockPath)) continue; | ||
| const lock = JSON.parse(fs.readFileSync(lockPath, "utf-8")) as unknown; | ||
| inventory.push(...parseInventoryFromPackageLock(lock, lockRelativePath)); | ||
| } | ||
| return inventory; | ||
| } | ||
|
|
||
| function loadAdvisories(advisoriesPath: string): unknown[] { | ||
| const parsed = JSON.parse(fs.readFileSync(advisoriesPath, "utf-8")) as unknown; | ||
| return Array.isArray(parsed) ? parsed : [parsed]; | ||
| } | ||
|
|
||
| function describeSignal(signal: AdvisorySignal): string { | ||
| return `${signal.advisoryId} ${signal.package} ${signal.vulnerableRange || "(no range)"} -> ${signal.action} (${signal.confidence}, matched ${signal.matchedVersions.join(", ")})`; | ||
| } | ||
|
|
||
| function readFlagValue(argv: readonly string[], flag: string): string | undefined { | ||
| const index = argv.indexOf(flag); | ||
| if (index < 0) return undefined; | ||
| const value = argv[index + 1]; | ||
| if (value === undefined || value.startsWith("--")) { | ||
| throw new Error(`${flag} requires a value`); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| function main(argv: readonly string[]): void { | ||
| const inventory = loadReviewedInventory(); | ||
| if (argv.includes("--list-packages")) { | ||
| const names = [...new Set(inventory.map((entry) => entry.name))].sort(); | ||
| for (const name of names) console.log(name); | ||
| return; | ||
| } | ||
| const advisoriesPath = readFlagValue(argv, "--advisories"); | ||
| if (!advisoriesPath) { | ||
| throw new Error( | ||
| "usage: advisory-early-warning-scan.mts --list-packages | --advisories <file> [--output <file>]", | ||
| ); | ||
| } | ||
| const advisories = loadAdvisories(advisoriesPath); | ||
| const signals = correlateAdvisories(advisories, inventory); | ||
| const outputPath = readFlagValue(argv, "--output"); | ||
| if (outputPath) { | ||
| fs.writeFileSync(outputPath, `${JSON.stringify(signals, null, 2)}\n`); | ||
| } | ||
| console.log( | ||
| `advisory early warning: ${advisories.length} advisories, ${inventory.length} inventory entries, ${signals.length} signals`, | ||
| ); | ||
| for (const signal of signals) console.log(describeSignal(signal)); | ||
| // Signals are intentionally non-blocking: the process exits 0 either way, | ||
| // and the caller routes signals to a tracking issue for investigation. | ||
| } | ||
|
|
||
| function isMainModule(): boolean { | ||
| return process.argv[1] | ||
| ? import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href | ||
| : false; | ||
| } | ||
|
|
||
| if (isMainModule()) { | ||
| try { | ||
| main(process.argv.slice(2)); | ||
| } catch (error) { | ||
| console.error(error instanceof Error ? error.message : String(error)); | ||
| process.exit(1); | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.