cve-lite-cli 1.36.1 → 1.38.0

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.
Files changed (57) hide show
  1. package/README.md +25 -3
  2. package/dist/advisory/local-db.js +22 -3
  3. package/dist/audit-log/events.js +14 -0
  4. package/dist/cli/args.js +125 -102
  5. package/dist/cli/flags.js +39 -0
  6. package/dist/cli/help.js +8 -3
  7. package/dist/cli/overrides.js +25 -19
  8. package/dist/cli/validate.js +34 -9
  9. package/dist/index.js +6 -1
  10. package/dist/output/compact-truncation.js +35 -0
  11. package/dist/output/cyclonedx.js +6 -3
  12. package/dist/output/formatters.js +10 -2
  13. package/dist/output/html-reporter.js +31 -15
  14. package/dist/output/multi-folder-html-reporter.js +26 -7
  15. package/dist/output/output-dir.js +20 -0
  16. package/dist/output/override-findings-html.js +24 -3
  17. package/dist/output/override-findings-json.js +5 -2
  18. package/dist/output/override-findings-sarif.js +1 -0
  19. package/dist/output/override-findings-terminal.js +21 -1
  20. package/dist/output/printers.js +52 -25
  21. package/dist/output/sarif.js +63 -6
  22. package/dist/output/sbom-file.js +6 -4
  23. package/dist/output/scan-json.js +74 -0
  24. package/dist/output/skipped-override-rules.js +41 -0
  25. package/dist/output/spdx.js +2 -2
  26. package/dist/output/write-outputs.js +22 -32
  27. package/dist/overrides/admitted-scan.js +12 -1
  28. package/dist/overrides/api.js +75 -21
  29. package/dist/overrides/context-builder.js +17 -2
  30. package/dist/overrides/detectors/index.js +2 -0
  31. package/dist/overrides/detectors/oa008-materialized.js +74 -14
  32. package/dist/overrides/detectors/oa009-stale-floor.js +12 -15
  33. package/dist/overrides/detectors/oa010-vulnerable-floor.js +5 -1
  34. package/dist/overrides/detectors/oa011-exceeds-range.js +128 -0
  35. package/dist/overrides/detectors/pd001-override-only-phantom.js +5 -4
  36. package/dist/overrides/detectors/pd002-transitive-only-phantom.js +5 -4
  37. package/dist/overrides/detectors/phantom-utils.js +29 -0
  38. package/dist/overrides/parsing/registry.js +79 -10
  39. package/dist/remediation/fix-commands.js +89 -31
  40. package/dist/remediation/npm-registry.js +9 -1
  41. package/dist/remediation/parent-update-child-note.js +11 -0
  42. package/dist/scan/multi-folder-scan.js +68 -53
  43. package/dist/scan/override-audit.js +49 -0
  44. package/dist/scan/single-scan.js +115 -44
  45. package/dist/scanner.js +35 -11
  46. package/dist/skills/content.js +4 -2
  47. package/dist/usage/scanner.js +219 -28
  48. package/dist/utils/contextual-signals.js +193 -0
  49. package/dist/utils/create-pr.js +21 -2
  50. package/dist/utils/finding.js +5 -0
  51. package/dist/utils/fix-runner.js +15 -2
  52. package/dist/utils/package-json.js +66 -14
  53. package/dist/utils/severity.js +22 -0
  54. package/dist/utils/update-check.js +2 -1
  55. package/dist/utils/version.js +81 -86
  56. package/package.json +3 -1
  57. package/scripts/pr-scan-delta.mjs +7 -4
@@ -0,0 +1,39 @@
1
+ export const FLAG_ALL = "--all";
2
+ export const FLAG_ALLOW_PRIVATE_OSV_URL = "--allow-private-osv-url";
3
+ export const FLAG_AUDIT_LOG = "--audit-log";
4
+ export const FLAG_BASE = "--base";
5
+ export const FLAG_BATCH_SIZE = "--batch-size";
6
+ export const FLAG_CA_CERT = "--ca-cert";
7
+ export const FLAG_CACHE_DIR = "--cache-dir";
8
+ export const FLAG_CDX = "--cdx";
9
+ export const FLAG_CHECK_LICENSES = "--check-licenses";
10
+ export const FLAG_CHECK_MAINTENANCE = "--check-maintenance";
11
+ export const FLAG_CHECK_NETWORK = "--check-network";
12
+ export const FLAG_CHECK_OVERRIDES = "--check-overrides";
13
+ export const FLAG_CREATE_PR = "--create-pr";
14
+ export const FLAG_DEBUG = "--debug";
15
+ export const FLAG_FAIL_ON = "--fail-on";
16
+ export const FLAG_FIX = "--fix";
17
+ export const FLAG_HELP = "--help";
18
+ export const FLAG_INCOMPLETE_POLICY = "--incomplete-policy";
19
+ export const FLAG_JSON = "--json";
20
+ export const FLAG_MIN_SEVERITY = "--min-severity";
21
+ export const FLAG_NO_CACHE = "--no-cache";
22
+ export const FLAG_NO_OPEN = "--no-open";
23
+ export const FLAG_OFFLINE = "--offline";
24
+ export const FLAG_OFFLINE_DB = "--offline-db";
25
+ export const FLAG_ONLY_USED = "--only-used";
26
+ export const FLAG_OSV_URL = "--osv-url";
27
+ export const FLAG_OUTPUT = "--output";
28
+ export const FLAG_PROD_ONLY = "--prod-only";
29
+ export const FLAG_RATCHET = "--ratchet";
30
+ export const FLAG_REPORT = "--report";
31
+ export const FLAG_RULE = "--rule";
32
+ export const FLAG_SARIF = "--sarif";
33
+ export const FLAG_SBOM = "--sbom";
34
+ export const FLAG_SBOM_INVENTORY_ONLY = "--sbom-inventory-only";
35
+ export const FLAG_SEARCH_DEPTH = "--search-depth";
36
+ export const FLAG_USAGE = "--usage";
37
+ export const FLAG_USAGE_HINTS = "--usage-hints";
38
+ export const FLAG_VERBOSE = "--verbose";
39
+ export const FLAG_VERSION = "--version";
package/dist/cli/help.js CHANGED
@@ -37,6 +37,7 @@ export function printHelp() {
37
37
  " --sbom <format> Write an SBOM: cyclonedx (1.6) or spdx (2.3), to a timestamped file",
38
38
  " --sbom-inventory-only Omit the vulnerability overlay from --sbom, leaving a pure inventory",
39
39
  " --cdx Alias for --sbom cyclonedx",
40
+ " --output <dir> Directory for --json, --sarif and --sbom files (default: current directory)",
40
41
  " --no-open Don't auto-open the report in the browser",
41
42
  " --fix Apply validated direct dependency fixes and rescan",
42
43
  " --ratchet Save current findings as baseline or, if baseline exists, only fail on new findings",
@@ -48,8 +49,11 @@ export function printHelp() {
48
49
  " --debug Write verbose runtime/network diagnostics to a timestamped log file",
49
50
  " --verbose Show detailed output with fix plan, paths, and full table",
50
51
  " --prod-only Exclude dev dependencies where available",
51
- " --check-overrides Also audit package.json overrides (OA001-OA010, PD001-PD002); findings",
52
+ " --check-overrides Also audit package.json overrides (OA001-OA011, PD001-PD002); findings",
52
53
  " print, thread to JSON/SARIF/HTML, and count toward --fail-on",
54
+ " --check-network Let the network-backed override rules run (OA007 registry drift,",
55
+ " OA010 vulnerable floor). Requires --check-overrides; without it",
56
+ " both rules are reported as skipped rather than passing silently",
53
57
  " --check-maintenance Also flag direct deps that block a transitive CVE fix via a major-version",
54
58
  " drag, or are marked deprecated on npm (DM001); counts toward --fail-on",
55
59
  " --check-licenses Also detect copyleft (LC001) and unknown (LC002) licenses; informational",
@@ -87,6 +91,7 @@ export function printHelp() {
87
91
  " cve-lite . --fail-on high Exit 1 if any high or critical findings are found",
88
92
  " cve-lite . --incomplete-policy error Exit 3 if detection data is incomplete",
89
93
  " cve-lite . --json Write findings to a timestamped JSON file",
94
+ " cve-lite . --sarif --output out Write the SARIF file into ./out",
90
95
  " cve-lite . --report Generate an interactive HTML report",
91
96
  " cve-lite . --fix Apply validated direct dependency fixes and rescan",
92
97
  " cve-lite . --offline Scan using the local advisory database (no network)",
@@ -100,12 +105,12 @@ export function printOverridesHelp() {
100
105
  const lines = [
101
106
  `${OVERRIDES_COMMAND} [path] [flags]`,
102
107
  "",
103
- "Audit package.json overrides and phantom dependency imports (OA001-OA010, PD001-PD002).",
108
+ "Audit package.json overrides and phantom dependency imports (OA001-OA011, PD001-PD002).",
104
109
  "",
105
110
  "Flags:",
106
111
  " --json Emit findings as JSON",
107
112
  " --fix Apply RFC 6902 patches for findings with auto-fix",
108
- " --rule <id> Only run a specific rule (OA001-OA010, PD001-PD002)",
113
+ " --rule <id> Only run a specific rule (OA001-OA011, PD001-PD002)",
109
114
  " --check-network Enable OA007 registry drift + OA010 admitted-range checks (opt-in network)",
110
115
  " --audit-log <path> Stream NDJSON change-control to <path>",
111
116
  " --fail-on <severity> Exit non-zero at or above this severity (default: critical)",
@@ -1,33 +1,34 @@
1
1
  import fs from "node:fs";
2
2
  import path, { resolve } from "node:path";
3
- import { buildOverrideContext, audit, applyFix } from "../overrides/index.js";
4
- import { createAdvisorySource } from "../scanner.js";
3
+ import { applyFix } from "../overrides/index.js";
4
+ import { runOverrideAudit } from "../scan/override-audit.js";
5
5
  import { createAuditLog } from "../audit-log/index.js";
6
6
  import { EXIT_OK, EXIT_FINDINGS, EXIT_ERROR } from "../types.js";
7
- import { renderOverrideFindings } from "../output/override-findings-terminal.js";
7
+ import { renderOverrideFindings, renderSkippedOverrideRules } from "../output/override-findings-terminal.js";
8
8
  import { reachesFailOn } from "../utils/severity.js";
9
9
  import { chalk } from "../utils/chalk.js";
10
- export async function runOverrides({ projectArg, options, logger, auditLog: injectedAuditLog }) {
10
+ export async function runOverrides({ projectArg, options, logger, auditLog: injectedAuditLog, fetchImpl, debugLog }) {
11
11
  const projectPath = resolve(projectArg ?? ".");
12
12
  const ownsAuditLog = !injectedAuditLog;
13
13
  const auditLog = injectedAuditLog ?? createAuditLog(options.auditLog ?? process.env.CVE_LITE_AUDIT_LOG);
14
- // OA010 needs an advisory source on top of the network opt-in. Built here
15
- // rather than inside audit() to keep the overrides module free of a scanner
16
- // import; closed in the finally so an offline database handle never leaks.
17
- const advisoryContext = options.checkNetwork === true ? createAdvisorySource() : null;
18
14
  try {
19
- const ctx = buildOverrideContext(projectPath, {
15
+ // Same helper the scan paths use, so all three entry points wire up identically.
16
+ const result = await runOverrideAudit({
17
+ projectPath,
18
+ checkNetwork: options.checkNetwork === true,
19
+ osvUrl: options.osvUrl,
20
20
  auditLog,
21
21
  logger,
22
- checkNetwork: options.checkNetwork === true,
23
- });
24
- const result = await audit(ctx, {
25
- checkNetwork: options.checkNetwork === true,
26
- advisorySource: advisoryContext?.advisorySource,
22
+ fetchImpl,
23
+ debugLog,
27
24
  });
28
25
  let findings = result.findings;
26
+ let skipped = result.skipped;
29
27
  if (options.rule) {
30
28
  findings = findings.filter((f) => f.ruleId === options.rule);
29
+ // Scope the skip notice the same way. On `--rule OA001` the user asked about one
30
+ // rule, so reporting that six others did not run is noise and reads as a failure.
31
+ skipped = skipped.filter((s) => s.ruleId === options.rule);
31
32
  }
32
33
  if (options.fix) {
33
34
  // Tier 1 only by default: "proposed" fixes write an inferred value (OA006
@@ -45,13 +46,13 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
45
46
  if (options.json) {
46
47
  const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
47
48
  const jsonFilename = `cve-lite-overrides-${ts}.json`;
48
- fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings: remaining, fixReport: report }, null, 2));
49
+ fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings: remaining, skippedOverrideRules: skipped, fixReport: report }, null, 2));
49
50
  console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
50
51
  }
51
52
  else {
52
53
  logger.info(`Applied ${report.appliedPatches.length} fix${report.appliedPatches.length === 1 ? "" : "es"}; skipped ${report.skipped.length}.`);
53
54
  if (remaining.length > 0) {
54
- process.stdout.write(renderOverrideFindings(remaining, { projectPath }) + "\n");
55
+ process.stdout.write(renderOverrideFindings(remaining, { projectPath, rulesSkipped: skipped.length > 0 }) + "\n");
55
56
  }
56
57
  }
57
58
  return reachesFailOn(remaining, options.failOn) ? EXIT_FINDINGS : EXIT_OK;
@@ -60,11 +61,16 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
60
61
  if (options.json) {
61
62
  const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
62
63
  const jsonFilename = `cve-lite-overrides-${ts}.json`;
63
- fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings }, null, 2));
64
+ fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings, skippedOverrideRules: skipped }, null, 2));
64
65
  console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
65
66
  }
66
67
  else {
67
- process.stdout.write(renderOverrideFindings(findings, { projectPath }) + "\n");
68
+ process.stdout.write(renderOverrideFindings(findings, { projectPath, rulesSkipped: skipped.length > 0 }) + "\n");
69
+ // This subcommand is the documented home of --check-network, so it is the surface
70
+ // where a silently skipped rule is most misleading (#1222).
71
+ if (skipped.length > 0) {
72
+ process.stdout.write(renderSkippedOverrideRules(skipped) + "\n");
73
+ }
68
74
  }
69
75
  return reachesFailOn(findings, options.failOn) ? EXIT_FINDINGS : EXIT_OK;
70
76
  }
@@ -73,7 +79,7 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
73
79
  return EXIT_ERROR;
74
80
  }
75
81
  finally {
76
- advisoryContext?.cleanup?.();
82
+ // The advisory source is opened and closed inside runOverrideAudit now.
77
83
  if (ownsAuditLog)
78
84
  auditLog.close();
79
85
  }
@@ -1,15 +1,24 @@
1
1
  import { validateCaCertFile } from "./config.js";
2
+ import { FLAG_CDX, FLAG_CHECK_NETWORK, FLAG_CHECK_OVERRIDES, FLAG_CREATE_PR, FLAG_FIX, FLAG_JSON, FLAG_NO_CACHE, FLAG_OFFLINE, FLAG_OFFLINE_DB, FLAG_OSV_URL, FLAG_REPORT, FLAG_SARIF, FLAG_SBOM, } from "./flags.js";
2
3
  import { validateOsvUrl } from "../utils/validate-url.js";
3
4
  import { resolveSbomFormat } from "../utils/sbom-format.js";
5
+ function conflictMessage(flag, withFlag) {
6
+ return `${flag} cannot be used with ${withFlag}.`;
7
+ }
8
+ /** Sibling of conflictMessage for the other shape of flag error, so the two kinds of
9
+ * message stay consistent as flags are added. */
10
+ function requiresMessage(flag, requiredFlag) {
11
+ return `${flag} requires ${requiredFlag}.`;
12
+ }
4
13
  export async function validateOptions(options) {
5
14
  if (options.allowPrivateOsvUrl && !options.osvUrl) {
6
- throw new Error("--allow-private-osv-url requires --osv-url. Provide a custom OSV endpoint with --osv-url, or remove --allow-private-osv-url.");
15
+ throw new Error(`${requiresMessage("--allow-private-osv-url", "--osv-url")} Provide a custom OSV endpoint with --osv-url, or remove --allow-private-osv-url.`);
7
16
  }
8
17
  if ((options.offline || options.offlineDb) && options.osvUrl) {
9
- throw new Error("--offline/--offline-db cannot be used with --osv-url. Choose offline mode (local DB) or online mode (custom OSV endpoint), not both.");
18
+ throw new Error(`${conflictMessage(`${FLAG_OFFLINE}/${FLAG_OFFLINE_DB}`, FLAG_OSV_URL)} Choose offline mode (local DB) or online mode (custom OSV endpoint), not both.`);
10
19
  }
11
20
  if (options.noCache && (options.offline || options.offlineDb)) {
12
- throw new Error("--no-cache cannot be used with --offline or --offline-db. Offline mode uses the local advisory DB directly; --no-cache only applies to online scans.");
21
+ throw new Error(`${conflictMessage(FLAG_NO_CACHE, `${FLAG_OFFLINE} or ${FLAG_OFFLINE_DB}`)} Offline mode uses the local advisory DB directly; --no-cache only applies to online scans.`);
13
22
  }
14
23
  let ssrfWarning;
15
24
  if (options.osvUrl) {
@@ -23,19 +32,19 @@ export async function validateOptions(options) {
23
32
  ssrfWarning = await validateOsvUrl(options.osvUrl, !!options.allowPrivateOsvUrl);
24
33
  }
25
34
  if (options.createPr && options.json) {
26
- throw new Error("--create-pr cannot be used with --json. Use --create-pr to open a pull request for applied fixes, or --json to save scan results as JSON, not both.");
35
+ throw new Error(`${conflictMessage(FLAG_CREATE_PR, FLAG_JSON)} Use --create-pr to open a pull request for applied fixes, or --json to save scan results as JSON, not both.`);
27
36
  }
28
37
  if (options.fix && options.json) {
29
- throw new Error("--fix cannot be used with --json. Use --fix to apply validated fixes and rescan, or --json to save scan results as JSON, not both.");
38
+ throw new Error(`${conflictMessage(FLAG_FIX, FLAG_JSON)} Use --fix to apply validated fixes and rescan, or --json to save scan results as JSON, not both.`);
30
39
  }
31
40
  if (options.fix && options.sarif) {
32
- throw new Error("--fix cannot be used with --sarif. Use --fix to apply validated fixes and rescan, or --sarif to save scan results as SARIF, not both.");
41
+ throw new Error(`${conflictMessage(FLAG_FIX, FLAG_SARIF)} Use --fix to apply validated fixes and rescan, or --sarif to save scan results as SARIF, not both.`);
33
42
  }
34
43
  if (options.fix && resolveSbomFormat(options)) {
35
44
  // Name the flag the user actually typed: --cdx is an alias for --sbom cyclonedx.
36
- const flag = options.cdx ? "--cdx" : "--sbom";
45
+ const flag = options.cdx ? FLAG_CDX : FLAG_SBOM;
37
46
  const what = options.cdx ? "a CycloneDX SBOM" : "an SBOM";
38
- throw new Error(`--fix cannot be used with ${flag}. Use --fix to apply validated fixes and rescan, or ${flag} to save ${what}, not both.`);
47
+ throw new Error(`${conflictMessage(FLAG_FIX, flag)} Use --fix to apply validated fixes and rescan, or ${flag} to save ${what}, not both.`);
39
48
  }
40
49
  if (options.createPr && !options.fix) {
41
50
  throw new Error("--create-pr requires --fix. Add --fix to apply validated fixes before opening a pull request, or remove --create-pr.");
@@ -44,7 +53,23 @@ export async function validateOptions(options) {
44
53
  throw new Error("--base can only be used with --create-pr. Add --create-pr to select its target branch, or remove --base.");
45
54
  }
46
55
  if (options.report && options.json) {
47
- throw new Error("--report cannot be used with --json. Use --report to generate an HTML report, or --json to save scan results as JSON, not both.");
56
+ throw new Error(`${conflictMessage(FLAG_REPORT, FLAG_JSON)} Use --report to generate an HTML report, or --json to save scan results as JSON, not both.`);
57
+ }
58
+ if (options.output && !(options.json || options.sarif || resolveSbomFormat(options))) {
59
+ throw new Error("--output requires --json, --sarif or --sbom. Add one of them to write a file into the output directory, or remove --output.");
60
+ }
61
+ if (options.checkNetwork && !options.checkOverrides) {
62
+ throw new Error(`${requiresMessage(FLAG_CHECK_NETWORK, FLAG_CHECK_OVERRIDES)} It lets the network-backed override rules run, so add ${FLAG_CHECK_OVERRIDES}, or remove ${FLAG_CHECK_NETWORK}.`);
63
+ }
64
+ // Rejected rather than silently partly honoured, and deliberately covering BOTH offline
65
+ // flags. The network-backed rules reach the npm registry for dist-tags and published
66
+ // version lists, which no local advisory database can supply, so the combination would
67
+ // print "no external advisory calls will be made" and then call the registry anyway.
68
+ // Everywhere else in the codebase offline means --offline OR --offline-db (the advisory
69
+ // source factory and the banner both), so guarding only one would leave two different
70
+ // definitions of offline depending on which check you happen to be reading.
71
+ if ((options.offline || options.offlineDb) && options.checkNetwork) {
72
+ throw new Error(`${conflictMessage(`${FLAG_OFFLINE}/${FLAG_OFFLINE_DB}`, FLAG_CHECK_NETWORK)} The network-backed override rules query the npm registry for dist-tags and published version lists, which a local advisory database cannot supply. Drop ${FLAG_CHECK_NETWORK} to audit offline, or drop the offline flag to run them.`);
48
73
  }
49
74
  if (options.caCert) {
50
75
  try {
package/dist/index.js CHANGED
@@ -110,14 +110,19 @@ if (parsedArgs) {
110
110
  options,
111
111
  logger,
112
112
  auditLog: auditLogHandle,
113
+ // Same cert-aware fetch and debug sink the scan path uses, so a CA certificate
114
+ // and --debug behave identically on both.
115
+ fetchImpl: certFetch,
116
+ debugLog,
113
117
  });
114
118
  auditLogHandle.close();
115
119
  process.exit(exitCode);
116
120
  return;
117
121
  }
118
122
  const validationWarning = await validateOptions(options);
119
- if (validationWarning)
123
+ if (validationWarning) {
120
124
  logWarn(validationWarning, options);
125
+ }
121
126
  // Multi-folder mode: if no root lockfile and 2+ nested lockfiles exist,
122
127
  // route to dedicated multi-folder handler instead of single-lockfile scan
123
128
  const nestedLockfiles = findNestedLockfiles(projectPath, searchDepth);
@@ -0,0 +1,35 @@
1
+ import { pluralize } from "../utils/string.js";
2
+ /** Compact finding-block cap. Selection still lives in `selectFindingsForCompact`. */
3
+ export const COMPACT_FINDING_BLOCK_LIMIT = 3;
4
+ /** Compact suggested-fix section cap. Hidden sections keep their original order. */
5
+ export const COMPACT_COMMAND_GROUP_LIMIT = 3;
6
+ /**
7
+ * Disclosure line printed after the last compact finding block when more
8
+ * findings exist than were shown. Returns null when nothing was withheld, so
9
+ * compact output stays quiet when it already shows everything.
10
+ */
11
+ export function formatCompactFindingTruncationNotice(shownCount, totalCount) {
12
+ if (shownCount >= totalCount)
13
+ return null;
14
+ return `Showing ${shownCount} of ${totalCount} findings. Run --verbose --all to see them all.`;
15
+ }
16
+ /**
17
+ * Disclosure line printed after the last compact suggested-fix section when
18
+ * sections were omitted. Count and severities are derived from the hidden
19
+ * sections themselves so the message stays honest when the mix differs.
20
+ */
21
+ export function formatCompactCommandGroupTruncationNotice(hiddenSections) {
22
+ if (hiddenSections.length === 0)
23
+ return null;
24
+ const count = hiddenSections.length;
25
+ const severities = [];
26
+ const seen = new Set();
27
+ for (const section of hiddenSections) {
28
+ if (seen.has(section.severity))
29
+ continue;
30
+ seen.add(section.severity);
31
+ severities.push(section.severity);
32
+ }
33
+ const severityPart = severities.length > 0 ? ` (${severities.join(", ")})` : "";
34
+ return `${count} more ${pluralize(count, "command group")}${severityPart}. Run --verbose to see them.`;
35
+ }
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
2
+ import { findFixTargetForFinding, findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
3
3
  import { getRecommendedAction } from "./formatters.js";
4
4
  import { getCliVersion } from "../utils/version-info.js";
5
5
  import { buildPurl } from "../utils/purl.js";
@@ -49,6 +49,9 @@ export function buildCycloneDxBom(allPackages, findings, projectMeta, version, p
49
49
  addProperty("fix-version-published-at", finding.fixVersionPublishedAt);
50
50
  addProperty("versions-scanned", finding.validatedTargetScannedVersions);
51
51
  addProperty("versions-still-vulnerable", finding.validatedTargetKnownVulnerableVersions);
52
+ const planTarget = plan ? findFixTargetForFinding(plan, finding) : null;
53
+ addProperty("child-package", planTarget?.childPackage);
54
+ addProperty("child-target-version", planTarget?.childTargetVersion);
52
55
  vulnerabilities.push({
53
56
  id: cveId,
54
57
  source: {
@@ -94,8 +97,8 @@ export function buildCycloneDxBom(allPackages, findings, projectMeta, version, p
94
97
  vulnerabilities,
95
98
  };
96
99
  }
97
- export function writeCycloneDxReport(allPackages, findings, plan, projectMeta) {
100
+ export function writeCycloneDxReport(allPackages, findings, plan, projectMeta, outputDir) {
98
101
  const filename = `cve-lite-scan-${sbomTimestamp()}.cdx.json`;
99
102
  const bom = buildCycloneDxBom(allPackages, findings, projectMeta, getCliVersion(), plan);
100
- return writeSbomFile(filename, bom, "CycloneDX report");
103
+ return writeSbomFile(filename, bom, "CycloneDX report", outputDir);
101
104
  }
@@ -3,11 +3,12 @@ import { chalk } from "../utils/chalk.js";
3
3
  import { severityOrder, MAL_PRIVATE_REGISTRY_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, } from "../constants.js";
4
4
  import { loadCache } from "../osv/cache.js";
5
5
  import { inferSeverity } from "../osv/severity.js";
6
- import { getPrimaryParent, getRootDependencies } from "../utils/finding.js";
6
+ import { getPrimaryParent, getRootDependencies, isUnconfirmedFix } from "../utils/finding.js";
7
7
  import { calculatePathCoverage, formatDependencyPath } from "../utils/path-coverage.js";
8
8
  import { pluralize } from "../utils/string.js";
9
9
  import { hasMaliciousAdvisory } from "../utils/vuln.js";
10
10
  import { computePrioritySignal } from "../utils/priority-signal.js";
11
+ import { computeContextualSignals } from "../utils/contextual-signals.js";
11
12
  export function formatRelationshipLabel(value) {
12
13
  if (value.startsWith("direct"))
13
14
  return chalk.green(value);
@@ -68,6 +69,9 @@ export function getRecommendedAction(finding) {
68
69
  // may itself be vulnerable), and the validated target is what the fix
69
70
  // command actually uses.
70
71
  const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
72
+ if (isUnconfirmedFix(finding)) {
73
+ return `Verify a safe version of ${finding.pkg.name} before upgrading.`;
74
+ }
71
75
  if (finding.relationship === "direct" && directTarget) {
72
76
  return `Upgrade ${finding.pkg.name} to ${directTarget}+ in this project.`;
73
77
  }
@@ -143,7 +147,7 @@ export function summarizeRisk(finding) {
143
147
  else {
144
148
  risk = "Review this finding and inspect the dependency path for the safest upgrade path.";
145
149
  }
146
- if (finding.usage && !finding.usage.imported) {
150
+ if (finding.usage && finding.usage.imported === false) {
147
151
  if (finding.relationship === "transitive") {
148
152
  risk = risk.replace("Transitive issue.", "Transitive issue. No direct imports found in source code, so practical reachability may be low.");
149
153
  }
@@ -176,6 +180,9 @@ export function summarizeNextAction(finding) {
176
180
  ? "This package has a malicious code advisory. Remove it from your dependencies."
177
181
  : "This package has a malicious code advisory. Upgrade or remove the parent package that pulls it in.";
178
182
  }
183
+ if (isUnconfirmedFix(finding)) {
184
+ return `Verify a safe version of ${finding.pkg.name} before upgrading.`;
185
+ }
179
186
  if (finding.relationship === "direct" && directTarget) {
180
187
  return `Upgrade ${finding.pkg.name} toward ${directTarget}.`;
181
188
  }
@@ -244,6 +251,7 @@ export function serializeFinding(finding, plan) {
244
251
  cves: finding.cveAliases,
245
252
  epssScores: finding.epssScores ?? null,
246
253
  prioritySignal: computePrioritySignal(finding.severity, finding.epssScores) ?? null,
254
+ contextualSignals: computeContextualSignals(finding),
247
255
  dependencyPaths: finding.dependencyPaths,
248
256
  usage: finding.usage ?? null,
249
257
  maliciousUnverifiable: finding.maliciousUnverifiable ?? false,
@@ -12,7 +12,9 @@ import { renderMaintenanceFindingsHtml } from "./maintenance-findings-html.js";
12
12
  import { renderLicenseFindingsHtml } from "./license-findings-html.js";
13
13
  import { PRIORITY_SIGNAL_LABELS, PRIORITY_SIGNAL_DESCRIPTIONS, PRIORITY_SIGNAL_LEGEND_DESCRIPTIONS } from "../utils/priority-signal.js";
14
14
  import { UNVERIFIED_PARENT_UPGRADE_NOTE } from "../remediation/fix-commands.js";
15
+ import { formatParentUpdateChildNote } from "../remediation/parent-update-child-note.js";
15
16
  import { getCompletenessImpact } from "../scan/completeness.js";
17
+ import { isUnconfirmedFix } from "../utils/finding.js";
16
18
  export function serializeHtmlFinding(finding, plan) {
17
19
  return {
18
20
  ...serializeFinding(finding, plan),
@@ -34,6 +36,7 @@ export function buildReportData(params) {
34
36
  warnings: params.warnings,
35
37
  skippedDependencies: params.skippedDependencies,
36
38
  overrideFindings: params.overrideFindings,
39
+ skippedOverrideRules: params.skippedOverrideRules,
37
40
  maintenanceFindings: params.maintenanceFindings,
38
41
  licenseFindings: params.licenseFindings,
39
42
  licenseLimitedToDirectOnly: params.licenseLimitedToDirectOnly,
@@ -205,6 +208,11 @@ button.header-link:hover{color:var(--link);border-color:var(--link)}
205
208
  .override-hygiene table tbody tr:last-child{border-bottom:none}
206
209
  .override-hygiene table tbody tr:hover{background:var(--surface)}
207
210
  .override-hygiene table tbody td{padding:11px 14px;font-size:13px;color:var(--text);vertical-align:middle}
211
+ .override-skipped{margin-top:14px;background:#e3b34111;border:1px solid #e3b34144;border-radius:8px;padding:12px 16px}
212
+ .override-skipped p{font-size:12px;color:var(--text);margin:0}
213
+ .override-skipped ul{margin:6px 0 0;padding:0 0 0 18px;display:flex;flex-direction:column;gap:3px}
214
+ .override-skipped li{font-size:11px;color:var(--text-2);line-height:1.5}
215
+ .override-skipped code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;color:var(--text)}
208
216
  .maintenance-risk{margin:0 32px 32px}
209
217
  .maintenance-risk h2{font-size:13px;font-weight:600;color:var(--text);margin-bottom:12px}
210
218
  .maintenance-risk p{font-size:13px;color:var(--text-2)}
@@ -227,7 +235,15 @@ button.header-link:hover{color:var(--link);border-color:var(--link)}
227
235
  .priority-legend-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:10px}
228
236
  .priority-legend-item{display:flex;align-items:flex-start;gap:10px;font-size:12px;color:var(--text-2);line-height:1.5}
229
237
  .sev-dev-note{text-align:center;font-size:12px;color:var(--text-2);margin:-12px 0 16px;padding:0 32px}`;
230
- export function renderHtmlReport(data) {
238
+ function embedJson(value) {
239
+ return JSON.stringify(value)
240
+ .replace(/</g, "\\u003c")
241
+ .replace(/>/g, "\\u003e")
242
+ .replace(/&/g, "\\u0026")
243
+ .replace(/\u2028/g, "\\u2028")
244
+ .replace(/\u2029/g, "\\u2029");
245
+ }
246
+ export function renderHtmlReport(data, jsonPayload) {
231
247
  const projectName = path.basename(data.projectPath);
232
248
  const scanDate = new Date(data.scannedAt).toLocaleString();
233
249
  const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
@@ -249,12 +265,7 @@ export function renderHtmlReport(data) {
249
265
  const skippedDepsHtml = renderSkippedDependenciesSection(data.skippedDependencies);
250
266
  const duplicatePackagesHtml = renderDuplicatePackagesSection(data.findings);
251
267
  const findingRowsHtml = data.findings.map((f, i) => renderFindingRow(f, i, skippedKeys)).join("\n");
252
- const dataJson = JSON.stringify(data)
253
- .replace(/</g, "\\u003c")
254
- .replace(/>/g, "\\u003e")
255
- .replace(/&/g, "\\u0026")
256
- .replace(/\u2028/g, "\\u2028")
257
- .replace(/\u2029/g, "\\u2029");
268
+ const dataJson = embedJson(jsonPayload ?? data);
258
269
  return `<!DOCTYPE html>
259
270
  <html lang="en">
260
271
  <head>
@@ -360,7 +371,7 @@ ${findingRowsHtml}
360
371
  </table>
361
372
  ${renderPriorityLegendHtml(data.findings)}
362
373
  </div>
363
- ${renderOverrideFindingsHtml(data.overrideFindings, data.projectPath)}
374
+ ${renderOverrideFindingsHtml(data.overrideFindings, data.projectPath, data.skippedOverrideRules)}
364
375
  ${renderMaintenanceFindingsHtml(data.maintenanceFindings)}
365
376
  ${renderLicenseFindingsHtml(data.licenseFindings, { limitedToDirectOnly: data.licenseLimitedToDirectOnly })}
366
377
  ${skippedDepsHtml}
@@ -604,9 +615,10 @@ export function renderFindingRow(finding, idx, skippedKeys) {
604
615
  : finding.vulnerabilities.map(v => advisoryLink(v.id)).join(", ");
605
616
  const isMalicious = hasMaliciousAdvisory(finding.vulnerabilities);
606
617
  const isSkipped = skippedKeys?.has(`${finding.package}@${finding.version}`);
618
+ const unconfirmed = isUnconfirmedFix(finding);
607
619
  const fixVersion = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
608
- const fixHtml = isSkipped && fixVersion
609
- ? `<span class="fix-hint hint-only" title="Advisory hint only — no automated fix command was generated. See the Skipped findings section below for details.">${escapeHtml(fixVersion)} ⊘</span>`
620
+ const fixHtml = (isSkipped || unconfirmed) && fixVersion
621
+ ? `<span class="fix-hint hint-only" title="Advisory hint only — a safe fix has not been confirmed.">${escapeHtml(fixVersion)} ⊘</span>`
610
622
  : fixVersion
611
623
  ? `<span class="fix-hint">${escapeHtml(fixVersion)}</span>`
612
624
  : isMalicious && finding.maliciousUnverifiable
@@ -681,6 +693,7 @@ export function renderFindingRow(finding, idx, skippedKeys) {
681
693
  <div class="detail-col">
682
694
  <h4>Recommended action</h4>
683
695
  ${recommendedActionHtml}
696
+ ${finding.fixVersionValidationNote ? `<p class="fix-cmd-note">${escapeHtml(finding.fixVersionValidationNote)}</p>` : ""}
684
697
  <h4 class="detail-subheading">Risk summary</h4>
685
698
  <p>${escapeHtml(finding.riskSummary)}</p>
686
699
  <h4 class="detail-subheading">Next action</h4>
@@ -870,9 +883,12 @@ export function renderFixPlan(plan) {
870
883
  const displayVersion = t.targetVersion;
871
884
  const isMajor = t.currentVersion ? isBreakingUpgrade(t.currentVersion, t.targetVersion) : false;
872
885
  const breakBadge = isMajor ? ` <span class="break-badge">⚠ breaking</span>` : "";
873
- const versionHtml = t.currentVersion
874
- ? `<span class="fix-target-pkg">${escapeHtml(t.package)}@${escapeHtml(t.currentVersion)}</span><span class="fix-target-arrow">→</span><span class="fix-target-to">${escapeHtml(displayVersion)}</span>`
875
- : `<span class="fix-target-pkg">${escapeHtml(t.package)}</span><span class="fix-target-arrow">→</span><span class="fix-target-to">${escapeHtml(displayVersion)}</span>`;
886
+ const childNote = formatParentUpdateChildNote(t);
887
+ const versionHtml = childNote
888
+ ? `<span class="fix-target-pkg">${escapeHtml(t.package)}${t.currentVersion ? `@${escapeHtml(t.currentVersion)}` : ""}</span><span class="fix-target-note">${escapeHtml(childNote)}</span>`
889
+ : t.currentVersion
890
+ ? `<span class="fix-target-pkg">${escapeHtml(t.package)}@${escapeHtml(t.currentVersion)}</span><span class="fix-target-arrow">→</span><span class="fix-target-to">${escapeHtml(displayVersion)}</span>`
891
+ : `<span class="fix-target-pkg">${escapeHtml(t.package)}</span><span class="fix-target-arrow">→</span><span class="fix-target-to">${escapeHtml(displayVersion)}</span>`;
876
892
  const statsHtml = t.scannedVersions != null
877
893
  ? ` <span class="fix-target-stats">${t.scannedVersions} scanned${t.knownVulnerableVersions != null ? ` · ${t.knownVulnerableVersions} still vulnerable` : ""}</span>`
878
894
  : "";
@@ -927,8 +943,8 @@ export async function writeHtmlReport(params) {
927
943
  const indexPath = path.join(params.outputDir, "index.html");
928
944
  const jsonPath = path.join(params.outputDir, "report.json");
929
945
  try {
930
- fs.writeFileSync(jsonPath, JSON.stringify(params.data, null, 2), "utf8");
931
- fs.writeFileSync(indexPath, renderHtmlReport(params.data), "utf8");
946
+ fs.writeFileSync(jsonPath, JSON.stringify(params.jsonPayload, null, 2), "utf8");
947
+ fs.writeFileSync(indexPath, renderHtmlReport(params.data, params.jsonPayload), "utf8");
932
948
  }
933
949
  catch (err) {
934
950
  if (!dirExisted) {
@@ -6,6 +6,7 @@ import { renderOverrideFindingsHtml } from "./override-findings-html.js";
6
6
  import { renderMaintenanceFindingsHtml } from "./maintenance-findings-html.js";
7
7
  import { renderLicenseFindingsHtml } from "./license-findings-html.js";
8
8
  import { loadLogoDataUri } from "./logos.js";
9
+ import { buildMultiFolderScanJson } from "./scan-json.js";
9
10
  import { pluralize } from "../utils/string.js";
10
11
  export function buildMultiFolderReportData(params) {
11
12
  const findings = params.results.flatMap((r, i) => params.serializedByFolder[i].map(f => ({
@@ -42,12 +43,16 @@ function summaryCounts(results) {
42
43
  }
43
44
  return counts;
44
45
  }
45
- function renderFolderNotices(coverage) {
46
- if (coverage.length === 0)
46
+ function renderFolderNotices(coverage, warnings) {
47
+ if (coverage.length === 0 && warnings.length === 0)
47
48
  return "";
48
- const items = coverage.map(n => `<li>${escapeHtml(n)}</li>`).join("\n");
49
+ const total = coverage.length + warnings.length;
50
+ const items = [
51
+ ...coverage.map(n => `<li>${escapeHtml(n)}</li>`),
52
+ ...warnings.map(w => `<li class="warning">${escapeHtml(w)}</li>`),
53
+ ].join("\n");
49
54
  return `<div class="scan-notes" style="margin:16px 32px">
50
- <button class="scan-notes-toggle" onclick="toggleNotes(this)"><span class="arrow">▶</span> Scan notes (${coverage.length})</button>
55
+ <button class="scan-notes-toggle" onclick="toggleNotes(this)"><span class="arrow">▶</span> Scan notes (${total})</button>
51
56
  <div class="scan-notes-body"><ul>${items}</ul></div>
52
57
  </div>`;
53
58
  }
@@ -67,10 +72,10 @@ function renderFolderSection(result, folderIdx, idxOffset, serialized, projectRo
67
72
  const fi = folderIdx;
68
73
  const findingRowsHtml = serialized.map((f, i) => renderFindingRow(f, idxOffset + i)).join("\n");
69
74
  const fixPlanHtml = renderFixPlan(result.suggestedFixCommands);
70
- const noticesHtml = renderFolderNotices(result.coverage);
75
+ const noticesHtml = renderFolderNotices(result.coverage, result.scanInput.warnings);
71
76
  const folderAbs = path.join(projectRoot, result.subfolder);
72
77
  const overrideHtml = includeOverrides
73
- ? renderOverrideFindingsHtml(result.overrideFindings, folderAbs)
78
+ ? renderOverrideFindingsHtml(result.overrideFindings, folderAbs, result.overrideSkipped)
74
79
  : "";
75
80
  const maintenanceHtml = includeMaintenance
76
81
  ? renderMaintenanceFindingsHtml(result.maintenanceFindings)
@@ -382,9 +387,23 @@ document.addEventListener('click', function(e) {
382
387
  </script>
383
388
  </body>
384
389
  </html>`;
390
+ // Same --json multi-folder shape, plus cliVersion for saved-artifact provenance
391
+ // (scannedAt is already on the multi-folder payload) and per-finding
392
+ // riskSummary/nextAction from serializeHtmlFinding.
393
+ const jsonPayload = {
394
+ ...buildMultiFolderScanJson({
395
+ results: params.results,
396
+ projectPath: params.projectPath,
397
+ includeOverrides: params.includeOverrides,
398
+ includeMaintenance: params.includeMaintenance,
399
+ includeLicenses: params.includeLicenses,
400
+ }),
401
+ cliVersion: params.cliVersion,
402
+ findings: reportData.findings,
403
+ };
385
404
  const indexPath = path.join(params.outputDir, "index.html");
386
405
  const jsonPath = path.join(params.outputDir, "report.json");
387
- fs.writeFileSync(jsonPath, JSON.stringify(reportData, null, 2), "utf8");
406
+ fs.writeFileSync(jsonPath, JSON.stringify(jsonPayload, null, 2), "utf8");
388
407
  fs.writeFileSync(indexPath, html, "utf8");
389
408
  if (params.autoOpen)
390
409
  openInBrowser(indexPath);
@@ -0,0 +1,20 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ /** Directory for --json, --sarif and --sbom files: the working directory, or --output resolved against it and created when missing. */
4
+ export function resolveOutputDir(output) {
5
+ if (!output)
6
+ return process.cwd();
7
+ const dir = path.resolve(process.cwd(), output);
8
+ try {
9
+ fs.mkdirSync(dir, { recursive: true });
10
+ }
11
+ catch (err) {
12
+ throw new Error(`Failed to create output directory ${dir}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
13
+ }
14
+ return dir;
15
+ }
16
+ /** Path printed for a written file: relative to the working directory, or absolute when it lies outside it. */
17
+ export function displayOutputPath(outputPath) {
18
+ const relative = path.relative(process.cwd(), outputPath);
19
+ return relative.startsWith("..") ? outputPath : relative;
20
+ }