Files
pruefwerk/scripts/vex-994-cleanup.js
T
sharangandClaude Opus 5.5 87b1e281ed
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Docs (push) Successful in 1m19s
CI / Deploy MCP (push) Successful in 2m42s
CI / Deploy Dashboard (push) Successful in 6m14s
CI / Deploy Agent (push) Successful in 8m42s
fix(vex): a CVE a scan no longer finds is not stated fixed (#994) (#1015)
A scan never states VEX `fixed`. When a scan stops finding a CVE, its tracker issue stays open and gets one comment; a person closes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
2026-11-27 22:23:03 +00:00

54 lines
1.8 KiB
JavaScript

// #994: count, and only on request remove, the VEX `fixed` statements that
// scans inferred from a CVE no longer being found (before the fix, Weg A).
//
// Since the fix, every reader ignores them (`CveAlert::statement`), so the
// stored statements no longer reach an export, the dashboard or a tracker.
// This script removes them from the data too; whether and when it runs is the
// owner's decision on #994. The alerts keep `resolved_at`: that the scan no
// longer finds the CVE stays recorded, as an observation.
//
// A statement counts when a scan made it (`by_scan`), it says `fixed`, and it
// gives no reason (`impact_statement`). A scan's statement from the target's
// own data (a Yocto recipe's patch) always gives one, so it is never matched.
//
// It prints counts only, never a database, target or CVE. Dry run unless
// `apply` is true:
//
// mongosh "$MONGODB_URI" --quiet \
// --eval 'var prefix = "<DB prefix>", apply = false' \
// scripts/vex-994-cleanup.js
if (typeof prefix !== "string" || prefix === "") {
throw new Error("set prefix, the agent's database prefix");
}
const write = typeof apply !== "undefined" && apply === true;
const inferred = {
"vex.by_scan": true,
"vex.status": "fixed",
"vex.impact_statement": null,
};
let databases = 0;
let matched = 0;
let removed = 0;
for (const { name } of db.adminCommand({ listDatabases: 1, nameOnly: true }).databases) {
if (!name.startsWith(prefix + "_")) {
continue;
}
const alerts = db.getSiblingDB(name).getCollection("cve_alerts");
const count = alerts.countDocuments(inferred);
if (count === 0) {
continue;
}
databases += 1;
matched += count;
if (write) {
removed += alerts.updateMany(inferred, { $unset: { vex: "" } }).modifiedCount;
}
}
print(
JSON.stringify({ mode: write ? "apply" : "dry-run", databases, statements: matched, removed }),
);