@profullstack/threatcrush 0.13.32 → 0.13.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7380,11 +7380,11 @@ function solve(total, items, gap = 0) {
7380
7380
  }
7381
7381
  }
7382
7382
  let assigned = 0;
7383
- const order = [...pending];
7384
- order.forEach((i, k) => {
7383
+ const order2 = [...pending];
7384
+ order2.forEach((i, k) => {
7385
7385
  const p = parsed[i];
7386
7386
  const exact = remainingFr > 0 ? pool * p.fr / remainingFr : 0;
7387
- const v = k === order.length - 1 ? Math.max(0, pool - assigned) : Math.floor(exact);
7387
+ const v = k === order2.length - 1 ? Math.max(0, pool - assigned) : Math.floor(exact);
7388
7388
  out[i] = v;
7389
7389
  assigned += v;
7390
7390
  });
@@ -24745,9 +24745,9 @@ var source_default = chalk;
24745
24745
 
24746
24746
  // src/index.ts
24747
24747
  var import_readline = __toESM(require("readline"));
24748
- var import_node_child_process17 = require("child_process");
24749
- var import_node_fs42 = require("fs");
24750
- var import_node_path30 = require("path");
24748
+ var import_node_child_process18 = require("child_process");
24749
+ var import_node_fs43 = require("fs");
24750
+ var import_node_path31 = require("path");
24751
24751
  var import_node_os13 = require("os");
24752
24752
 
24753
24753
  // src/commands/monitor.ts
@@ -36680,12 +36680,12 @@ var import_node_path12 = require("path");
36680
36680
  var MAX_DEPS_PER_LOCKFILE = 50;
36681
36681
  async function scanDependencies(targetPath) {
36682
36682
  const findings = [];
36683
- for (const { file, ecosystem, parse: parse2 } of LOCKFILES) {
36683
+ for (const { file, ecosystem, parse: parse3 } of LOCKFILES) {
36684
36684
  const lockPath = (0, import_node_path12.join)(targetPath, file);
36685
36685
  if (!(0, import_node_fs14.existsSync)(lockPath)) continue;
36686
36686
  let deps;
36687
36687
  try {
36688
- deps = dedupe(parse2((0, import_node_fs14.readFileSync)(lockPath, "utf-8")));
36688
+ deps = dedupe(parse3((0, import_node_fs14.readFileSync)(lockPath, "utf-8")));
36689
36689
  } catch {
36690
36690
  continue;
36691
36691
  }
@@ -41674,7 +41674,8 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
41674
41674
  severity: r.severity,
41675
41675
  title: r.title.slice(0, MAX_TITLE_CHARS),
41676
41676
  recommendation: r.recommendation,
41677
- observed_at: observedAt.toISOString()
41677
+ observed_at: observedAt.toISOString(),
41678
+ ...r.details ? { details: trimMetadata(r.details) } : {}
41678
41679
  }));
41679
41680
  }
41680
41681
 
@@ -42354,12 +42355,12 @@ var DEFAULT_INTERVAL_MS = 6 * 36e5;
42354
42355
  var DEFAULT_MIN_AGE_MS = 2 * 36e5;
42355
42356
  var RETRY_AFTER_MS = 24 * 36e5;
42356
42357
  function isNewer(a, b) {
42357
- const parse2 = (v) => {
42358
+ const parse3 = (v) => {
42358
42359
  const [core, pre] = v.replace(/^v/, "").split("-", 2);
42359
42360
  return { nums: core.split(".").map((n) => Number.parseInt(n, 10) || 0), pre: pre ?? null };
42360
42361
  };
42361
- const x = parse2(a);
42362
- const y = parse2(b);
42362
+ const x = parse3(a);
42363
+ const y = parse3(b);
42363
42364
  for (let i = 0; i < 3; i++) {
42364
42365
  if ((x.nums[i] ?? 0) !== (y.nums[i] ?? 0)) return (x.nums[i] ?? 0) > (y.nums[i] ?? 0);
42365
42366
  }
@@ -44045,7 +44046,21 @@ async function runHardeningChecks() {
44045
44046
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
44046
44047
  );
44047
44048
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
44048
- return Array.isArray(parsed.findings) ? parsed.findings : [];
44049
+ const findings = Array.isArray(parsed.findings) ? parsed.findings : [];
44050
+ const patches = await runPatchCheck().catch((err) => {
44051
+ logLine(`[cloud] patch check failed: ${err.message.split("\n")[0]}`);
44052
+ return null;
44053
+ });
44054
+ return patches ? [...findings, patches] : findings;
44055
+ }
44056
+ async function runPatchCheck() {
44057
+ const { stdout } = await (0, import_node_util.promisify)(import_node_child_process12.execFile)(
44058
+ process.execPath,
44059
+ [(0, import_node_path26.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
44060
+ { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
44061
+ );
44062
+ const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
44063
+ return parsed.finding ?? null;
44049
44064
  }
44050
44065
  function logLine(line2) {
44051
44066
  try {
@@ -45793,6 +45808,412 @@ async function hardenCommand(opts) {
45793
45808
  if (opts.upload !== false) await uploadFindings(results, false);
45794
45809
  }
45795
45810
 
45811
+ // src/core/patches/index.ts
45812
+ var import_node_fs42 = require("fs");
45813
+ var import_node_path30 = require("path");
45814
+ var import_node_child_process16 = require("child_process");
45815
+ var import_node_util2 = require("util");
45816
+
45817
+ // src/core/patches/dpkg-version.ts
45818
+ function parse2(version) {
45819
+ let rest = version.trim();
45820
+ let epoch = 0;
45821
+ const colon = rest.indexOf(":");
45822
+ if (colon > 0 && /^\d+$/.test(rest.slice(0, colon))) {
45823
+ epoch = Number(rest.slice(0, colon));
45824
+ rest = rest.slice(colon + 1);
45825
+ }
45826
+ const dash = rest.lastIndexOf("-");
45827
+ return dash >= 0 ? { epoch, upstream: rest.slice(0, dash), revision: rest.slice(dash + 1) } : { epoch, upstream: rest, revision: "" };
45828
+ }
45829
+ function order(ch) {
45830
+ if (ch === void 0) return 0;
45831
+ if (ch === "~") return -1;
45832
+ if (/[A-Za-z]/.test(ch)) return ch.charCodeAt(0);
45833
+ return ch.charCodeAt(0) + 256;
45834
+ }
45835
+ function compareFragment(a, b) {
45836
+ let i = 0;
45837
+ let j = 0;
45838
+ while (i < a.length || j < b.length) {
45839
+ let firstDiff = 0;
45840
+ while (i < a.length && !/\d/.test(a[i]) || j < b.length && !/\d/.test(b[j])) {
45841
+ const ac = i < a.length && !/\d/.test(a[i]) ? a[i] : void 0;
45842
+ const bc = j < b.length && !/\d/.test(b[j]) ? b[j] : void 0;
45843
+ const diff = order(ac) - order(bc);
45844
+ if (diff !== 0) return diff;
45845
+ i++;
45846
+ j++;
45847
+ }
45848
+ while (a[i] === "0") i++;
45849
+ while (b[j] === "0") j++;
45850
+ while (i < a.length && /\d/.test(a[i]) && j < b.length && /\d/.test(b[j])) {
45851
+ if (!firstDiff) firstDiff = a.charCodeAt(i) - b.charCodeAt(j);
45852
+ i++;
45853
+ j++;
45854
+ }
45855
+ if (i < a.length && /\d/.test(a[i])) return 1;
45856
+ if (j < b.length && /\d/.test(b[j])) return -1;
45857
+ if (firstDiff) return firstDiff;
45858
+ }
45859
+ return 0;
45860
+ }
45861
+ function compareDebianVersions(a, b) {
45862
+ const x = parse2(a);
45863
+ const y = parse2(b);
45864
+ if (x.epoch !== y.epoch) return x.epoch - y.epoch;
45865
+ return compareFragment(x.upstream, y.upstream) || compareFragment(x.revision, y.revision);
45866
+ }
45867
+
45868
+ // src/core/patches/index.ts
45869
+ var OSV_QUERY = "https://api.osv.dev/v1/query";
45870
+ var STALE_AFTER_MS = 2 * 864e5;
45871
+ var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
45872
+ var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
45873
+ var defaultExec = async (file, args) => {
45874
+ const { stdout } = await (0, import_node_util2.promisify)(import_node_child_process16.execFile)(file, args, {
45875
+ timeout: 12e4,
45876
+ maxBuffer: 32 * 1024 * 1024,
45877
+ env: { ...process.env, LC_ALL: "C" }
45878
+ });
45879
+ return stdout;
45880
+ };
45881
+ function parseOsRelease(text) {
45882
+ const out = {};
45883
+ for (const line2 of text.split("\n")) {
45884
+ const m = /^([A-Z_]+)=(.*)$/.exec(line2.trim());
45885
+ if (m) out[m[1]] = m[2].replace(/^["']|["']$/g, "");
45886
+ }
45887
+ return out;
45888
+ }
45889
+ function osvEcosystem(os3) {
45890
+ if (os3.ID === "ubuntu" && os3.VERSION_ID) {
45891
+ return /LTS/.test(os3.VERSION ?? "") ? `Ubuntu:${os3.VERSION_ID}:LTS` : `Ubuntu:${os3.VERSION_ID}`;
45892
+ }
45893
+ if (os3.ID === "debian" && os3.VERSION_ID) return `Debian:${os3.VERSION_ID.split(".")[0]}`;
45894
+ return null;
45895
+ }
45896
+ function parseAptSimulation(text) {
45897
+ const out = [];
45898
+ for (const line2 of text.split("\n")) {
45899
+ const m = /^Inst (\S+) \[([^\]]+)\] \((\S+) ([^[)]*)/.exec(line2);
45900
+ if (!m) continue;
45901
+ const origins = m[4];
45902
+ out.push({
45903
+ name: m[1],
45904
+ installed: m[2],
45905
+ candidate: m[3],
45906
+ security: /-security\b|Debian-Security/i.test(origins)
45907
+ });
45908
+ }
45909
+ return out;
45910
+ }
45911
+ function parseSourceMap(text) {
45912
+ const out = /* @__PURE__ */ new Map();
45913
+ for (const line2 of text.split("\n")) {
45914
+ const [binary, source, version] = line2.trim().split("|");
45915
+ if (binary && source && version) out.set(binary.split(":")[0], { source, version });
45916
+ }
45917
+ return out;
45918
+ }
45919
+ function parseCandidateSources(text) {
45920
+ const out = /* @__PURE__ */ new Map();
45921
+ for (const stanza of text.split(/\n\s*\n/)) {
45922
+ const pkg = /^Package: (\S+)/m.exec(stanza)?.[1];
45923
+ const version = /^Version: (\S+)/m.exec(stanza)?.[1];
45924
+ if (!pkg || !version) continue;
45925
+ const src = /^Source: (\S+)(?: \(([^)]+)\))?/m.exec(stanza);
45926
+ out.set(`${pkg}=${version}`, { source: src?.[1] ?? pkg, version: src?.[2] ?? version });
45927
+ }
45928
+ return out;
45929
+ }
45930
+ function advisorySeverity(rec, ecosystem, source) {
45931
+ const label = (rec.severity?.find((s) => s.type === "Ubuntu")?.score ?? rec.database_specific?.severity ?? rec.affected?.find((a) => a.package?.ecosystem === ecosystem && a.package?.name === source)?.ecosystem_specific?.urgency ?? "").toLowerCase();
45932
+ if (label === "negligible" || label === "unimportant") return "info";
45933
+ if (label === "moderate") return "medium";
45934
+ if (SEVERITIES2.includes(label)) return label;
45935
+ return "medium";
45936
+ }
45937
+ function fixedByUpdate(rec, ecosystem, source, installed, candidate) {
45938
+ for (const a of rec.affected ?? []) {
45939
+ if (a.package?.ecosystem !== ecosystem || a.package?.name !== source) continue;
45940
+ for (const range of a.ranges ?? []) {
45941
+ for (const ev of range.events ?? []) {
45942
+ const fixed = ev.fixed;
45943
+ if (!fixed) continue;
45944
+ if (compareDebianVersions(installed, fixed) < 0 && compareDebianVersions(fixed, candidate) <= 0) return true;
45945
+ }
45946
+ }
45947
+ }
45948
+ return false;
45949
+ }
45950
+ function displayId(rec) {
45951
+ return rec.upstream?.find((u) => u.startsWith("CVE-")) ?? rec.aliases?.find((u) => u.startsWith("CVE-")) ?? rec.id;
45952
+ }
45953
+ async function osvRecords(doFetch, ecosystem, source, version) {
45954
+ const out = [];
45955
+ let pageToken;
45956
+ for (let page = 0; page < 20; page++) {
45957
+ const res = await doFetch(OSV_QUERY, {
45958
+ method: "POST",
45959
+ headers: { "Content-Type": "application/json" },
45960
+ body: JSON.stringify({ package: { name: source, ecosystem }, version, ...pageToken ? { page_token: pageToken } : {} })
45961
+ });
45962
+ if (!res.ok) throw new Error(`OSV query for ${source} failed: HTTP ${res.status}`);
45963
+ const body = await res.json();
45964
+ out.push(...body.vulns ?? []);
45965
+ pageToken = body.next_page_token;
45966
+ if (!pageToken) break;
45967
+ }
45968
+ return out;
45969
+ }
45970
+ function newestReleaseMtime(dir) {
45971
+ try {
45972
+ let newest = 0;
45973
+ for (const name of (0, import_node_fs42.readdirSync)(dir)) {
45974
+ if (!/Release$/.test(name)) continue;
45975
+ newest = Math.max(newest, (0, import_node_fs42.statSync)((0, import_node_path30.join)(dir, name)).mtimeMs);
45976
+ }
45977
+ return newest > 0 ? new Date(newest) : null;
45978
+ } catch {
45979
+ return null;
45980
+ }
45981
+ }
45982
+ function emptyCounts2() {
45983
+ return { info: 0, low: 0, medium: 0, high: 0, critical: 0, cves: 0, packages: 0 };
45984
+ }
45985
+ async function checkPatches(opts = {}) {
45986
+ const exec = opts.exec ?? defaultExec;
45987
+ const doFetch = opts.fetchImpl ?? globalThis.fetch;
45988
+ const now = opts.now ?? /* @__PURE__ */ new Date();
45989
+ let osText = opts.osRelease;
45990
+ if (osText === void 0) {
45991
+ try {
45992
+ osText = (0, import_node_fs42.readFileSync)("/etc/os-release", "utf-8");
45993
+ } catch {
45994
+ osText = "";
45995
+ }
45996
+ }
45997
+ const os3 = parseOsRelease(osText);
45998
+ const ecosystem = osvEcosystem(os3);
45999
+ const base = {
46000
+ supported: false,
46001
+ os: os3.PRETTY_NAME ?? os3.ID ?? "unknown",
46002
+ ecosystem,
46003
+ checked_at: now.toISOString(),
46004
+ lists_updated_at: null,
46005
+ lists_stale: false,
46006
+ upgradable: 0,
46007
+ packages: [],
46008
+ counts: emptyCounts2()
46009
+ };
46010
+ if (!ecosystem) {
46011
+ return { ...base, reason: `patch status supports Debian and Ubuntu; this is ${base.os}` };
46012
+ }
46013
+ let simulation;
46014
+ try {
46015
+ simulation = await exec("apt-get", ["-s", "-o", "Debug::NoLocking=1", "dist-upgrade"]);
46016
+ } catch (err) {
46017
+ return { ...base, reason: `apt-get simulation failed: ${err.message.split("\n")[0]}` };
46018
+ }
46019
+ const listsAt = newestReleaseMtime(opts.aptListsDir ?? "/var/lib/apt/lists");
46020
+ const report = {
46021
+ ...base,
46022
+ supported: true,
46023
+ lists_updated_at: listsAt?.toISOString() ?? null,
46024
+ lists_stale: !listsAt || now.getTime() - listsAt.getTime() > (opts.staleAfterMs ?? STALE_AFTER_MS)
46025
+ };
46026
+ const upgrades = parseAptSimulation(simulation);
46027
+ report.upgradable = upgrades.length;
46028
+ const security = upgrades.filter((u) => u.security);
46029
+ if (security.length === 0) return report;
46030
+ const installedSources = parseSourceMap(await exec("dpkg-query", [
46031
+ "-W",
46032
+ "-f=${Package}|${source:Package}|${source:Version}\n",
46033
+ ...security.map((u) => u.name)
46034
+ ]).catch(() => ""));
46035
+ const candidateSources = parseCandidateSources(await exec("apt-cache", [
46036
+ "show",
46037
+ "--no-all-versions",
46038
+ ...security.map((u) => `${u.name}=${u.candidate}`)
46039
+ ]).catch(() => ""));
46040
+ const bySource = /* @__PURE__ */ new Map();
46041
+ for (const u of security) {
46042
+ const inst = installedSources.get(u.name) ?? { source: u.name, version: u.installed };
46043
+ const cand = candidateSources.get(`${u.name}=${u.candidate}`) ?? { source: inst.source, version: u.candidate };
46044
+ const key = `${inst.source}|${inst.version}`;
46045
+ const entry = bySource.get(key);
46046
+ if (entry) {
46047
+ entry.binaries.push(u.name);
46048
+ if (compareDebianVersions(cand.version, entry.candidate) > 0) entry.candidate = cand.version;
46049
+ } else {
46050
+ bySource.set(key, {
46051
+ binaries: [u.name],
46052
+ source: inst.source,
46053
+ installed: inst.version,
46054
+ candidate: cand.version,
46055
+ severity: "medium",
46056
+ cves: []
46057
+ });
46058
+ }
46059
+ }
46060
+ for (const pkg of bySource.values()) {
46061
+ try {
46062
+ const seen = /* @__PURE__ */ new Set();
46063
+ for (const rec of await osvRecords(doFetch, ecosystem, pkg.source, pkg.installed)) {
46064
+ if (!fixedByUpdate(rec, ecosystem, pkg.source, pkg.installed, pkg.candidate)) continue;
46065
+ const id = displayId(rec);
46066
+ if (seen.has(id)) continue;
46067
+ seen.add(id);
46068
+ pkg.cves.push({ id, severity: advisorySeverity(rec, ecosystem, pkg.source) });
46069
+ }
46070
+ } catch (err) {
46071
+ report.osv_error ??= err.message;
46072
+ }
46073
+ pkg.cves.sort((a, b) => RANK[b.severity] - RANK[a.severity] || a.id.localeCompare(b.id));
46074
+ if (pkg.cves.length > 0) pkg.severity = pkg.cves[0].severity;
46075
+ pkg.binaries.sort();
46076
+ }
46077
+ report.packages = [...bySource.values()].sort(
46078
+ (a, b) => RANK[b.severity] - RANK[a.severity] || b.cves.length - a.cves.length || a.source.localeCompare(b.source)
46079
+ );
46080
+ const counts = emptyCounts2();
46081
+ counts.packages = report.packages.length;
46082
+ for (const pkg of report.packages) {
46083
+ counts.cves += pkg.cves.length;
46084
+ for (const cve of pkg.cves) counts[cve.severity]++;
46085
+ }
46086
+ report.counts = counts;
46087
+ return report;
46088
+ }
46089
+ function worstSeverity(report) {
46090
+ if (report.packages.length === 0) return null;
46091
+ return report.packages.reduce((w, p) => RANK[p.severity] > RANK[w] ? p.severity : w, "info");
46092
+ }
46093
+ var MAX_DETAIL_PACKAGES = 30;
46094
+ function patchFinding(report) {
46095
+ const details = {
46096
+ kind: "os-patches",
46097
+ supported: report.supported,
46098
+ os: report.os,
46099
+ ecosystem: report.ecosystem,
46100
+ checked_at: report.checked_at,
46101
+ lists_updated_at: report.lists_updated_at,
46102
+ lists_stale: report.lists_stale,
46103
+ upgradable: report.upgradable,
46104
+ counts: report.counts,
46105
+ packages: report.packages.slice(0, MAX_DETAIL_PACKAGES).map((p) => ({
46106
+ source: p.source,
46107
+ installed: p.installed,
46108
+ candidate: p.candidate,
46109
+ severity: p.severity,
46110
+ binaries: p.binaries.slice(0, 10),
46111
+ cve_count: p.cves.length,
46112
+ cves: p.cves.slice(0, 10).map((c2) => c2.id)
46113
+ })),
46114
+ ...report.packages.length > MAX_DETAIL_PACKAGES ? { packages_truncated: report.packages.length } : {},
46115
+ ...report.osv_error ? { osv_error: report.osv_error } : {}
46116
+ };
46117
+ if (!report.supported) {
46118
+ return {
46119
+ key: "os-patches",
46120
+ status: "warn",
46121
+ severity: "info",
46122
+ title: "OS patch status unavailable",
46123
+ explanation: report.reason ?? "Patch status could not be checked on this system.",
46124
+ details
46125
+ };
46126
+ }
46127
+ const worst = worstSeverity(report);
46128
+ const staleNote = report.lists_stale ? ` Package lists were last refreshed ${report.lists_updated_at ? report.lists_updated_at.slice(0, 10) : "never"}, so newer fixes may be missing.` : "";
46129
+ if (!worst) {
46130
+ return {
46131
+ key: "os-patches",
46132
+ status: report.lists_stale ? "warn" : "pass",
46133
+ severity: report.lists_stale ? "low" : "high",
46134
+ title: report.lists_stale ? "No pending security updates (package lists stale)" : "No pending security updates",
46135
+ explanation: `apt has no security updates waiting.${staleNote}`,
46136
+ recommendation: report.lists_stale ? "Run `sudo apt-get update` (or enable unattended-upgrades) so fixes are seen." : void 0,
46137
+ details
46138
+ };
46139
+ }
46140
+ const c = report.counts;
46141
+ const parts = [c.critical && `${c.critical} critical`, c.high && `${c.high} high`].filter(Boolean);
46142
+ const cveText = c.cves > 0 ? `${c.cves} CVE${c.cves === 1 ? "" : "s"}${parts.length ? ` (${parts.join(", ")})` : ""}` : "unnamed advisories";
46143
+ const top = report.packages.slice(0, 5).map((p) => `${p.source} ${p.installed} \u2192 ${p.candidate}`).join("; ");
46144
+ return {
46145
+ key: "os-patches",
46146
+ status: worst === "critical" || worst === "high" ? "fail" : "warn",
46147
+ severity: worst,
46148
+ title: `${c.packages} package${c.packages === 1 ? "" : "s"} with security fixes available: ${cveText}`,
46149
+ explanation: `Security updates are waiting for ${c.packages} source package${c.packages === 1 ? "" : "s"}: ${top}${report.packages.length > 5 ? "; \u2026" : ""}.${staleNote}`,
46150
+ recommendation: "Apply them: `sudo apt-get update && sudo apt-get upgrade`, then restart affected services (or reboot for a kernel or libc update).",
46151
+ details
46152
+ };
46153
+ }
46154
+
46155
+ // src/commands/patches.ts
46156
+ var SEVERITY_COLOR = {
46157
+ critical: source_default.red.bold,
46158
+ high: source_default.red,
46159
+ medium: source_default.yellow,
46160
+ low: source_default.cyan,
46161
+ info: source_default.gray
46162
+ };
46163
+ async function patchesCommand(opts) {
46164
+ if (!opts.json) {
46165
+ banner();
46166
+ logger.info("Checking OS packages for pending security updates...\n");
46167
+ }
46168
+ const spinner = opts.json ? null : ora({ text: "Asking apt and OSV...", color: "green" }).start();
46169
+ const report = await checkPatches();
46170
+ const finding = patchFinding(report);
46171
+ if (opts.json) {
46172
+ console.log(JSON.stringify({ report, finding }, null, 2));
46173
+ if (opts.upload !== false) await uploadFindings([finding], true);
46174
+ return;
46175
+ }
46176
+ if (!report.supported) {
46177
+ spinner?.warn(report.reason ?? "Patch status unavailable on this system\n");
46178
+ console.log();
46179
+ return;
46180
+ }
46181
+ spinner?.succeed("Patch check complete\n");
46182
+ console.log(` ${source_default.white.bold("System:")} ${report.os} ${source_default.gray(`(${report.ecosystem})`)}`);
46183
+ const listsAge = report.lists_updated_at ? report.lists_updated_at.replace("T", " ").slice(0, 16) + " UTC" : "unknown";
46184
+ console.log(` ${source_default.white.bold("Package lists:")} ${report.lists_stale ? source_default.yellow(`${listsAge} (stale; run sudo apt-get update)`) : listsAge}`);
46185
+ console.log(` ${source_default.white.bold("Upgradable:")} ${report.upgradable} package(s), ${report.counts.packages} with security fixes`);
46186
+ console.log(source_default.gray(" " + "\u2500".repeat(60)));
46187
+ console.log();
46188
+ if (report.packages.length === 0) {
46189
+ console.log(` ${source_default.green("\u2713")} No security updates waiting.
46190
+ `);
46191
+ } else {
46192
+ for (const p of report.packages) {
46193
+ const sev = SEVERITY_COLOR[p.severity](p.severity.toUpperCase().padEnd(8));
46194
+ console.log(` ${sev} ${source_default.white.bold(p.source)} ${source_default.gray(p.installed)} \u2192 ${source_default.green(p.candidate)}`);
46195
+ if (p.cves.length > 0) {
46196
+ const shown = p.cves.slice(0, 6).map((c2) => SEVERITY_COLOR[c2.severity](c2.id)).join(" ");
46197
+ console.log(` ${shown}${p.cves.length > 6 ? source_default.gray(` +${p.cves.length - 6} more`) : ""}`);
46198
+ } else {
46199
+ console.log(source_default.gray(" security update; no matching advisory in OSV"));
46200
+ }
46201
+ if (p.binaries.length > 1 || p.binaries[0] !== p.source) {
46202
+ console.log(source_default.gray(` packages: ${p.binaries.join(", ")}`));
46203
+ }
46204
+ }
46205
+ console.log();
46206
+ const c = report.counts;
46207
+ console.log(source_default.gray(" " + "\u2500".repeat(60)));
46208
+ console.log(` ${source_default.white.bold(`${c.cves} CVE(s) fixed by pending updates:`)} ${source_default.red(`${c.critical} critical`)} ${source_default.red(`${c.high} high`)} ${source_default.yellow(`${c.medium} medium`)} ${source_default.cyan(`${c.low} low`)}`);
46209
+ if (finding.recommendation) console.log(` ${source_default.yellow("Fix:")} ${finding.recommendation}`);
46210
+ console.log();
46211
+ }
46212
+ if (report.osv_error) console.log(source_default.yellow(` ! CVE lookup incomplete: ${report.osv_error}
46213
+ `));
46214
+ if (opts.upload !== false) await uploadFindings([finding], false);
46215
+ }
46216
+
45796
46217
  // src/commands/firewall.ts
45797
46218
  init_ipc_client();
45798
46219
  init_paths();
@@ -45937,11 +46358,11 @@ async function allowlistCommand(opts) {
45937
46358
  init_paths();
45938
46359
 
45939
46360
  // src/upgrade.ts
45940
- var import_node_child_process16 = require("child_process");
46361
+ var import_node_child_process17 = require("child_process");
45941
46362
  var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
45942
46363
  var defaultRunner = (cmd) => {
45943
46364
  try {
45944
- return (0, import_node_child_process16.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
46365
+ return (0, import_node_child_process17.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
45945
46366
  } catch {
45946
46367
  return null;
45947
46368
  }
@@ -46056,25 +46477,25 @@ ${source_default.dim(" C R U S H")}
46056
46477
  var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
46057
46478
  var PKG_NAME2 = "@profullstack/threatcrush";
46058
46479
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
46059
- var INSTALL_CONFIG_PATH = (0, import_node_path30.join)((0, import_node_os13.homedir)(), ".threatcrush", "install.json");
46480
+ var INSTALL_CONFIG_PATH = (0, import_node_path31.join)((0, import_node_os13.homedir)(), ".threatcrush", "install.json");
46060
46481
  function detectPackageManager() {
46061
46482
  try {
46062
- const npmGlobal = (0, import_node_child_process17.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
46483
+ const npmGlobal = (0, import_node_child_process18.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
46063
46484
  if (npmGlobal.includes(PKG_NAME2)) return "npm";
46064
46485
  } catch {
46065
46486
  }
46066
46487
  try {
46067
- (0, import_node_child_process17.execSync)("pnpm --version", { stdio: "pipe" });
46488
+ (0, import_node_child_process18.execSync)("pnpm --version", { stdio: "pipe" });
46068
46489
  return "pnpm";
46069
46490
  } catch {
46070
46491
  }
46071
46492
  try {
46072
- (0, import_node_child_process17.execSync)("yarn --version", { stdio: "pipe" });
46493
+ (0, import_node_child_process18.execSync)("yarn --version", { stdio: "pipe" });
46073
46494
  return "yarn";
46074
46495
  } catch {
46075
46496
  }
46076
46497
  try {
46077
- (0, import_node_child_process17.execSync)("bun --version", { stdio: "pipe" });
46498
+ (0, import_node_child_process18.execSync)("bun --version", { stdio: "pipe" });
46078
46499
  return "bun";
46079
46500
  } catch {
46080
46501
  }
@@ -46082,14 +46503,14 @@ function detectPackageManager() {
46082
46503
  }
46083
46504
  function readInstallConfig() {
46084
46505
  try {
46085
- return JSON.parse((0, import_node_fs42.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
46506
+ return JSON.parse((0, import_node_fs43.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
46086
46507
  } catch {
46087
46508
  return {};
46088
46509
  }
46089
46510
  }
46090
46511
  function packageLooksInstalled(pm, pkgName) {
46091
46512
  try {
46092
- const output = (0, import_node_child_process17.execSync)(globalListCommand(pm, pkgName), {
46513
+ const output = (0, import_node_child_process18.execSync)(globalListCommand(pm, pkgName), {
46093
46514
  encoding: "utf-8",
46094
46515
  stdio: ["pipe", "pipe", "pipe"]
46095
46516
  });
@@ -46192,14 +46613,14 @@ async function promoteUnprivilegedDaemon() {
46192
46613
  function restartSystemdDaemon() {
46193
46614
  const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
46194
46615
  const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
46195
- if (!asRoot && (0, import_node_child_process17.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
46616
+ if (!asRoot && (0, import_node_child_process18.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
46196
46617
  const [cmd, ...args] = argv;
46197
- if ((0, import_node_child_process17.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
46198
- return (0, import_node_child_process17.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
46618
+ if ((0, import_node_child_process18.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
46619
+ return (0, import_node_child_process18.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
46199
46620
  }
46200
46621
  function execQuiet(cmd) {
46201
46622
  try {
46202
- return (0, import_node_child_process17.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
46623
+ return (0, import_node_child_process18.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
46203
46624
  } catch {
46204
46625
  return null;
46205
46626
  }
@@ -46349,6 +46770,9 @@ program2.command("rules").description("Manage detection rules").argument("[actio
46349
46770
  program2.command("harden").description("Run hardening security scan").option("--json", "Output results as JSON").option("--no-upload", "Do not upload findings to the dashboard (uploaded when this machine is linked)").action(async (opts) => {
46350
46771
  await hardenCommand(opts);
46351
46772
  });
46773
+ program2.command("patches").description("List OS packages with a security update waiting, and the CVEs it fixes (Debian/Ubuntu)").option("--json", "Output the report as JSON").option("--no-upload", "Do not upload the result to the dashboard (uploaded when this machine is linked)").action(async (opts) => {
46774
+ await patchesCommand(opts);
46775
+ });
46352
46776
  program2.command("block").description("Block an IP address via the firewall").argument("<ip>", "IP address to block").option("--ttl <duration>", "Block duration (e.g. 1h, 30m, 1d)").action(async (ip, opts) => {
46353
46777
  await blockCommand(ip, opts);
46354
46778
  });
@@ -46385,7 +46809,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
46385
46809
  program2.command("logs").description("Tail daemon logs").action(async () => {
46386
46810
  console.log(LOGO2);
46387
46811
  const logPath = PATHS.logFile;
46388
- if (!(0, import_node_fs42.existsSync)(logPath)) {
46812
+ if (!(0, import_node_fs43.existsSync)(logPath)) {
46389
46813
  console.log(source_default.yellow(` No log file found at ${logPath}`));
46390
46814
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
46391
46815
  return;
@@ -46393,7 +46817,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
46393
46817
  console.log(source_default.green(` Tailing ${logPath}...
46394
46818
  `));
46395
46819
  console.log(source_default.gray(" Press Ctrl+C to stop\n"));
46396
- (0, import_node_child_process17.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
46820
+ (0, import_node_child_process18.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
46397
46821
  });
46398
46822
  program2.command("update").description("Update ThreatCrush CLI and installed bundle").option("--cli", "Update CLI only").option("--modules", "Update modules only").option("--desktop", "Update desktop app too").action(async (opts) => {
46399
46823
  console.log(LOGO2);
@@ -46405,7 +46829,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
46405
46829
  for (const cmd of commands2) {
46406
46830
  console.log(source_default.green(` \u2192 ${cmd}
46407
46831
  `));
46408
- (0, import_node_child_process17.execSync)(cmd, { stdio: "inherit" });
46832
+ (0, import_node_child_process18.execSync)(cmd, { stdio: "inherit" });
46409
46833
  }
46410
46834
  console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
46411
46835
  await reportIfStillStale();
@@ -46430,7 +46854,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
46430
46854
  for (const cmd of commands) {
46431
46855
  console.log(source_default.green(` \u2192 ${cmd}
46432
46856
  `));
46433
- (0, import_node_child_process17.execSync)(cmd, { stdio: "inherit" });
46857
+ (0, import_node_child_process18.execSync)(cmd, { stdio: "inherit" });
46434
46858
  }
46435
46859
  console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
46436
46860
  if (installMode === "desktop") {
@@ -46481,7 +46905,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
46481
46905
  for (const cmd of commands) {
46482
46906
  console.log(source_default.green(` \u2192 ${cmd}
46483
46907
  `));
46484
- (0, import_node_child_process17.execSync)(cmd, { stdio: "inherit" });
46908
+ (0, import_node_child_process18.execSync)(cmd, { stdio: "inherit" });
46485
46909
  }
46486
46910
  console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
46487
46911
  console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
@@ -46558,10 +46982,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
46558
46982
  });
46559
46983
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
46560
46984
  console.log(LOGO2);
46561
- const configPath = (0, import_node_path30.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
46985
+ const configPath = (0, import_node_path31.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
46562
46986
  let email = "";
46563
46987
  try {
46564
- const config = JSON.parse((0, import_node_fs42.readFileSync)(configPath, "utf-8"));
46988
+ const config = JSON.parse((0, import_node_fs43.readFileSync)(configPath, "utf-8"));
46565
46989
  email = config.email || "";
46566
46990
  } catch {
46567
46991
  }
@@ -46578,9 +47002,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
46578
47002
  return;
46579
47003
  }
46580
47004
  try {
46581
- const dir = (0, import_node_path30.join)((0, import_node_os13.homedir)(), ".threatcrush");
46582
- if (!(0, import_node_fs42.existsSync)(dir)) (0, import_node_fs42.mkdirSync)(dir, { recursive: true });
46583
- (0, import_node_fs42.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
47005
+ const dir = (0, import_node_path31.join)((0, import_node_os13.homedir)(), ".threatcrush");
47006
+ if (!(0, import_node_fs43.existsSync)(dir)) (0, import_node_fs43.mkdirSync)(dir, { recursive: true });
47007
+ (0, import_node_fs43.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
46584
47008
  console.log(source_default.dim(` Saved email to ${configPath}`));
46585
47009
  } catch {
46586
47010
  }