Skip to content

ci: scan a full node build for known CVEs every week - #63

Merged
seberm merged 8 commits into
bitcoinix:masterfrom
ostermayer:cve-scan
Oct 27, 2026
Merged

seberm merged 8 commits into
bitcoinix:masterfrom
ostermayer:cve-scan

Conversation

@ostermayer

@ostermayer ostermayer commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #16 (section 5)

Problem

bitcoinix has no routine check for known CVEs in the software it deploys. The project ships NixOS modules rather than a flat package set, so a package-level scan misses what a node really runs, and a scan of a test-derivation closure reports build tools that never run on a node.

Change

  • test/ci/scan-node.nix builds a representative node: the secure-node and WireGuard presets plus bitcoind, clightning (with clnrest and encrypted replication), lnd, charge-lnd, electrs, fulcrum, btcpayserver (lnd backend), mempool, rtl (both node interfaces), backups and nodeinfo. Hardware wallets are host tooling, so they're left out.
  • test/ci/cve-scan.sh builds that node and runs vulnix --closure on its system toplevel, which is the RUNTIME closure (nix path-info -r). Without --closure vulnix scans nix-store -qR of the deriver, the build closure, which is what the fork's version did, and its whitelist of compilers was masking that. The script fails closed: a failed build, a vulnix error exit, or a report that isn't a JSON array of well-formed entries fails the job and never reads as a clean scan. The per-package CVSS shown in the summary is the max over the non-whitelisted CVEs only.
  • .github/cve-whitelist.toml contains only vulnix pname collisions (git, dash, snappy, uuid), each scoped to explicit CVE ids, and no blanket pname entries. The fork's [nix] entry for CVE-2024-27297 is dropped, because it was meant for the Rust nix crate, which isn't in a runtime closure, and it would've masked a real Nix package-manager finding.
  • .github/workflows/cve-scan.yml runs the scan every Monday and on demand. Every run writes the summary to the step summary and uploads the report as an artifact. If the repository variable CVE_SCAN_ISSUE holds the number of a pinned tracking issue, test/ci/cve-report.sh keeps the part of that issue's body below a <!-- cve-scan-report --> line current and leaves everything above it to people. It stores the sorted set of active CVEs in an HTML comment in the body, writes nothing when the set is unchanged, and on a change posts one comment listing the new and the resolved CVEs. It never opens, closes or labels issues. The variable reaches the script through the environment and has to be digits. The workflow only reads the bitcoinix Cachix cache, has no signing key, pins actions by commit SHA, and isn't part of ci_gate. It caches ~/.cache/vulnix between runs, because NVD serves the yearly feeds at a few tens of KB/s to anonymous clients and vulnix gives up after 10 s without data and discards the partial update, so a cold run from a slow connection fails outright. With the cache a run fetches only the modified feed, and the script retries the scan up to five times to ride out short stalls.
  • SECURITY.md describes the scan, where the report goes, who triages it and what a whitelist entry needs.
  • .github/CODEOWNERS covers the whitelist and the workflow, because a whitelist edit can hide a real finding and should get the same review as the release tooling.

Ported from the fork ostermayer/nix-bitcoin with the --closure fix.

Testing

Run Result
./test/ci/cve-scan.sh on a Linux box with Nix, this branch node toplevel builds, vulnix exit 2 (findings), found=true, summary written
./test/shellcheck.sh PASS
test/ci/cve-report.sh against a stubbed gh, 12 scenarios (fresh issue, unchanged set, CRLF body, changed set with a human edit kept, clean after findings, markerless issue with a clean scan, non-numeric variable, failed gh issue view, oversized comment and body) PASS
bash -n, YAML parse of the workflow PASS

The first real run reported 22 store paths with non-whitelisted CVEs at the pin of that time: glibc, perl, zlib, openssl 3.5.8, sqlite, openssh 10.5p1, dbus, dhcpcd, jq, nghttp2, coreutils, cups, avahi, libusb, busybox, ada (the URL parser linked into Node.js, used by rtl and mempool), plus gcc (CVE-2023-4039) and patch. The last two are in the runtime closure because libgcc shares the gcc derivation and some package keeps a reference to patch. Neither runs on a node, but I left them reported rather than whitelisting a whole pname. That list is the expected shape of the first tracking issue, and most entries are nixpkgs-wide and get fixed by moving the pin.

A cold run on a KVM host on 2026-10-22 failed five times in a row on the NVD download, which is what the cache step is for. The scan node itself evaluates and builds on current master.

Models used on this PR: Fable 5.1 and Opus 5.5 for the changes. Kimi K3, GLM 5.3 and DeepSeek V4.1 Flash 1017, all at max thinking, and GPT-6 Astra at xhigh reasoning reviewed earlier revisions in the audit runs over the open branches and found no problem in the changed files. Fable 5.1 made the 2026-10-22 revision (rebase, the scan node without the removed services, the cache and the retries), and Astra reviewed it: it corrected my claim that retries resume a download, and found nothing else. DeepSeek and GLM, both at max thinking, reviewed the tree of this revision and found nothing in the workflow, the script, the scan node or the whitelist. Their two findings elsewhere are master code that #25, #48 and #133 already cover.

The second commit (3a3fbb5) replaces the issue search, create and close logic after seberm's review. Fable 5.1 planned it, Opus 5.5 wrote the first draft, Codex (GPT-6 Astra, xhigh) reviewed the uncommitted diff and found five real problems that were fixed before the push, GLM 5.3 (max) reviewed the tree at 3a3fbb5 and found nothing in the files this PR touches, and DeepSeek V4.1 Flash 1017 (max) timed out at the provider and gave no result.

@ostermayer

ostermayer commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Force-pushed: dropped the [nix] whitelist entry (meant for the Rust crate, which a runtime closure doesn't contain; it would have masked a real Nix CVE) and silenced a shellcheck SC2016 note on the jq program. Re-ran the scan: same 22 findings, nothing about nix.

@ostermayer

Copy link
Copy Markdown
Collaborator Author

Added the whitelist and the workflow to CODEOWNERS, same owners as the release tooling: an edit to cve-whitelist.toml can hide a real finding from the weekly report.

@ostermayer

Copy link
Copy Markdown
Collaborator Author

Scan node now also imports the WireGuard preset (wireguard-tools, qrencode, lndconnect) and enables encrypted clightning replication (gocryptfs), so those parts of the shipped closure are scanned too. Re-ran on a Linux box: builds, same 22 findings.

@ostermayer ostermayer changed the title ci: weekly vulnix CVE scan of a representative node closure ci: scan a representative node closure for CVEs every week Oct 17, 2026
@ostermayer ostermayer changed the title ci: scan a representative node closure for CVEs every week ci: scan a full node build for known CVEs every week Oct 17, 2026
@github-actions github-actions Bot added area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets labels Oct 22, 2026
@ostermayer
ostermayer force-pushed the cve-scan branch 3 times, most recently from 6c2bc1e to f6ad969 Compare October 23, 2026 15:49
@seberm seberm added the type: feature New capability or service label Oct 23, 2026
@seberm

seberm commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Hello, I went through this PR with AI agent to collect some ideas and problems. I'm still not sure whether these reports might get too noisy. Maybe we should just run the scans without reporting to an issue, or send all reports to one fixed issue (which we could pin, for example).

btw - none of the points below is a hard requirement, and there may be a better approach.

Thanks!


The scan itself looks solid. My doubts are about how the findings are reported. None of this is a hard requirement, and there may be a better approach.

Concerns

  • Noise. vulnix matches CVEs by version and doesn't see nixpkgs patches. Most of the first run's 22 findings (glibc, openssl, zlib, ...) only change when we bump the pin, so I expect the same list every week, an issue that never closes, and a comment every Monday.
  • Issue lookup. --search "$title in:title" matches words, not the exact title, and .[0] takes the first hit, so the job can pick an issue a person wrote, overwrite its body and close it. It also only searches open issues: if we close the issue as noise, next Monday opens a new one.
  • Triage history. The body is replaced on every run, so triage notes don't survive there. The only way to stop reporting a triaged CVE is a whitelist entry, and since the whitelist is under CODEOWNERS, every one is a review for @seberm or @prusnak. That ongoing work should be described in the PR and in SECURITY.md (who triages, how often, what an entry needs).
  • Label. The job looks for a label named security, but ours is type: security, so issues get no label. type: security + area: packages would fit.

Ideas

  • Start without issues: write the summary to $GITHUB_STEP_SUMMARY for a few weeks and see how noisy it is.
  • Use one pinned, pre-created issue with its number in a repo variable, so there's no search and no new issues. Or at least match the exact title and the bot author.
  • Comment only when the findings change, e.g. keep a hash of the sorted CVE list in the body (<!-- sha: … -->) and post only new/resolved CVEs.
  • Consider vulnxscan (sbomnix): it drops CVEs that nixpkgs already patches, and can write SARIF for GitHub code scanning. Each CVE then becomes an alert you can dismiss with a reason. Trade-offs: needs security-events: write, and only people with write access see the alerts.

Did you look at vulnxscan/SARIF, or is there a reason vulnix + an issue fits better?

@ostermayer

Copy link
Copy Markdown
Collaborator Author

Thanks, those are fair points. I pushed 3a3fbb5 on top of a rebase to master with your design.

What changed:

  • The summary goes to the run's step summary and the artifact on every run. A failed scan writes "did not complete" there instead of nothing.
  • No search and no issue creation any more. If you set the repository variable CVE_SCAN_ISSUE to the number of a pinned issue, test/ci/cve-report.sh keeps the part of its body below a <!-- cve-scan-report --> line current. Everything above the line is yours, so the description and triage notes stay. Without the variable the job only writes the step summary, so you can run it for a few weeks first and see how noisy it is.
  • It comments only when the set of active CVEs changes, and the comment lists the new and the resolved ones. The set is stored sorted in an HTML comment in the body, so a stable list writes nothing. The comment goes out before the body is saved, so a failed comment fails the job and the next run retries it.
  • It never opens, closes or labels issues. The label logic is gone. The variable reaches the script through the environment and has to be digits.
  • SECURITY.md says where the report goes, who triages and when (a maintainer, when the set changes, which in practice is after a pin bump), the three outcomes, and what a whitelist entry needs. The whitelist stays under CODEOWNERS.
  • cve-scan.sh now requires the vulnix fields instead of substituting empty arrays, so a malformed report fails the job and can't mark every CVE as resolved.

On the noise premise: vulnix does see nixpkgs patches. It drops a CVE when a patch filename in the derivation carries that CVE id (the CVE patch auto-detection section in its README), and vulnxscan uses the same filename heuristic. So the stable part of the list is CVEs that nixpkgs hasn't patched or bumped past yet, plus NVD entries with wrong version ranges. That list only changes with the pin, which is why the job now only speaks when it changes.

On vulnxscan: I looked at it. It aggregates vulnix, grype and OSV. Its docs say the OSV queries don't specify the ecosystem and return false positives for Nix, and grype needs its own database download, so I'd expect more noise, not less, and a much bigger tool closure. The SARIF route is real and dismissing an alert with a reason is nicer than a whitelist file, but only people with write access see the alerts and it needs security-events: write. I'd start with the step summary and the pinned issue and move to SARIF later if you want the alert workflow. Happy to do that as a follow-up.

Testing: test/ci/cve-report.sh ran against a stubbed gh in 12 scenarios (a fresh issue with a description, an unchanged set, a CRLF body from the web editor, a changed set with a human edit above the line, clean after findings, a markerless issue with a clean scan, a non-numeric variable, a failed gh issue view, and sets too big for a comment or a body). shellcheck passes on both scripts and CI is green.

Models: Fable 5.1 planned the change and Opus 5.5 wrote the first draft. Codex (GPT-6 Astra, xhigh) reviewed the uncommitted diff and found five real problems that I fixed (CRLF bodies, a clean first run that never initialized the issue, no comment size limit, a lost comment when the body was saved first, and the inherited shape check). GLM 5.3 (max) reviewed the tree at 3a3fbb5 and found nothing in the files this PR touches. Its three findings elsewhere are #107, a point #48 already fixes, and the Trezor bridge, which I filed as #153. Astra graded those three too and agreed on the first two. DeepSeek V4.1 Flash 1017 (max) timed out at the provider and gave no result.

@seberm
seberm enabled auto-merge October 26, 2026 12:22
@seberm
seberm disabled auto-merge October 26, 2026 12:22
@seberm

seberm commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@ostermayer Thanks, you're right about vulnix: it skips CVEs named in patch filenames, so my noise premise was wrong.

  • CODEOWNERS: let's leave the two new entries out for now. The workflow and the whitelist aren't the only files that decide what gets reported (cve-scan.sh, cve-report.sh and scan-node.nix do too), and ownership of only some of them doesn't buy much. Please drop the SECURITY.md sentence about code owners reviewing the whitelist with it.
  • stored_set takes the first set block anywhere in the body. If someone deletes the marker line, the old set ends up in the part above it and every later run comments again. Could you read the set only below the marker? Not a blocker; a follow-up is fine if you prefer.
  • The set doesn't only change with the pin: every run fetches NVD's modified feed, so a newly published CVE or a corrected version range for a package we already ship changes it too. That's the main reason to scan weekly, so SECURITY.md shouldn't say "in practice, after a nixpkgs pin bump".

@seberm

seberm commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@prusnak any opinion on this one? I'd give it a try and see how well it works in the long run.

bitcoinix ships NixOS modules, not a flat package set, so the meaningful
CVE scan target is the runtime closure of a built node.
test/ci/scan-node.nix builds a representative node (the secure-node preset
with every shipped service and backups enabled), and test/ci/cve-scan.sh
runs vulnix on its system toplevel.

Build-time dependencies that still reach that closure (compilers, build
systems, VCS used to fetch sources) are not run on a deployed node; they
are whitelisted pname-wide in .github/cve-whitelist.toml. Known vulnix
pname collisions are whitelisted per CVE only.

The scan fails closed: a failed build, a vulnix error exit, or a report
that is not a JSON array of well-formed entries fails the job instead of
reading as a clean scan.

.github/workflows/cve-scan.yml runs the scan weekly and on demand. New
findings open or update a `[cve-scan]` tracking issue; a clean scan
closes it. SECURITY.md documents this.

Ported from the fork ostermayer/nix-bitcoin.

NVD serves the yearly 2.0 feeds at a few tens of KB/s to anonymous
clients, and vulnix aborts after 10 s without data and discards the
partial update. The workflow caches ~/.cache/vulnix between runs, so a
run normally fetches only the `modified` feed, and the script retries
the scan up to five times to ride out short stalls.

Assisted-by: Codex (GPT-6)
The first version searched for a tracking issue by title, opened one on
findings and closed it on a clean scan. A title search matches words and
takes the first hit, so it could overwrite and close a human's issue, and the
same findings produced a comment every week.

Every run now writes the summary to the step summary and uploads it as an
artifact. When the CVE_SCAN_ISSUE repository variable holds the number of a
pinned issue, test/ci/cve-report.sh keeps that issue current: it stores the
sorted set of active CVEs in an HTML comment in the body, writes nothing when
the set is unchanged, and on a change posts one comment listing new and
resolved CVEs before it rewrites the report part of the body. Everything
above the <!-- cve-scan-report --> line is left to people. The script never
creates, closes or labels issues. The variable reaches the script through
the environment and must be digits.

cve-scan.sh writes the set as cve-set.txt and now requires the vulnix fields
instead of substituting empty arrays, so a malformed report fails the job
rather than resolving every tracked CVE. SECURITY.md describes where the
report goes and how a finding is triaged.

Assisted-by: Codex (GPT-6)
Add offline fixtures for the scanner and issue reporter as a flake check. Evaluate the representative scan node in check_flake so module changes cannot silently break the scheduled target.

Assisted-by: Codex (GPT-6)
Run on Mondays and Thursdays so ordinary runs stay within the strict seven-day limit for incremental NVD updates. Document that cold caches and longer gaps still need the yearly feeds.

Assisted-by: Codex (GPT-6)
Ignore stored sets above the report marker when comparing findings or detecting initialization. Recover from a deleted marker without overwriting human text or repeating notifications on later runs.

Assisted-by: Codex (GPT-6)
Diff package/CVE identities so upgrades do not report an unfixed CVE as resolved and new. Count each identity once across vulnerable versions, while preserving version details in the stored report and artifacts.

Assisted-by: Codex (GPT-6)
Remove the new whitelist and workflow entries and the corresponding documentation claim. The scan scripts and node definition also determine findings, so ownership of only two files does not cover the reporting behavior.

Assisted-by: Codex (GPT-6)
Describe newly published CVEs and corrected affected-version ranges as reasons findings change even when package pins stay the same.

Assisted-by: Codex (GPT-6)
@prusnak

prusnak commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@prusnak any opinion on this one?

yeah, let's try this - rebased the PR and added 6 more commits suggested by Astra (some of them implementing your suggestions)

@github-actions github-actions Bot added the area: packages pkgs/ and flake pins label Oct 27, 2026

@seberm seberm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prusnak thanks, the six commits look good. I'll probably also create a pinned issue for CVE_SCAN_ISSUE so we can test that part of the feature too.

Opus 5.5 review:


One thing for later, not blocking: since the compare ignores versions, a pin bump that changes only package versions writes nothing to the issue. The body then shows the old versions and the old scan date until the package/CVE pairs change (test_version_only_change_does_not_notify checks for exactly that). Notifications are right, but someone reading the pinned issue can't tell how current it is.

Suggested fix: when the versioned set changes but the pairs don't, rewrite the report part of the body without a comment. Body edits don't notify anyone. Alternatively, say in the report that the date is the last change, not the last scan.

@seberm
seberm merged commit edff94e into bitcoinix:master Oct 27, 2026
9 of 10 checks passed
@seberm

seberm commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Tracking issue created here:

I've configured the CVE_SCAN_ISSUE repository variable.

Testing the cve-scan workflow here:

@seberm

seberm commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

@ostermayer the scan works. I opened #159 for triaging the first findings. Would you take a first pass?

seberm added a commit that referenced this pull request Oct 28, 2026
…ange (#162)

cve-report.sh wrote nothing to the pinned tracking issue when the set
of package/CVE pairs was unchanged. After a pin bump that only moved
versions, or after a plain rerun, the body kept the old versions and
the old scan date, so nobody could tell how current it was.

The script now renders the new body first and compares it with the
stored one. Different pairs: one comment, then the body edit, as
before. Same pairs and a different body: the body is edited without a
comment. Same body: nothing is written. Trailing newlines don't count
as a change, because gh prints one that the stored body doesn't have.

The summary carries the scan time, so every completed scan now
refreshes the body. Body edits don't notify anyone; comments still go
out only when the pairs change. A failed scan leaves the body as it
was. An oversized set now fails the job even when the pairs didn't
change.

SECURITY.md says the body shows the last run. Tests cover the refresh,
idempotence and that the part above the marker survives.

Follow-up to #63.
@ostermayer
ostermayer deleted the cve-scan branch November 8, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: packages pkgs/ and flake pins type: feature New capability or service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants