cve-lite-cli 1.39.0 → 1.41.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 (82) hide show
  1. package/README.md +28 -22
  2. package/dist/advisory/local-advisory-source.js +9 -5
  3. package/dist/advisory/local-db.js +91 -13
  4. package/dist/advisory/osv-sync.js +187 -56
  5. package/dist/advisory/staging-directory.js +112 -0
  6. package/dist/cli/advisories-sync.js +16 -2
  7. package/dist/cli/args.js +46 -35
  8. package/dist/cli/config.js +4 -1
  9. package/dist/cli/help.js +5 -3
  10. package/dist/cli/validate.js +23 -1
  11. package/dist/constants.js +15 -28
  12. package/dist/index.js +8 -3
  13. package/dist/osv/severity.js +1 -1
  14. package/dist/output/cyclonedx.js +24 -15
  15. package/dist/output/debug.js +68 -18
  16. package/dist/output/formatters.js +35 -7
  17. package/dist/output/html-reporter.js +68 -12
  18. package/dist/output/multi-folder-html-reporter.js +71 -11
  19. package/dist/output/output-dir.js +193 -7
  20. package/dist/output/override-findings-html.js +3 -6
  21. package/dist/output/override-findings-terminal.js +7 -12
  22. package/dist/output/override-fix-command.js +13 -0
  23. package/dist/output/printers.js +27 -12
  24. package/dist/output/sarif.js +168 -57
  25. package/dist/output/sbom-dependency-edges.js +16 -10
  26. package/dist/output/sbom-file.js +14 -6
  27. package/dist/output/scan-json.js +46 -3
  28. package/dist/output/spdx.js +61 -23
  29. package/dist/output/spinner.js +2 -1
  30. package/dist/output/write-outputs.js +143 -41
  31. package/dist/overrides/context-builder.js +23 -70
  32. package/dist/overrides/parsing/registry.js +1 -1
  33. package/dist/parsers/bun-lock.js +1 -2
  34. package/dist/parsers/index.js +22 -1
  35. package/dist/parsers/npm-lock-graph.js +39 -1
  36. package/dist/parsers/package-lock.js +25 -5
  37. package/dist/parsers/pnpm-lock.js +26 -12
  38. package/dist/parsers/utils.js +5 -3
  39. package/dist/parsers/yarn-lock-graph.js +5 -2
  40. package/dist/parsers/yarn-lock.js +1 -2
  41. package/dist/remediation/fix-commands.js +140 -50
  42. package/dist/remediation/npm-registry.js +56 -7
  43. package/dist/remediation/npm-transitive-graph.js +30 -72
  44. package/dist/remediation/npm-transitive-resolution.js +35 -107
  45. package/dist/remediation/parent-candidate-resolver.js +65 -0
  46. package/dist/remediation/parent-upgrade-blockers.js +51 -0
  47. package/dist/remediation/parent-upgrade.js +11 -116
  48. package/dist/remediation/registry-parent-ranges.js +21 -0
  49. package/dist/remediation/transitive-chain-resolver.js +3 -3
  50. package/dist/scan/completeness.js +17 -11
  51. package/dist/scan/multi-folder-scan.js +154 -59
  52. package/dist/scan/override-audit.js +11 -1
  53. package/dist/scan/single-scan.js +123 -67
  54. package/dist/scanner.js +288 -66
  55. package/dist/skills/content.js +12 -12
  56. package/dist/usage/scanner.js +19 -8
  57. package/dist/utils/array.js +11 -3
  58. package/dist/utils/contextual-signals.js +1 -1
  59. package/dist/utils/debug-bundle.js +118 -0
  60. package/dist/utils/debug-project.js +102 -0
  61. package/dist/utils/debug-redaction.js +117 -0
  62. package/dist/utils/effective-options.js +55 -0
  63. package/dist/utils/file.js +2 -1
  64. package/dist/utils/finding.js +1 -1
  65. package/dist/utils/fix-runner.js +98 -15
  66. package/dist/utils/import-type-queries.js +322 -0
  67. package/dist/utils/network.js +14 -10
  68. package/dist/utils/npm-lockfile.js +12 -0
  69. package/dist/utils/osv-fetch.js +70 -0
  70. package/dist/utils/package-identity.js +43 -0
  71. package/dist/utils/package-manager-source.js +24 -0
  72. package/dist/utils/purl.js +37 -0
  73. package/dist/utils/registry-config.js +129 -0
  74. package/dist/utils/severity.js +8 -0
  75. package/dist/utils/string.js +8 -0
  76. package/dist/utils/validate-url.js +4 -4
  77. package/dist/utils/version.js +47 -8
  78. package/dist/utils/versions/osv-range.js +191 -0
  79. package/dist/utils/versions/pep440.js +246 -0
  80. package/dist/utils/versions/scheme.js +10 -0
  81. package/dist/utils/vuln.js +75 -0
  82. package/package.json +3 -2
@@ -4,16 +4,16 @@ export const SKILL_CONTENT = `Run \`cve-lite . --json\` in the project root. The
4
4
 
5
5
  Key fields in each finding:
6
6
 
7
- - \`package\`, \`version\` — the vulnerable package
8
- - \`severity\` — \`critical | high | medium | low | unknown\`
9
- - \`relationship\` — \`direct | transitive\`
10
- - \`firstFixedVersion\` — minimum safe version, if known
11
- - \`runnableFixCommand\` — exact install command to run, if available
12
- - \`recommendedAction\` — human-readable fix guidance
13
- - \`cves\` — CVE IDs
14
- - \`dependencyPaths\` — chains showing how the package is pulled in
15
- - \`usage.imported\` — whether the package is imported in source files; \`null\` when the usage scan hit its file cap (import status unknown), and \`usage\` itself is \`null\` when \`--usage\` was not run
16
- - \`contextualSignals\` — heuristic prioritization hints (\`usage\`, \`reachabilityHint\`, \`exposure\`). Not exploitability verdicts; \`not_imported\` / \`not_indicated\` does not mean safe or unreachable
7
+ - \`package\`, \`version\`: the vulnerable package
8
+ - \`severity\`: \`critical | high | medium | low | unknown\`
9
+ - \`relationship\`: \`direct | transitive\`
10
+ - \`firstFixedVersion\`: minimum safe version, if known
11
+ - \`runnableFixCommand\`: exact install command to run, if available
12
+ - \`recommendedAction\`: human-readable fix guidance
13
+ - \`cves\`: CVE IDs
14
+ - \`dependencyPaths\`: chains showing how the package is pulled in
15
+ - \`usage.imported\`: whether the package is imported in source files; \`null\` when the usage scan hit its file cap (import status unknown), and \`usage\` itself is \`null\` when \`--usage\` was not run
16
+ - \`contextualSignals\`: heuristic prioritization hints (\`usage\`, \`reachabilityHint\`, \`exposure\`). Not exploitability verdicts; \`not_imported\` / \`not_indicated\` does not mean safe or unreachable
17
17
 
18
18
  Top-level \`suggestedFixCommands\` contains grouped, copy-ready fix commands.
19
19
 
@@ -22,8 +22,8 @@ Top-level \`suggestedFixCommands\` contains grouped, copy-ready fix commands.
22
22
  1. Critical before high before medium before low
23
23
  2. Direct dependencies before transitive
24
24
  3. If \`usage.imported === false\`, flag as lower practical risk but do not dismiss
25
- 4. If \`runnableFixCommand\` is present, that is the exact command to run — prefer it over manual guidance
26
- 5. Treat \`contextualSignals\` as triage context only — never as exploitability or runtime reachability
25
+ 4. If \`runnableFixCommand\` is present, that is the exact command to run: prefer it over manual guidance
26
+ 5. Treat \`contextualSignals\` as triage context only: never as exploitability or runtime reachability
27
27
 
28
28
  ### Codebase analysis
29
29
 
@@ -1,7 +1,9 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { EXCLUDED_DIRS } from "../constants.js";
4
- const ALLOWED_EXTS = new Set([".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"]);
4
+ import { importTypeQueryOffsets } from "../utils/import-type-queries.js";
5
+ const ALLOWED_EXTS = new Set([".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".mts", ".cts"]);
6
+ const TYPESCRIPT_DECLARATION_FILE = /\.d\.[cm]?ts$/;
5
7
  export const MAX_FILES_TO_SCAN = 5000;
6
8
  /**
7
9
  * Single source of truth for the cap disclosure, so the three call sites cannot
@@ -10,12 +12,13 @@ export const MAX_FILES_TO_SCAN = 5000;
10
12
  * reported. Otherwise it only warns that coverage is incomplete.
11
13
  */
12
14
  export function usageScanTruncationWarning(opts) {
15
+ const remedy = "The only way to improve usage scan coverage is to scan a narrower path.";
13
16
  const scope = opts?.subfolder ? ` in ${opts.subfolder}/` : "";
14
17
  const head = `Usage scan stopped at ${MAX_FILES_TO_SCAN} files${scope}`;
15
18
  if (opts?.onlyUsed) {
16
- return `${head}; --only-used filtering was skipped so packages imported only in unscanned files are not dropped.`;
19
+ return `${head}; --only-used filtering was skipped so packages imported only in unscanned files are not dropped. ${remedy}`;
17
20
  }
18
- return `${head}; packages imported only in unscanned files may not be detected.`;
21
+ return `${head}; packages imported only in unscanned files may not be detected. ${remedy}`;
19
22
  }
20
23
  const ALL_IMPORTS_EXCLUDED_DIRS = new Set([
21
24
  ...EXCLUDED_DIRS,
@@ -35,7 +38,7 @@ const ALL_IMPORTS_EXCLUDED_DIRS = new Set([
35
38
  // import 'pkg'
36
39
  // require('pkg')
37
40
  // await import('pkg')
38
- const IMPORT_REQUIRE_REGEX = /(?:(?:import|export)\s+[\w\s{},*]+\s+from\s+['"]([^'"]+)['"]|import\s+['"]([^'"]+)['"]|require\s*\(\s*['"]([^'"]+)['"]\s*\)|import\s*\(\s*['"]([^'"]+)['"]\s*\))/g;
41
+ const IMPORT_REQUIRE_REGEX = /(?:(?:import|export)\s+[\w$\s{},*]+\s+from\s+['"]([^'"]+)['"]|import\s+['"]([^'"]+)['"]|require\s*\(\s*['"]([^'"]+)['"]\s*\)|import\s*\(\s*['"]([^'"]+)['"]\s*\))/g;
39
42
  // A `/` opens a regex literal only where an expression may begin. After a value
40
43
  // - an identifier, a number, `)`, `]` or a closing backtick - it is division.
41
44
  // These keywords are the cases where a `/` directly after a word is still a
@@ -189,7 +192,7 @@ export function isTypeOnlyImportStatement(statement) {
189
192
  const clause = /^(?:import|export)\s+([\s\S]*?)\s+from\s/.exec(statement)?.[1]?.trim();
190
193
  if (!clause)
191
194
  return false;
192
- if (/^type\s+[\w{*]/.test(clause))
195
+ if (/^type\s+[\w${*]/.test(clause))
193
196
  return true;
194
197
  const braced = /^\{([\s\S]*)\}$/.exec(clause);
195
198
  if (!braced)
@@ -202,7 +205,15 @@ export function isTypeOnlyImportStatement(statement) {
202
205
  // `import()`, minus anything inside a comment or in a type-only import.
203
206
  function collectRuntimeImportPaths(content) {
204
207
  const paths = [];
205
- for (const match of stripComments(content).matchAll(IMPORT_REQUIRE_REGEX)) {
208
+ const source = stripComments(content);
209
+ let typeQueries;
210
+ for (const match of source.matchAll(IMPORT_REQUIRE_REGEX)) {
211
+ if (match[4]) {
212
+ typeQueries ??= importTypeQueryOffsets(source);
213
+ if (typeQueries.has(match.index)) {
214
+ continue;
215
+ }
216
+ }
206
217
  if (match[1] && isTypeOnlyImportStatement(match[0]))
207
218
  continue;
208
219
  const importPath = match[1] || match[2] || match[3] || match[4];
@@ -252,7 +263,7 @@ export function scanProjectForPackageUsage(projectPath, packagesToLookFor) {
252
263
  }
253
264
  else if (entry.isFile()) {
254
265
  const ext = path.extname(entry.name);
255
- if (ALLOWED_EXTS.has(ext)) {
266
+ if (ALLOWED_EXTS.has(ext) && !TYPESCRIPT_DECLARATION_FILE.test(entry.name)) {
256
267
  // Cap at 5000 files to prevent performance issues on massive projects
257
268
  if (scannedCount >= MAX_FILES_TO_SCAN) {
258
269
  truncated = true;
@@ -323,7 +334,7 @@ export function scanAllImports(projectPath) {
323
334
  }
324
335
  else if (entry.isFile()) {
325
336
  const ext = path.extname(entry.name);
326
- if (ALLOWED_EXTS.has(ext)) {
337
+ if (ALLOWED_EXTS.has(ext) && !TYPESCRIPT_DECLARATION_FILE.test(entry.name)) {
327
338
  if (scannedCount >= MAX_FILES_TO_SCAN) {
328
339
  truncated = true;
329
340
  return;
@@ -20,14 +20,22 @@ export function uniquePathArrays(paths) {
20
20
  }
21
21
  return output;
22
22
  }
23
- export async function runWithConcurrency(items, limit, fn) {
23
+ export async function runWithConcurrency(items, limit, fn, options) {
24
24
  const results = new Array(items.length);
25
25
  const queue = items.map((item, index) => ({ item, index }));
26
26
  let next = 0;
27
+ let stopped = false;
27
28
  async function worker() {
28
- while (next < queue.length) {
29
+ while (!stopped && next < queue.length) {
29
30
  const { item, index } = queue[next++];
30
- results[index] = await fn(item);
31
+ try {
32
+ results[index] = await fn(item);
33
+ }
34
+ catch (error) {
35
+ if (options?.onError === "stop")
36
+ stopped = true;
37
+ throw error;
38
+ }
31
39
  }
32
40
  }
33
41
  await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
@@ -5,7 +5,7 @@
5
5
  * a network probe, a runtime check, or an exploitability verdict.
6
6
  *
7
7
  * Short/generic names (`http`, `next`, `router`, …) match the exact package or
8
- * a scoped prefix such as `@next/` — never hyphenated lookalikes. Distinctive
8
+ * a scoped prefix such as `@next/` - never hyphenated lookalikes. Distinctive
9
9
  * stacks (`express`, `fastify`, `@nestjs/`, …) still allow hyphen/token forms.
10
10
  */
11
11
  export const REQUEST_FACING_MARKERS = [
@@ -0,0 +1,118 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { getCliVersion } from "./version-info.js";
4
+ import { summarizeEffectiveOptions } from "./effective-options.js";
5
+ import { createBundleRedactor } from "./debug-redaction.js";
6
+ import { findNpmLockfile } from "./npm-lockfile.js";
7
+ import { buildProjectJson as projectMetadata } from "./debug-project.js";
8
+ export { redactDeep, redactPath } from "./debug-redaction.js";
9
+ function detectPackageManager(projectPath) {
10
+ if (fs.existsSync(path.join(projectPath, "pnpm-lock.yaml")))
11
+ return "pnpm";
12
+ if (fs.existsSync(path.join(projectPath, "bun.lockb")) || fs.existsSync(path.join(projectPath, "bun.lock")))
13
+ return "bun";
14
+ if (fs.existsSync(path.join(projectPath, "yarn.lock")))
15
+ return "yarn";
16
+ if (findNpmLockfile(projectPath))
17
+ return "npm";
18
+ return "unknown";
19
+ }
20
+ function readLockfileVersion(projectPath) {
21
+ const lockPath = findNpmLockfile(projectPath);
22
+ if (lockPath === null)
23
+ return null;
24
+ try {
25
+ const parsed = JSON.parse(fs.readFileSync(lockPath, "utf8"));
26
+ return typeof parsed.lockfileVersion === "number" ? parsed.lockfileVersion : null;
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ export function buildEnvironmentJson(options, projectPath) {
33
+ const packageManager = detectPackageManager(projectPath);
34
+ return {
35
+ cliVersion: getCliVersion(),
36
+ nodeVersion: process.version,
37
+ platform: process.platform,
38
+ arch: process.arch,
39
+ packageManager,
40
+ lockfileVersion: packageManager === "npm" ? readLockfileVersion(projectPath) : null,
41
+ nodeModulesPresent: fs.existsSync(path.join(projectPath, "node_modules")),
42
+ effectiveFlags: summarizeEffectiveOptions(options),
43
+ osvEndpoint: {
44
+ configured: !!options.osvUrl,
45
+ kind: !options.osvUrl || options.osvUrl.replace(/\/+$/, "") === "https://api.osv.dev" ? "default" : "custom",
46
+ },
47
+ };
48
+ }
49
+ function eventsJsonl(events, redact) {
50
+ return events.map(e => {
51
+ const obj = { timestamp: e.timestamp, message: e.message };
52
+ if (e.details !== undefined) {
53
+ // Keep the established flat event format, without letting details replace
54
+ // the event's message or timestamp.
55
+ if (e.details !== null && typeof e.details === "object" && !Array.isArray(e.details)) {
56
+ Object.assign(obj, e.details, { timestamp: e.timestamp, message: e.message });
57
+ if ("message" in e.details)
58
+ obj.detailsMessage = e.details.message;
59
+ }
60
+ else
61
+ obj.details = e.details;
62
+ }
63
+ return JSON.stringify(redact(obj));
64
+ }).join("\n") + (events.length ? "\n" : "");
65
+ }
66
+ export function buildEventsJsonl(events, projectPath) {
67
+ return eventsJsonl(events, createBundleRedactor(projectPath, [events]));
68
+ }
69
+ export function buildProjectJson(events, projectPath) {
70
+ const metadata = projectMetadata(events, projectPath);
71
+ return createBundleRedactor(projectPath, [events, metadata])(metadata);
72
+ }
73
+ /** Only the exact JSON path reported by this run's writer may be attached. */
74
+ export function createDebugBundle(events, options, projectPath, scanJsonPath) {
75
+ let scan;
76
+ if (options.json && scanJsonPath && !/\.(?:cdx|spdx)\.json$/i.test(scanJsonPath)) {
77
+ try {
78
+ scan = JSON.parse(fs.readFileSync(scanJsonPath, "utf8"));
79
+ }
80
+ catch { /* An unavailable scan artifact does not prevent a diagnostic bundle. */ }
81
+ }
82
+ const environment = buildEnvironmentJson(options, projectPath);
83
+ const project = projectMetadata(events, projectPath);
84
+ const redact = createBundleRedactor(projectPath, [events, options, environment, project, scan]);
85
+ const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
86
+ // A unique directory prevents a same-second run from inheriting scan.json
87
+ // from a previous bundle, including when this run failed before writing JSON.
88
+ const prefix = path.join(process.cwd(), `cve-lite-debug-${ts}-`);
89
+ let bundleDir;
90
+ try {
91
+ bundleDir = fs.mkdtempSync(prefix);
92
+ fs.writeFileSync(path.join(bundleDir, "environment.json"), JSON.stringify(redact(environment), null, 2), "utf8");
93
+ fs.writeFileSync(path.join(bundleDir, "events.jsonl"), eventsJsonl(events, redact), "utf8");
94
+ fs.writeFileSync(path.join(bundleDir, "project.json"), JSON.stringify(redact(project), null, 2), "utf8");
95
+ if (scan !== undefined)
96
+ fs.writeFileSync(path.join(bundleDir, "scan.json"), JSON.stringify(redact(scan), null, 2), "utf8");
97
+ }
98
+ catch (error) {
99
+ // Do not leave an apparently complete bundle after a partial write.
100
+ if (bundleDir !== undefined) {
101
+ try {
102
+ fs.rmSync(bundleDir, { recursive: true, force: true });
103
+ }
104
+ catch { /* best effort */ }
105
+ }
106
+ throw tagWriteTarget(error, bundleDir ?? prefix);
107
+ }
108
+ return bundleDir;
109
+ }
110
+ function tagWriteTarget(error, target) {
111
+ if (error && typeof error === "object") {
112
+ try {
113
+ Object.defineProperty(error, "writeTarget", { value: target });
114
+ }
115
+ catch { /* frozen */ }
116
+ }
117
+ return error;
118
+ }
@@ -0,0 +1,102 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import YAML from "yaml";
4
+ import { findNpmLockfile } from "./npm-lockfile.js";
5
+ function isDetails(value) {
6
+ return value !== null && typeof value === "object" && !Array.isArray(value);
7
+ }
8
+ function finiteCount(value) {
9
+ return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : null;
10
+ }
11
+ function stringList(value) {
12
+ if (!Array.isArray(value))
13
+ return null;
14
+ const values = value.filter((entry) => typeof entry === "string");
15
+ return values.length === value.length ? values : null;
16
+ }
17
+ /** Read only workspace declarations; this deliberately does not resolve members. */
18
+ function readWorkspaceGlobs(projectPath) {
19
+ const packageJsonPath = path.join(projectPath, "package.json");
20
+ try {
21
+ const manifest = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
22
+ if (isDetails(manifest)) {
23
+ const workspaces = manifest.workspaces;
24
+ const patterns = Array.isArray(workspaces)
25
+ ? stringList(workspaces)
26
+ : isDetails(workspaces) ? stringList(workspaces.packages) : null;
27
+ if (patterns !== null)
28
+ return patterns;
29
+ }
30
+ }
31
+ catch {
32
+ // A missing or invalid root manifest does not prevent other metadata.
33
+ }
34
+ try {
35
+ const parsed = YAML.parse(fs.readFileSync(path.join(projectPath, "pnpm-workspace.yaml"), "utf8"));
36
+ return isDetails(parsed) ? stringList(parsed.packages) : null;
37
+ }
38
+ catch {
39
+ return null;
40
+ }
41
+ }
42
+ /** Count package entries explicitly marked as links in npm's active lockfile. */
43
+ function readNpmLinkEntryCount(projectPath) {
44
+ const lockPath = findNpmLockfile(projectPath);
45
+ if (lockPath === null)
46
+ return null;
47
+ try {
48
+ const lockfile = JSON.parse(fs.readFileSync(lockPath, "utf8"));
49
+ if (!isDetails(lockfile) || !isDetails(lockfile.packages))
50
+ return null;
51
+ return Object.values(lockfile.packages).filter(entry => isDetails(entry) && entry.link === true).length;
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ }
57
+ /**
58
+ * Build project metadata from debug events and project declaration files.
59
+ * Workspace member names/counts are intentionally never inferred from lockfile maps.
60
+ */
61
+ export function buildProjectJson(events, projectPath) {
62
+ const project = {};
63
+ const skippedRules = [];
64
+ const workspaceGlobs = readWorkspaceGlobs(projectPath);
65
+ if (workspaceGlobs !== null)
66
+ project.workspaceGlobs = workspaceGlobs;
67
+ const linkEntryCount = readNpmLinkEntryCount(projectPath);
68
+ if (linkEntryCount !== null)
69
+ project.linkEntryCount = linkEntryCount;
70
+ for (const event of events) {
71
+ if (!isDetails(event.details))
72
+ continue;
73
+ if (event.message === "Findings classified") {
74
+ const direct = finiteCount(event.details.direct);
75
+ const transitive = finiteCount(event.details.transitive);
76
+ if (direct !== null)
77
+ project.directFindingCount = direct;
78
+ if (transitive !== null)
79
+ project.transitiveFindingCount = transitive;
80
+ continue;
81
+ }
82
+ if (event.message === "Scan finished") {
83
+ const packageCount = finiteCount(event.details.packages);
84
+ if (packageCount !== null)
85
+ project.packageCount = packageCount;
86
+ continue;
87
+ }
88
+ if (event.message === "Rules skipped" && Array.isArray(event.details.rules)) {
89
+ const eventProjectPath = typeof event.details.projectPath === "string" ? event.details.projectPath : undefined;
90
+ for (const rule of event.details.rules) {
91
+ if (!isDetails(rule) || typeof rule.ruleId !== "string" || typeof rule.reason !== "string")
92
+ continue;
93
+ skippedRules.push(eventProjectPath === undefined
94
+ ? { ruleId: rule.ruleId, reason: rule.reason }
95
+ : { ruleId: rule.ruleId, reason: rule.reason, projectPath: eventProjectPath });
96
+ }
97
+ }
98
+ }
99
+ if (skippedRules.length > 0)
100
+ project.skippedRules = skippedRules;
101
+ return project;
102
+ }
@@ -0,0 +1,117 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ const URL_PATTERN = /[a-z][a-z\d+.-]*:\/\/[^\s<>"'`]+/gi;
4
+ const SECRET_KEY = /^(?:password|passwd|_authToken|_auth|authToken|token|authorization|credentials?|apiKey|secret|accessToken|refreshToken)$/i;
5
+ const PRIVATE_VALUE_KEY = /^(?:cacheDir|offlineDb|output|caCert|nodeExtraCaCerts|auditLog|report|osvUrl|proxy|httpsProxy|httpProxy)$/i;
6
+ /** One context for every file: hostnames and credentials also occur bare in errors. */
7
+ export function createBundleRedactor(projectPath, inputs) {
8
+ const sensitive = new Set();
9
+ const hosts = new Set();
10
+ const seen = new WeakSet();
11
+ function collect(value, key = "") {
12
+ if (typeof value === "string") {
13
+ if ((SECRET_KEY.test(key) || PRIVATE_VALUE_KEY.test(key)) && value)
14
+ sensitive.add(value);
15
+ for (const match of value.replace(/\\\//g, "/").matchAll(URL_PATTERN)) {
16
+ try {
17
+ const url = new URL(match[0]);
18
+ if (url.hostname)
19
+ hosts.add(url.hostname);
20
+ for (const [name, param] of url.searchParams) {
21
+ if (SECRET_KEY.test(name) && param)
22
+ sensitive.add(param);
23
+ }
24
+ for (const part of [url.username, url.password]) {
25
+ if (!part)
26
+ continue;
27
+ sensitive.add(part);
28
+ try {
29
+ sensitive.add(decodeURIComponent(part));
30
+ }
31
+ catch { /* malformed escape */ }
32
+ }
33
+ }
34
+ catch { /* All URL-shaped strings are still removed below. */ }
35
+ }
36
+ }
37
+ else if (value && typeof value === "object" && !seen.has(value)) {
38
+ seen.add(value);
39
+ for (const [k, v] of Object.entries(value)) {
40
+ collect(k);
41
+ collect(v, k);
42
+ }
43
+ }
44
+ }
45
+ inputs.forEach(input => collect(input));
46
+ const replacements = [...sensitive].filter(Boolean).sort((a, b) => b.length - a.length);
47
+ const home = os.homedir();
48
+ const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
49
+ const homePattern = home ? new RegExp(escape(home) + "(?:[/\\\\][^\\n\\r\\\"'<>)]*)?", "g") : null;
50
+ function text(value) {
51
+ let result = value.replace(/\\\//g, "/").replace(URL_PATTERN, "<url>");
52
+ for (const host of hosts)
53
+ result = result.replace(new RegExp(escape(host), "gi"), "<host>");
54
+ for (const secret of replacements)
55
+ result = result.split(secret).join("<redacted>");
56
+ // Whole project paths retain useful relative context; other home paths lose
57
+ // the entire suffix, not just the username. Embedded paths are conservative.
58
+ if (path.isAbsolute(result))
59
+ return redactPath(result, projectPath);
60
+ if (homePattern)
61
+ result = result.replace(homePattern, "<home>");
62
+ result = result.replace(/(?:[A-Za-z]:\\|\/)(?:[^\s"'<>()[\],;]+[\/\\])+[^\s"'<>()[\],;]*/g, match => redactPath(match, projectPath));
63
+ return result;
64
+ }
65
+ function redact(value, ancestors = new WeakSet()) {
66
+ if (typeof value === "string")
67
+ return text(value);
68
+ if (!value || typeof value !== "object")
69
+ return value;
70
+ if (ancestors.has(value))
71
+ return "<circular>";
72
+ ancestors.add(value);
73
+ let output;
74
+ if (Array.isArray(value)) {
75
+ output = value.map(v => redact(v, ancestors));
76
+ }
77
+ else {
78
+ const out = Object.create(null);
79
+ for (const [key, v] of Object.entries(value)) {
80
+ const safeKey = text(key);
81
+ if (SECRET_KEY.test(key) || PRIVATE_VALUE_KEY.test(key)) {
82
+ out[safeKey] = v == null || v === false ? v : true;
83
+ }
84
+ else if (/^(?:registry|defaultRegistry)$/i.test(key) && typeof v === "string") {
85
+ out[safeKey] = { configured: true, kind: v === "https://registry.npmjs.org" || v === "https://registry.npmjs.org/" ? "default" : "custom" };
86
+ }
87
+ else if (key === "args" && Array.isArray(v)) {
88
+ // Never preserve positional or option values (including relative paths).
89
+ out[safeKey] = v.map(arg => typeof arg === "string" && /^--[a-z][a-z-]*(?:=.*)?$/i.test(arg)
90
+ ? arg.split("=")[0] : "<set>");
91
+ }
92
+ else {
93
+ out[safeKey] = redact(v, ancestors);
94
+ }
95
+ }
96
+ output = out;
97
+ }
98
+ ancestors.delete(value);
99
+ return output;
100
+ }
101
+ return (value) => redact(value);
102
+ }
103
+ export function redactPath(p, projectPath) {
104
+ if (typeof p !== "string" || !path.isAbsolute(p))
105
+ return p;
106
+ const project = path.resolve(projectPath);
107
+ const abs = path.resolve(p);
108
+ if (abs === project || abs.startsWith(project + path.sep))
109
+ return path.relative(project, abs) || ".";
110
+ const home = os.homedir();
111
+ if (home && (abs === home || abs.startsWith(home + path.sep)))
112
+ return "<home>";
113
+ return "<outside-project>";
114
+ }
115
+ export function redactDeep(value, projectPath) {
116
+ return createBundleRedactor(projectPath, [value])(value);
117
+ }
@@ -0,0 +1,55 @@
1
+ import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH } from "../constants.js";
2
+ export function summarizeEffectiveOptions(options) {
3
+ const summary = {
4
+ json: options.json ?? false,
5
+ debug: options.debug ?? false,
6
+ verbose: options.verbose ?? false,
7
+ fix: options.fix ?? false,
8
+ ratchet: options.ratchet ?? false,
9
+ createPr: options.createPr ?? false,
10
+ prodOnly: options.prodOnly ?? false,
11
+ offline: options.offline ?? false,
12
+ all: options.all ?? false,
13
+ onlyUsed: options.onlyUsed ?? false,
14
+ noOpen: options.noOpen ?? false,
15
+ noCache: options.noCache ?? false,
16
+ sarif: options.sarif ?? false,
17
+ cdx: options.cdx ?? false,
18
+ sbomInventoryOnly: options.sbomInventoryOnly ?? false,
19
+ checkOverrides: options.checkOverrides ?? false,
20
+ checkMaintenance: options.checkMaintenance ?? false,
21
+ checkLicenses: options.checkLicenses ?? false,
22
+ checkNetwork: options.checkNetwork ?? false,
23
+ allowPrivateOsvUrl: options.allowPrivateOsvUrl ?? false,
24
+ usage: options.usage ?? false,
25
+ failOn: options.failOn,
26
+ incompletePolicy: options.incompletePolicy,
27
+ // Same normalization as the CLI entrypoint (src/index.ts).
28
+ batchSize: Number(options.batchSize || DEFAULT_BATCH_SIZE),
29
+ searchDepth: Math.max(0, Number(options.searchDepth || DEFAULT_SEARCH_DEPTH)),
30
+ };
31
+ if (options.minSeverity !== undefined)
32
+ summary.minSeverity = options.minSeverity;
33
+ if (options.sbom !== undefined)
34
+ summary.sbom = options.sbom;
35
+ if (options.rule !== undefined)
36
+ summary.rule = options.rule;
37
+ if (options.prBase !== undefined)
38
+ summary.prBase = options.prBase;
39
+ // Path/URL options: record only that they were set, never the value.
40
+ if (options.offlineDb)
41
+ summary.offlineDb = true;
42
+ if (options.cacheDir)
43
+ summary.cacheDir = true;
44
+ if (options.osvUrl)
45
+ summary.osvUrl = true;
46
+ if (options.output)
47
+ summary.output = true;
48
+ if (options.caCert)
49
+ summary.caCert = true;
50
+ if (options.auditLog)
51
+ summary.auditLog = true;
52
+ if (options.report)
53
+ summary.report = true;
54
+ return summary;
55
+ }
@@ -64,7 +64,8 @@ export function chooseBestLockfile(candidates) {
64
64
  }
65
65
  /**
66
66
  * Position in LOCKFILE_PRIORITY_NESTED, with anything unrecognised sorting last.
67
- * Shared with root detection so both paths agree on precedence.
67
+ * npm shrinkwrap precedence agrees with root detection; cross-manager
68
+ * differences are documented alongside the priority lists.
68
69
  */
69
70
  function lockfileRank(filePath) {
70
71
  const name = path.basename(filePath);
@@ -12,7 +12,7 @@ export function getPrimaryParent(finding) {
12
12
  /**
13
13
  * Unique root (top-level) dependencies that pull in this package, derived from
14
14
  * every known dependencyPaths chain. Paths of length < 3 (direct dependencies,
15
- * where the package itself is path[1]) are excluded — there is no meaningful
15
+ * where the package itself is path[1]) are excluded - there is no meaningful
16
16
  * root distinct from the package.
17
17
  *
18
18
  * Gated on relationship === "transitive": a package can be a direct dependency