cve-lite-cli 1.34.0 → 1.35.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 (37) hide show
  1. package/dist/cli/advisories-init.js +13 -0
  2. package/dist/cli/advisories-sync.js +30 -0
  3. package/dist/cli/config-command.js +15 -0
  4. package/dist/cli/config.js +29 -0
  5. package/dist/cli/help.js +4 -4
  6. package/dist/cli/overrides.js +10 -1
  7. package/dist/constants.js +52 -0
  8. package/dist/index.js +25 -719
  9. package/dist/output/cyclonedx.js +12 -0
  10. package/dist/output/html-reporter.js +73 -38
  11. package/dist/output/multi-folder-html-reporter.js +16 -10
  12. package/dist/output/multi-folder-printer.js +1 -1
  13. package/dist/output/override-findings-sarif.js +1 -0
  14. package/dist/output/printers.js +427 -270
  15. package/dist/output/sarif.js +17 -1
  16. package/dist/output/sbom-dependency-edges.js +29 -19
  17. package/dist/overrides/admitted-scan.js +158 -0
  18. package/dist/overrides/api.js +16 -0
  19. package/dist/overrides/context-builder.js +4 -0
  20. package/dist/overrides/context.js +8 -1
  21. package/dist/overrides/detectors/index.js +2 -0
  22. package/dist/overrides/detectors/oa010-vulnerable-floor.js +123 -0
  23. package/dist/overrides/parsing/registry.js +53 -0
  24. package/dist/parsers/bun-lock-graph.js +182 -0
  25. package/dist/parsers/bun-lock.js +93 -132
  26. package/dist/parsers/index.js +75 -149
  27. package/dist/parsers/multi-package.js +5 -6
  28. package/dist/parsers/pnpm-lock-graph.js +94 -0
  29. package/dist/parsers/pnpm-lock.js +5 -5
  30. package/dist/parsers/yarn-lock-graph.js +148 -0
  31. package/dist/parsers/yarn-lock.js +3 -3
  32. package/dist/remediation/fix-commands.js +48 -7
  33. package/dist/scan/completeness.js +1 -1
  34. package/dist/scan/single-scan.js +643 -0
  35. package/dist/utils/file.js +11 -14
  36. package/dist/utils/version.js +10 -0
  37. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
1
  import { existsSync } from "node:fs";
2
+ import process from "node:process";
2
3
  import { LocalAdvisoryDatabase } from "../advisory/local-db.js";
3
4
  import { getDefaultAdvisoryDbPath } from "../advisory/osv-sync.js";
5
+ import { chalk } from "../utils/chalk.js";
4
6
  /**
5
7
  * Creates an empty local advisory database with the current schema and no data.
6
8
  * This is for air-gapped users who cannot run `advisories sync`: they run
@@ -22,3 +24,14 @@ export function initAdvisoryDatabase(outputPath) {
22
24
  db.close();
23
25
  return dbPath;
24
26
  }
27
+ export function runAdvisoriesInit(options) {
28
+ try {
29
+ const dbPath = initAdvisoryDatabase(options.output);
30
+ console.log(`${chalk.gray("Advisory database:")} created an empty advisory database at ${chalk.cyan(dbPath)}`);
31
+ console.log(chalk.gray(`Populate it from your own sources, then scan with \`--offline-db ${dbPath}\`.`));
32
+ }
33
+ catch (error) {
34
+ console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
35
+ process.exit(1);
36
+ }
37
+ }
@@ -0,0 +1,30 @@
1
+ import process from "node:process";
2
+ import { syncOsvAdvisories } from "../advisory/osv-sync.js";
3
+ import { createSpinner } from "../output/spinner.js";
4
+ import { chalk } from "../utils/chalk.js";
5
+ import { pluralize } from "../utils/string.js";
6
+ export async function runAdvisoriesSync({ options, fetchImpl }) {
7
+ const spinner = createSpinner("Preparing advisory sync...", options);
8
+ const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
9
+ const result = await syncOsvAdvisories({
10
+ outputPath: options.output,
11
+ fetchImpl,
12
+ onProgress: (event) => {
13
+ if (event.phase === "complete") {
14
+ return;
15
+ }
16
+ if (usePlainProgressLogs) {
17
+ console.log(event.message);
18
+ return;
19
+ }
20
+ spinner.update(event.message);
21
+ },
22
+ });
23
+ if (usePlainProgressLogs) {
24
+ console.log(`Advisory sync complete (${result.advisoryCount} records)`);
25
+ }
26
+ else {
27
+ spinner.succeed(`Advisory sync complete (${result.advisoryCount} records)`);
28
+ }
29
+ console.log(`${chalk.gray("Advisory database:")} synced ${result.advisoryCount} ${pluralize(result.advisoryCount, "record")} to ${chalk.cyan(result.dbPath)}`);
30
+ }
@@ -38,3 +38,18 @@ export function runConfigCommand(sub) {
38
38
  return;
39
39
  }
40
40
  }
41
+ export function handleConfigCommand(configSubcommand) {
42
+ if (!configSubcommand) {
43
+ console.error(chalk.red("Error: config requires a subcommand: set, unset, show"));
44
+ console.error(chalk.gray("Run `cve-lite --help` for usage."));
45
+ process.exit(1);
46
+ }
47
+ try {
48
+ runConfigCommand(configSubcommand);
49
+ }
50
+ catch (error) {
51
+ const message = error instanceof Error ? error.message : String(error);
52
+ console.error(chalk.red(`Error: ${message}`));
53
+ process.exit(1);
54
+ }
55
+ }
@@ -1,6 +1,9 @@
1
1
  import fs from "node:fs";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
+ import process from "node:process";
5
+ import { chalk } from "../utils/chalk.js";
6
+ import { createCertAwareFetch } from "../utils/network.js";
4
7
  export const ConfigAction = {
5
8
  Set: "set",
6
9
  Unset: "unset",
@@ -64,3 +67,29 @@ export function writeConfig(config) {
64
67
  }
65
68
  fs.writeFileSync(getConfigPath(), JSON.stringify(config, null, 2) + "\n", "utf8");
66
69
  }
70
+ export function setupCaCert(options, debugLog) {
71
+ const savedConfig = readConfig();
72
+ const resolvedCaCert = options.caCert ?? savedConfig.caCert;
73
+ if (resolvedCaCert) {
74
+ if (!options.caCert && savedConfig.caCert) {
75
+ try {
76
+ validateCaCertFile(resolvedCaCert);
77
+ }
78
+ catch (err) {
79
+ const message = err instanceof Error ? err.message : String(err);
80
+ console.error(chalk.red(`Error: Saved ca-cert is no longer valid: ${message}`));
81
+ console.error(chalk.gray(`Run \`cve-lite config unset ca-cert\` to remove it.`));
82
+ process.exit(1);
83
+ }
84
+ }
85
+ process.env.NODE_EXTRA_CA_CERTS = resolvedCaCert;
86
+ }
87
+ const certFetch = resolvedCaCert ? createCertAwareFetch(resolvedCaCert) : undefined;
88
+ if (debugLog) {
89
+ debugLog("Config loaded", {
90
+ caCert: resolvedCaCert ?? null,
91
+ nodeExtraCaCerts: process.env.NODE_EXTRA_CA_CERTS ?? null,
92
+ });
93
+ }
94
+ return certFetch;
95
+ }
package/dist/cli/help.js CHANGED
@@ -48,7 +48,7 @@ export function printHelp() {
48
48
  " --debug Write verbose runtime/network diagnostics to a timestamped log file",
49
49
  " --verbose Show detailed output with fix plan, paths, and full table",
50
50
  " --prod-only Exclude dev dependencies where available",
51
- " --check-overrides Also audit package.json overrides (OA001-OA009, PD001-PD002); findings",
51
+ " --check-overrides Also audit package.json overrides (OA001-OA010, PD001-PD002); findings",
52
52
  " print, thread to JSON/SARIF/HTML, and count toward --fail-on",
53
53
  " --check-maintenance Also flag direct deps that block a transitive CVE fix via a major-version",
54
54
  " drag, or are marked deprecated on npm (DM001); counts toward --fail-on",
@@ -100,13 +100,13 @@ export function printOverridesHelp() {
100
100
  const lines = [
101
101
  `${OVERRIDES_COMMAND} [path] [flags]`,
102
102
  "",
103
- "Audit package.json overrides and phantom dependency imports (OA001-OA009, PD001-PD002).",
103
+ "Audit package.json overrides and phantom dependency imports (OA001-OA010, PD001-PD002).",
104
104
  "",
105
105
  "Flags:",
106
106
  " --json Emit findings as JSON",
107
107
  " --fix Apply RFC 6902 patches for findings with auto-fix",
108
- " --rule <id> Only run a specific rule (OA001-OA009, PD001-PD002)",
109
- " --check-network Enable OA007 registry drift check (opt-in network)",
108
+ " --rule <id> Only run a specific rule (OA001-OA010, PD001-PD002)",
109
+ " --check-network Enable OA007 registry drift + OA010 admitted-range checks (opt-in network)",
110
110
  " --audit-log <path> Stream NDJSON change-control to <path>",
111
111
  " --fail-on <severity> Exit non-zero at or above this severity (default: critical)",
112
112
  " --debug Enable debug logging",
@@ -1,6 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path, { resolve } from "node:path";
3
3
  import { buildOverrideContext, audit, applyFix } from "../overrides/index.js";
4
+ import { createAdvisorySource } from "../scanner.js";
4
5
  import { createAuditLog } from "../audit-log/index.js";
5
6
  import { EXIT_OK, EXIT_FINDINGS, EXIT_ERROR } from "../types.js";
6
7
  import { renderOverrideFindings } from "../output/override-findings-terminal.js";
@@ -10,13 +11,20 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
10
11
  const projectPath = resolve(projectArg ?? ".");
11
12
  const ownsAuditLog = !injectedAuditLog;
12
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;
13
18
  try {
14
19
  const ctx = buildOverrideContext(projectPath, {
15
20
  auditLog,
16
21
  logger,
17
22
  checkNetwork: options.checkNetwork === true,
18
23
  });
19
- const result = await audit(ctx, { checkNetwork: options.checkNetwork === true });
24
+ const result = await audit(ctx, {
25
+ checkNetwork: options.checkNetwork === true,
26
+ advisorySource: advisoryContext?.advisorySource,
27
+ });
20
28
  let findings = result.findings;
21
29
  if (options.rule) {
22
30
  findings = findings.filter((f) => f.ruleId === options.rule);
@@ -65,6 +73,7 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
65
73
  return EXIT_ERROR;
66
74
  }
67
75
  finally {
76
+ advisoryContext?.cleanup?.();
68
77
  if (ownsAuditLog)
69
78
  auditLog.close();
70
79
  }
package/dist/constants.js CHANGED
@@ -19,6 +19,58 @@ export const MAL_GIT_SOURCE_COMPACT_MESSAGE = "Git source — verify repository
19
19
  export const MAL_GIT_SOURCE_LEGEND_MESSAGE = "verify repository and org are trusted";
20
20
  export const MAL_GIT_SOURCE_PINNED_DISPLAY = "⚠ Git source (SHA-pinned)";
21
21
  export const MAL_GIT_SOURCE_FLOATING_DISPLAY = "⚠ Git source (floating ref)";
22
+ /**
23
+ * Supported lockfiles in precedence order, strongest signal first.
24
+ *
25
+ * This is the single source of truth for lockfile precedence. Root detection,
26
+ * nested discovery and `chooseBestLockfile` all read it, so a repo resolves to
27
+ * the same lockfile whether it sits at the root or in a subdirectory.
28
+ *
29
+ * npm-shrinkwrap.json outranks package-lock.json because npm itself ignores
30
+ * package-lock.json when a shrinkwrap is present.
31
+ */
32
+ /**
33
+ * Every lockfile the scanner understands. Order here is not precedence: it only
34
+ * fixes the set and the type. The two precedence lists below are what decide
35
+ * which file wins, and they currently disagree with each other.
36
+ */
37
+ export const LOCKFILE_NAMES = [
38
+ "bun.lock",
39
+ "npm-shrinkwrap.json",
40
+ "package-lock.json",
41
+ "pnpm-lock.yaml",
42
+ "yarn.lock",
43
+ ];
44
+ /**
45
+ * Precedence when several lockfiles sit at the repo root.
46
+ */
47
+ export const LOCKFILE_PRIORITY_ROOT = [
48
+ "bun.lock",
49
+ "npm-shrinkwrap.json",
50
+ "package-lock.json",
51
+ "pnpm-lock.yaml",
52
+ "yarn.lock",
53
+ ];
54
+ /**
55
+ * Precedence when several lockfiles sit in the same directory below the root.
56
+ *
57
+ * This disagrees with the root order on six of the ten pairs: `bun.lock` ranks
58
+ * last here and first at the root, and `npm-shrinkwrap.json` ranks last here
59
+ * and second at the root. That is a real inconsistency, and the shrinkwrap
60
+ * placement is a bug, since npm ignores `package-lock.json` whenever a
61
+ * shrinkwrap is present.
62
+ *
63
+ * Both are preserved exactly as they were so that this change is behaviour
64
+ * neutral. Reconciling them changes which lockfile is scanned on real projects,
65
+ * so it belongs in its own change where that can be argued and tested.
66
+ */
67
+ export const LOCKFILE_PRIORITY_NESTED = [
68
+ "package-lock.json",
69
+ "pnpm-lock.yaml",
70
+ "yarn.lock",
71
+ "bun.lock",
72
+ "npm-shrinkwrap.json",
73
+ ];
22
74
  export const EXCLUDED_DIRS = new Set([
23
75
  ".git",
24
76
  "node_modules",