Skip to content
Closed
244 changes: 244 additions & 0 deletions .github/workflows/advisory-early-warning.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Advisory early warning (#7338): every six hours, fetch public GitHub Security
# Advisories that name packages in the reviewed npm inventory and correlate them
# with scripts/advisory-early-warning-scan.mts. All three advisory types are
# fetched: "reviewed" records (the corpus npm audit already enforces, so a
# match means enforcement is imminent or active), "unreviewed" records
# (NVD-sourced, often published before curation reaches the reviewed feed —
# these commonly lack a verified npm mapping and flow through the module's
# ambiguous, informational-only path), and "malware" records (npm malware
# advisories naming an inventory package). Matches surface as a rolling,
# security-labeled tracking issue — a traceable, NON-blocking investigation
# signal. Signals that carry a CVE id are additionally reconciled against NVD,
# a SUPPLEMENTARY informational source that never overrides the reviewed npm
# mapping and whose outages degrade gracefully. Enforcement stays with the
# reviewed npm audit gate; this workflow never fails a build or mutates a
# release.

name: Security / Advisory Early Warning

on:
schedule:
- cron: "41 */6 * * *"
workflow_dispatch:

permissions:
contents: read
issues: write

concurrency:
group: advisory-early-warning
cancel-in-progress: false

jobs:
early-warning:
if: github.repository == 'NVIDIA/NemoClaw'
runs-on: ubuntu-latest
# NVD reconciliation worst case adds ~12 minutes (20 requests, 7 s apart,
# 30 s timeout each), on top of the advisory fetch.
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false

- name: Setup production-compatible Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: "22.22.2"

- name: Fetch advisories naming reviewed inventory packages
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
node --experimental-strip-types scripts/advisory-early-warning-scan.mts \
--list-packages >"$RUNNER_TEMP/inventory-packages.txt"
batches=()
batch=""
batch_count=0
while IFS= read -r package_name; do
[ -n "$package_name" ] || continue
if [ -z "$batch" ]; then
batch="$package_name"
else
batch="$batch,$package_name"
fi
batch_count=$((batch_count + 1))
if [ "$batch_count" -ge 25 ]; then
batches+=("$batch")
batch=""
batch_count=0
fi
done <"$RUNNER_TEMP/inventory-packages.txt"
[ -z "$batch" ] || batches+=("$batch")
: >"$RUNNER_TEMP/advisory-records.jsonl"
for advisory_type in reviewed unreviewed malware; do
for batch in "${batches[@]}"; do
gh api -X GET /advisories \
-f "type=$advisory_type" \
-f ecosystem=npm \
-f "affects=$batch" \
-f per_page=100 \
--paginate \
--jq '.[]' >>"$RUNNER_TEMP/advisory-records.jsonl"
done
done
jq -s 'unique_by(.ghsa_id)' "$RUNNER_TEMP/advisory-records.jsonl" \
>"$RUNNER_TEMP/advisories.json"
echo "Fetched $(jq 'length' "$RUNNER_TEMP/advisories.json") advisory records"

- name: Correlate advisories with the reviewed inventory
run: |
set -euo pipefail
node --experimental-strip-types scripts/advisory-early-warning-scan.mts \
--advisories "$RUNNER_TEMP/advisories.json" \
--output "$RUNNER_TEMP/signals.json"

- name: Reconcile signals with NVD (supplementary, non-blocking)
run: |
set -euo pipefail
signals="$RUNNER_TEMP/signals.json"
# NVD is a SUPPLEMENTARY reconciliation source (#7338). This is a
# deliberate contrast with the GitHub advisory fetch above, which
# fails loudly because no signals can exist without it: losing NVD
# data only loses an informational annotation, so NVD being down or
# rate-limited degrades gracefully to an "NVD: unavailable"
# annotation and never fails the workflow.
: >"$RUNNER_TEMP/nvd-unavailable.txt"
: >"$RUNNER_TEMP/nvd-skipped.txt"
: >"$RUNNER_TEMP/nvd-records.jsonl"
jq -r '[.[] | .cveId // empty] | unique | .[]' "$signals" \
>"$RUNNER_TEMP/nvd-cve-ids.txt"
mapfile -t cve_ids <"$RUNNER_TEMP/nvd-cve-ids.txt"
total="${#cve_ids[@]}"
cap=20
if [ "$total" -gt "$cap" ]; then
# No silent caps: unauthenticated NVD allows ~5 requests per 30 s,
# so one run reconciles at most $cap CVE ids; the rest are listed
# in the rolling issue without an NVD annotation.
echo "NVD reconciliation capped at $cap of $total CVE ids this run (unauthenticated NVD rate limit); $((total - cap)) CVE ids left unannotated."
printf '%s\n' "${cve_ids[@]:$cap}" >"$RUNNER_TEMP/nvd-skipped.txt"
fi
first=1
for cve_id in "${cve_ids[@]:0:$cap}"; do
# cveId values only reach signals when they match
# ^CVE-\d{4}-\d{4,}$ (scripts/lib/nvd-reconciliation.mts), so they
# are URL-safe as-is. Space requests ~7 s apart to respect the
# ~5-requests-per-30-s unauthenticated NVD rate limit.
[ "$first" -eq 1 ] || sleep 7
first=0
# Only a response carrying the NVD envelope (a vulnerabilities
# array — empty for reserved ids) counts as answered; a 200 with a
# JSON error body degrades to "unavailable" like any other outage.
if response="$(curl -sS --fail --max-time 30 \
"https://services.nvd.nist.gov/rest/json/cves/2.0?cveId=$cve_id")" \
&& record="$(jq -ce 'select(.vulnerabilities | type == "array")' \
<<<"$response" 2>/dev/null)"; then
printf '%s\n' "$record" >>"$RUNNER_TEMP/nvd-records.jsonl"
echo "Fetched NVD record for $cve_id"
else
echo "NVD unavailable for $cve_id; annotating the signal with 'NVD: unavailable'."
printf '%s\n' "$cve_id" >>"$RUNNER_TEMP/nvd-unavailable.txt"
fi
done
jq -s '.' "$RUNNER_TEMP/nvd-records.jsonl" >"$RUNNER_TEMP/nvd-records.json"
node --experimental-strip-types scripts/advisory-early-warning-scan.mts \
--advisories "$RUNNER_TEMP/advisories.json" \
--nvd-records "$RUNNER_TEMP/nvd-records.json" \
--output "$signals"

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
- name: Create or update the rolling early-warning issue
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
signals="$RUNNER_TEMP/signals.json"
count="$(jq 'length' "$signals")"
if [ "$count" -eq 0 ]; then
echo "No early-warning signals; nothing to report."
exit 0
fi
title="Advisory early warning: reviewed npm inventory signals"
marker="<!-- nemoclaw-advisory-early-warning -->"
body_file="$RUNNER_TEMP/issue-body.md"
# One line per advisoryId+package signal. Column 1 is the dedupe key
# ("<advisoryId> <package>") and is embedded verbatim in the line,
# always followed by a space (the range column falls back to
# "(no range)"), so existing bodies are checked with a fixed-string
# grep for "<key> " — a prefix-sibling package (tar vs tar-stream)
# can never falsely dedupe. Advisory free text is sanitized so it
# cannot split lines or corrupt the TSV. The NVD reconciliation
# extends the line TEXT only, never the dedupe key: a line appended
# before its NVD annotation was available is not re-appended later.
# Fetch-failed CVE ids override the re-scan's "nvd-missing" (which
# would falsely claim NVD answered), and capped-out CVE ids carry no
# NVD note at all.
jq -r --rawfile nvd_unavailable "$RUNNER_TEMP/nvd-unavailable.txt" \
--rawfile nvd_skipped "$RUNNER_TEMP/nvd-skipped.txt" '
($nvd_unavailable | split("\n") | map(select(length > 0))) as $nvdDown |
($nvd_skipped | split("\n") | map(select(length > 0))) as $nvdSkipped |
.[] |
(.cveId // "") as $cve |
(.advisoryId + " " + (.package | gsub("[\\r\\n\\t]"; " "))) as $key |
(if ($nvdDown | index($cve)) != null then " — NVD: unavailable"
elif ($nvdSkipped | index($cve)) != null then ""
elif .nvd then
" — NVD: " + .nvd.agreement +
(if .nvd.nvdPublished != null
then " (published " + (.nvd.nvdPublished | .[0:10]) + ")"
else "" end)
else "" end) as $nvdNote |
[$key,
"- [ ] " + $key + " " +
(if .vulnerableRange == "" then "(no range)"
else (.vulnerableRange | gsub("[\\r\\n\\t]"; " ")) end) +
" [" + .action + ", " + .confidence + ", matched " +
(.matchedVersions | join(" ")) + "] (source: " + .source + ")" +
$nvdNote] |
@tsv' "$signals" >"$RUNNER_TEMP/signal-lines.tsv"
# Only trust a rolling issue this workflow created itself: it must be
# authored by the Actions bot AND carry the embedded marker. A
# lookalike security-labeled issue must not become the sink (it could
# pre-seed dedupe keys to suppress real signals).
existing="$(gh issue list --repo "$REPO" --label security --state open \
--author "app/github-actions" \
--search "\"$title\" in:title" \
--json number,body |
jq --arg marker "$marker" '[.[] | select(.body | contains($marker))][0] // empty')"
if [ -z "$existing" ]; then
{
echo "$marker"
echo ""
echo "Automated, non-blocking early-warning signals: public GitHub Security"
echo "Advisories that plausibly affect the reviewed npm inventory before or"
echo "beyond what the reviewed npm audit gate currently enforces (#7338)."
echo "Ambiguous matches are informational only and must not block a release."
echo ""
cut -f2 "$RUNNER_TEMP/signal-lines.tsv"
} >"$body_file"
gh issue create --repo "$REPO" --label security --title "$title" \
--body-file "$body_file"
echo "Created rolling early-warning issue"
exit 0
fi
issue_number="$(jq -r '.number' <<<"$existing")"
jq -r '.body' <<<"$existing" >"$body_file"
appended=0
while IFS=$'\t' read -r dedupe_key line; do
[ -n "$dedupe_key" ] || continue
if ! grep -qF "$dedupe_key " "$body_file"; then
printf '%s\n' "$line" >>"$body_file"
appended=1
fi
done <"$RUNNER_TEMP/signal-lines.tsv"
if [ "$appended" -eq 1 ]; then
gh issue edit "$issue_number" --repo "$REPO" --body-file "$body_file"
echo "Updated rolling early-warning issue #$issue_number"
else
echo "Rolling early-warning issue #$issue_number already lists every signal."
fi
57 changes: 49 additions & 8 deletions docs/security/advisory-early-warning.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

# 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).
Status: correlation module, scan CLI, and audit provenance implemented. The
scheduled workflow and the policy defaults below are proposals and take effect
only after 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
Expand Down Expand Up @@ -71,11 +72,51 @@ node --experimental-strip-types scripts/advisory-early-warning-scan.mts \
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.
## Scheduled operation

`.github/workflows/advisory-early-warning.yaml` runs every six hours (and on
manual dispatch): it fetches reviewed, unreviewed, and malware advisories
naming inventory packages (paginated, batched by package), runs
`scripts/advisory-early-warning-scan.mts`, and routes signals into one rolling
GitHub issue labeled `security`, deduplicated by advisory id plus package. Only
an OPEN issue authored by the Actions bot that carries the workflow's embedded
marker is reused; otherwise a fresh issue is created. Closing the rolling issue
while its signals still apply therefore makes the next run open a fresh issue
re-listing them (the dedupe state lives in the open issue body), so close it
only once the listed advisories are resolved for the inventory. The workflow is
non-blocking by design and never fails a build.

Signals that carry a CVE id are reconciled against NVD in the same run
(supplementary only — see the NVD reconciliation section above):

- The workflow queries at most 20 CVE ids per run, spaced 7 seconds apart, to
respect the unauthenticated NVD rate limit of roughly five requests per 30
seconds; when the cap truncates the list it says so in the run log rather
than skipping silently. An NVD outage or rate-limit degrades gracefully to
an `NVD: unavailable` annotation — deliberately unlike the GitHub advisory
fetch, which fails loudly because signals cannot be computed without it.
- NVD annotations extend the rolling issue's line text only. The dedupe key
(advisory id plus package) is unchanged, so a line appended before its NVD
annotation was available is not re-appended later.

## Proposed policy defaults (pending maintainer confirmation)

The following defaults answer #7338's open policy questions. They are
proposals only and take effect when product/security owners confirm them.

- Scope: the reviewed graphs committed in `ci/reviewed-npm-audit.json`
(archive packages and locked graphs). Historical immutable image digests are
out of scope until owners define a supported-image list.
- Rescan ownership: repository maintainers, driven by the rolling
`security`-labeled early-warning issue; the six-hour schedule is the default
rescan trigger for advisory-database changes.
- Alert destination: the rolling GitHub issue created by the early-warning
workflow (one issue, deduplicated by advisory id plus package).
- Response expectation for `action: "investigate"` signals: acknowledge
Critical within 1 business day and resolve or escalate within 3; acknowledge
High within 2 business days and resolve or escalate within 5. While a
reviewed mapping is unavailable, unresolved High/Critical signals escalate to
a maintainer decision rather than automatically blocking a release.

## Provenance recorded per audit

Expand Down
Loading