Repository navigation
feat(security): schedule the advisory early-warning scan #7398
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 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 206944d
feat(security): schedule the advisory early-warning scan
Dongni-Yang 9cf4f42
Merge branch 'main' into dongniy/7338-early-warning-workflow
Dongni-Yang 045b81c
feat(security): reconcile scheduled early-warning signals with NVD
Dongni-Yang 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
| 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" | ||
|
|
||
| - 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 | ||
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.
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.