// #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 = "", 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 }), );