cve-lite-cli 1.24.0 → 1.26.0-beta.1

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 (77) hide show
  1. package/README.md +83 -2
  2. package/assets/OWASP_Logo_Black_TM.png +0 -0
  3. package/assets/logo-with-title-removebg-preview.png +0 -0
  4. package/dist/advisory/local-db.js +7 -1
  5. package/dist/advisory/osv-advisory-source.js +2 -1
  6. package/dist/audit-log/events.js +3 -0
  7. package/dist/audit-log/handle.js +20 -0
  8. package/dist/audit-log/index.js +16 -0
  9. package/dist/audit-log/ndjson-writer.js +28 -0
  10. package/dist/cli/args.js +75 -0
  11. package/dist/cli/fix-overrides-hook.js +64 -0
  12. package/dist/cli/help.js +24 -1
  13. package/dist/cli/overrides.js +67 -0
  14. package/dist/cli/validate.js +9 -1
  15. package/dist/index.js +310 -21
  16. package/dist/osv/cache.js +28 -4
  17. package/dist/output/formatters.js +22 -18
  18. package/dist/output/html-reporter.js +37 -8
  19. package/dist/output/logos.js +18 -0
  20. package/dist/output/multi-folder-html-reporter.js +3 -4
  21. package/dist/output/override-findings-html.js +63 -0
  22. package/dist/output/override-findings-json.js +3 -0
  23. package/dist/output/override-findings-sarif.js +52 -0
  24. package/dist/output/override-findings-terminal.js +106 -0
  25. package/dist/output/printers.js +66 -23
  26. package/dist/output/sarif.js +77 -8
  27. package/dist/output/write-outputs.js +7 -3
  28. package/dist/overrides/api.js +79 -0
  29. package/dist/overrides/composite.js +23 -0
  30. package/dist/overrides/context-builder.js +150 -0
  31. package/dist/overrides/context.js +3 -0
  32. package/dist/overrides/detectors/index.js +23 -0
  33. package/dist/overrides/detectors/oa001-orphaned-target.js +36 -0
  34. package/dist/overrides/detectors/oa002-floating-tag.js +40 -0
  35. package/dist/overrides/detectors/oa003-wrong-section.js +48 -0
  36. package/dist/overrides/detectors/oa004-surpassed-pin.js +49 -0
  37. package/dist/overrides/detectors/oa005-nested-ineffective.js +128 -0
  38. package/dist/overrides/detectors/oa006-coupled-platform-binary.js +170 -0
  39. package/dist/overrides/detectors/oa007-frozen-latest.js +69 -0
  40. package/dist/overrides/detectors/oa008-materialized.js +75 -0
  41. package/dist/overrides/detectors/platform-binary.js +37 -0
  42. package/dist/overrides/fixer.js +199 -0
  43. package/dist/overrides/index.js +5 -0
  44. package/dist/overrides/parsing/installed-tree.js +164 -0
  45. package/dist/overrides/parsing/json-pointer.js +8 -0
  46. package/dist/overrides/parsing/node-modules.js +19 -0
  47. package/dist/overrides/parsing/package-json.js +139 -0
  48. package/dist/overrides/parsing/registry.js +66 -0
  49. package/dist/overrides/types.js +2 -0
  50. package/dist/parsers/pnpm-lock.js +46 -3
  51. package/dist/parsers/yarn-lock.js +2 -2
  52. package/dist/remediation/fix-commands.js +59 -5
  53. package/dist/remediation/npm-registry.js +55 -43
  54. package/dist/remediation/npm-transitive-resolution.js +2 -2
  55. package/dist/remediation/transitive-chain-resolver.js +100 -0
  56. package/dist/scan/multi-folder-scan.js +37 -1
  57. package/dist/scanner.js +122 -46
  58. package/dist/types.js +13 -1
  59. package/dist/utils/baseline.js +16 -0
  60. package/dist/utils/create-pr.js +19 -4
  61. package/dist/utils/fix-runner.js +6 -0
  62. package/dist/utils/package-json.js +21 -0
  63. package/dist/utils/severity.js +16 -0
  64. package/dist/utils/string.js +34 -0
  65. package/dist/utils/validate-url.js +223 -0
  66. package/dist/utils/version.js +135 -2
  67. package/package.json +8 -2
  68. package/dist/learn/keypress.js +0 -50
  69. package/dist/learn/runner.js +0 -96
  70. package/dist/learn/scenario.js +0 -47
  71. package/dist/learn/session.js +0 -36
  72. package/dist/learn/types.js +0 -1
  73. package/dist/llm/client.js +0 -40
  74. package/dist/llm/config.js +0 -48
  75. package/dist/llm/explainer.js +0 -31
  76. package/dist/output/logo-base64.js +0 -1
  77. package/dist/output/owasp-logo-base64.js +0 -1
@@ -3,7 +3,7 @@ import path from "node:path";
3
3
  import { getRecommendedAction } from "./formatters.js";
4
4
  import { getCliVersion } from "../utils/version-info.js";
5
5
  import { severityToSarifLevel } from "../utils/severity.js";
6
- const SARIF_RULE_NAME = "VulnerableDependency";
6
+ import { buildOverrideSarifComponent, buildOverrideSarifResults } from "./override-findings-sarif.js";
7
7
  const LOCKFILE_NAMES = {
8
8
  "package-lock": "package-lock.json",
9
9
  "npm-shrinkwrap": "npm-shrinkwrap.json",
@@ -13,12 +13,67 @@ const LOCKFILE_NAMES = {
13
13
  "package-json": "package.json",
14
14
  "unknown": "lockfile",
15
15
  };
16
+ function findVulnForRuleId(ruleId, vulns) {
17
+ return vulns.find(v => v.id === ruleId || v.aliases?.includes(ruleId));
18
+ }
19
+ function extractAffectedRange(vuln) {
20
+ for (const entry of vuln.affected ?? []) {
21
+ for (const range of entry.ranges ?? []) {
22
+ if (range.type !== "SEMVER")
23
+ continue;
24
+ const fixedEvent = (range.events ?? []).find(e => e.fixed !== undefined);
25
+ if (fixedEvent?.fixed) {
26
+ return { affected: `< ${fixedEvent.fixed}`, patched: fixedEvent.fixed };
27
+ }
28
+ }
29
+ }
30
+ return null;
31
+ }
32
+ function buildRuleHelp(vuln, depPath, action) {
33
+ const title = vuln.summary ?? vuln.id;
34
+ const body = vuln.details && vuln.details !== vuln.summary ? vuln.details : null;
35
+ const cvssEntry = (vuln.severity ?? []).find(s => s.type?.startsWith("CVSS"));
36
+ const cvssScore = cvssEntry?.score ?? null;
37
+ const dbSpecific = vuln.database_specific;
38
+ const rawCweIds = dbSpecific?.cwe_ids;
39
+ const cweIds = Array.isArray(rawCweIds) ? rawCweIds : null;
40
+ const range = extractAffectedRange(vuln);
41
+ const textParts = [`Vulnerability: ${title}`];
42
+ if (body)
43
+ textParts.push("", body);
44
+ if (cvssScore)
45
+ textParts.push("", `CVSS: ${cvssScore}`);
46
+ if (cweIds?.length)
47
+ textParts.push(`CWE: ${cweIds.join(", ")}`);
48
+ if (range) {
49
+ textParts.push(`Affected: ${range.affected}`);
50
+ textParts.push(`Patched: ${range.patched}`);
51
+ }
52
+ if (depPath)
53
+ textParts.push("", `Dependency path: ${depPath}`);
54
+ textParts.push("", `Fix: ${action}`);
55
+ const mdParts = [`## ${title}`];
56
+ if (body)
57
+ mdParts.push("", body);
58
+ if (cvssScore)
59
+ mdParts.push("", `**CVSS:** \`${cvssScore}\``);
60
+ if (cweIds?.length)
61
+ mdParts.push(`**CWE:** ${cweIds.join(", ")}`);
62
+ if (range) {
63
+ mdParts.push(`**Affected versions:** ${range.affected}`);
64
+ mdParts.push(`**Patched version:** ${range.patched}`);
65
+ }
66
+ if (depPath)
67
+ mdParts.push("", `**Dependency path:** ${depPath}`);
68
+ mdParts.push("", "## Fix", "", action);
69
+ return { text: textParts.join("\n"), markdown: mdParts.join("\n") };
70
+ }
16
71
  export function deriveLockfileUri(scanInput) {
17
72
  if (scanInput.filePath)
18
73
  return path.basename(scanInput.filePath);
19
74
  return LOCKFILE_NAMES[scanInput.source] ?? "lockfile";
20
75
  }
21
- export function buildSarifOutput(findings, lockfileUri, version, _plan) {
76
+ export function buildSarifOutput(findings, lockfileUri, version, _plan, overrideFindings) {
22
77
  const ruleMap = new Map();
23
78
  const results = [];
24
79
  for (const finding of findings) {
@@ -35,11 +90,17 @@ export function buildSarifOutput(findings, lockfileUri, version, _plan) {
35
90
  : finding.vulnerabilities.map(v => v.id);
36
91
  for (const ruleId of ruleIds) {
37
92
  if (!ruleMap.has(ruleId)) {
93
+ const vuln = findVulnForRuleId(ruleId, finding.vulnerabilities);
94
+ const summary = vuln?.summary;
95
+ const details = vuln?.details;
96
+ const depPath = finding.pkg.paths?.[0]?.join(" → ") ?? "";
97
+ const help = vuln ? buildRuleHelp(vuln, depPath, action) : undefined;
38
98
  ruleMap.set(ruleId, {
39
99
  id: ruleId,
40
- name: SARIF_RULE_NAME,
41
- shortDescription: { text: ruleId },
42
- fullDescription: { text: `Vulnerable dependency: ${ruleId}` },
100
+ name: summary ?? ruleId,
101
+ shortDescription: { text: summary ?? ruleId },
102
+ fullDescription: { text: details ?? summary ?? `Vulnerable dependency: ${ruleId}` },
103
+ ...(help !== undefined ? { help } : {}),
43
104
  helpUri: `https://osv.dev/vulnerability/${ruleId}`,
44
105
  defaultConfiguration: { level },
45
106
  properties: { tags: ["security", "dependency"] },
@@ -55,6 +116,13 @@ export function buildSarifOutput(findings, lockfileUri, version, _plan) {
55
116
  });
56
117
  }
57
118
  }
119
+ const extensions = overrideFindings && overrideFindings.length > 0
120
+ ? [buildOverrideSarifComponent()]
121
+ : undefined;
122
+ const allResults = [
123
+ ...results,
124
+ ...(overrideFindings ? buildOverrideSarifResults(overrideFindings) : []),
125
+ ];
58
126
  return {
59
127
  $schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
60
128
  version: "2.1.0",
@@ -67,8 +135,9 @@ export function buildSarifOutput(findings, lockfileUri, version, _plan) {
67
135
  informationUri: "https://owasp.org/cve-lite-cli/",
68
136
  rules: Array.from(ruleMap.values()),
69
137
  },
138
+ ...(extensions ? { extensions } : {}),
70
139
  },
71
- results,
140
+ results: allResults,
72
141
  artifacts: [
73
142
  { location: { uri: lockfileUri, uriBaseId: "%SRCROOT%" } },
74
143
  ],
@@ -76,11 +145,11 @@ export function buildSarifOutput(findings, lockfileUri, version, _plan) {
76
145
  ],
77
146
  };
78
147
  }
79
- export function writeSarifReport(findings, lockfileUri, plan) {
148
+ export function writeSarifReport(findings, lockfileUri, plan, overrideFindings) {
80
149
  const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
81
150
  const filename = `cve-lite-scan-${ts}.sarif`;
82
151
  const outputPath = path.join(process.cwd(), filename);
83
- const sarif = buildSarifOutput(findings, lockfileUri, getCliVersion(), plan);
152
+ const sarif = buildSarifOutput(findings, lockfileUri, getCliVersion(), plan, overrideFindings);
84
153
  try {
85
154
  fs.writeFileSync(outputPath, JSON.stringify(sarif, null, 2));
86
155
  }
@@ -4,6 +4,7 @@ import { chalk } from "../utils/chalk.js";
4
4
  import { serializeFinding } from "./formatters.js";
5
5
  import { writeSarifReport, deriveLockfileUri } from "./sarif.js";
6
6
  import { writeCycloneDxReport } from "./cyclonedx.js";
7
+ import { overrideFindingsToJson } from "./override-findings-json.js";
7
8
  function readProjectMeta(projectPath) {
8
9
  try {
9
10
  const pkgPath = path.join(projectPath, "package.json");
@@ -27,7 +28,7 @@ export async function writeOutputs(options, scanState, scanInput, projectPath) {
27
28
  const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
28
29
  const jsonFilename = `cve-lite-scan-${ts}.json`;
29
30
  const jsonOutputPath = path.join(process.cwd(), jsonFilename);
30
- fs.writeFileSync(jsonOutputPath, JSON.stringify({
31
+ const payload = {
31
32
  projectPath,
32
33
  mode: scanInput.mode,
33
34
  source: scanInput.source,
@@ -38,12 +39,15 @@ export async function writeOutputs(options, scanState, scanInput, projectPath) {
38
39
  warnings: scanInput.warnings,
39
40
  skippedDependencies: scanInput.skippedDependencies,
40
41
  findings: scanState.sorted.map(finding => serializeFinding(finding, scanState.suggestedFixCommands)),
41
- }, null, 2));
42
+ };
43
+ const overridePayload = overrideFindingsToJson(scanState.overrideFindings ?? []);
44
+ const combined = { ...payload, ...overridePayload };
45
+ fs.writeFileSync(jsonOutputPath, JSON.stringify(combined, null, 2));
42
46
  console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
43
47
  }
44
48
  if (options.sarif) {
45
49
  const lockfileUri = deriveLockfileUri(scanInput);
46
- const sarifFilename = writeSarifReport(scanState.sorted, lockfileUri, scanState.suggestedFixCommands);
50
+ const sarifFilename = writeSarifReport(scanState.sorted, lockfileUri, scanState.suggestedFixCommands, scanState.overrideFindings);
47
51
  console.log(`${chalk.gray("SARIF report written to")} ${chalk.cyan(sarifFilename)}`);
48
52
  }
49
53
  if (options.cdx) {
@@ -0,0 +1,79 @@
1
+ import { ALL_DETECTORS, VERIFY_DETECTORS } from "./detectors/index.js";
2
+ import { applyComposite } from "./composite.js";
3
+ import { fetchDistTagsBatch } from "./parsing/registry.js";
4
+ /**
5
+ * Full audit: run all 8 detectors over the project, apply composite passes,
6
+ * emit oa.detected per finding.
7
+ */
8
+ export async function audit(ctx, opts) {
9
+ // OA007 network fetch - only when opted in.
10
+ if (opts.checkNetwork) {
11
+ const stringOverrideNames = ctx.overrideEntries
12
+ .filter((e) => typeof e.value === "string")
13
+ .map((e) => e.packageName);
14
+ if (stringOverrideNames.length > 0) {
15
+ try {
16
+ const fetched = await fetchDistTagsBatch(stringOverrideNames, opts.registry ?? {});
17
+ for (const [name, tags] of fetched) {
18
+ ctx.registryDistTags.set(name, tags);
19
+ }
20
+ }
21
+ catch (err) {
22
+ ctx.skippedDetectors.push({
23
+ ruleId: "OA007",
24
+ reason: `registry calls failed: ${err instanceof Error ? err.message : String(err)}`,
25
+ });
26
+ }
27
+ }
28
+ }
29
+ const raw = [];
30
+ for (const { detect } of ALL_DETECTORS) {
31
+ raw.push(...detect(ctx));
32
+ }
33
+ const findings = applyComposite(raw);
34
+ for (const f of findings) {
35
+ ctx.auditLog.emit({
36
+ ts: new Date().toISOString(),
37
+ type: "oa.detected",
38
+ schemaVersion: 1,
39
+ ruleId: f.ruleId,
40
+ severity: f.severity,
41
+ package: f.package.name,
42
+ message: f.message,
43
+ location: { file: f.location.file, jsonPath: f.location.jsonPath },
44
+ });
45
+ }
46
+ return { findings };
47
+ }
48
+ /**
49
+ * Post-fix verification: run OA001 and OA008 only, scoped to the just-touched
50
+ * packages. Cheaper than audit() because it skips the other detectors.
51
+ */
52
+ export async function verify(targets, ctx) {
53
+ const targetNames = new Set(targets.map((t) => t.name));
54
+ const raw = [];
55
+ for (const { detect } of VERIFY_DETECTORS) {
56
+ raw.push(...detect(ctx));
57
+ }
58
+ const scoped = raw.filter((f) => targetNames.has(f.package.name));
59
+ if (scoped.length === 0) {
60
+ ctx.auditLog.emit({
61
+ ts: new Date().toISOString(),
62
+ type: "verify.passed",
63
+ schemaVersion: 1,
64
+ targets: targets.map((t) => ({ name: t.name, version: t.version })),
65
+ });
66
+ return { ok: true, findings: [] };
67
+ }
68
+ ctx.auditLog.emit({
69
+ ts: new Date().toISOString(),
70
+ type: "verify.failed",
71
+ schemaVersion: 1,
72
+ failures: scoped.map((f) => ({
73
+ ruleId: f.ruleId,
74
+ package: f.package.name,
75
+ reason: f.message,
76
+ })),
77
+ });
78
+ return { ok: false, findings: scoped };
79
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Post-detection composite passes:
3
+ * 1. OA005 wins over OA001 for the same package (OA005 is the more specific framing).
4
+ * 2. OA006 (medium) escalates to high when OA008 also fires for the same target:
5
+ * the parent-coupling risk has materialized as a vulnerable copy on disk.
6
+ */
7
+ export function applyComposite(findings) {
8
+ const oa005Packages = new Set(findings.filter((f) => f.ruleId === "OA005").map((f) => f.package.name));
9
+ const oa008Packages = new Set(findings.filter((f) => f.ruleId === "OA008").map((f) => f.package.name));
10
+ const deduped = findings.filter((f) => !(f.ruleId === "OA001" && oa005Packages.has(f.package.name)));
11
+ return deduped.map((f) => {
12
+ if (f.ruleId === "OA006" &&
13
+ f.severity === "medium" &&
14
+ oa008Packages.has(f.package.name)) {
15
+ return {
16
+ ...f,
17
+ severity: "high",
18
+ message: "Override fights an exact-pinned parent (vulnerable copy on disk; OA008 confirms)",
19
+ };
20
+ }
21
+ return f;
22
+ });
23
+ }
@@ -0,0 +1,150 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { extractOverrideEntries } from "./parsing/package-json.js";
4
+ import { walkInstalledTree } from "./parsing/installed-tree.js";
5
+ import { loadFromPackageLock } from "../parsers/package-lock.js";
6
+ import { loadFromPnpmLock } from "../parsers/pnpm-lock.js";
7
+ import { loadFromYarnLock } from "../parsers/yarn-lock.js";
8
+ import { loadFromBunLock } from "../parsers/bun-lock.js";
9
+ export function buildOverrideContext(projectPath, opts) {
10
+ const pkgJsonPath = join(projectPath, "package.json");
11
+ if (!existsSync(pkgJsonPath)) {
12
+ throw new Error(`buildOverrideContext: no package.json at ${projectPath}`);
13
+ }
14
+ const raw = readFileSync(pkgJsonPath, "utf8");
15
+ const parsed = JSON.parse(raw);
16
+ const overrideEntries = extractOverrideEntries(parsed);
17
+ const packageManager = detectPackageManager(projectPath);
18
+ const readResult = readLockfileNames(projectPath, packageManager);
19
+ const lockfilePackageNames = readResult.kind === "ok" ? readResult.names : new Set();
20
+ const nodeModulesExists = existsSync(join(projectPath, "node_modules"));
21
+ const skipped = [];
22
+ if (lockfilePackageNames.size === 0 && overrideEntries.length > 0) {
23
+ if (readResult.kind === "error") {
24
+ skipped.push({ ruleId: "OA001", reason: `lockfile failed to parse: ${readResult.message}` });
25
+ opts.logger.warn(`Lockfile parse error: ${readResult.message}`);
26
+ }
27
+ else {
28
+ skipped.push({ ruleId: "OA001", reason: "lockfile missing or empty" });
29
+ }
30
+ }
31
+ if (!nodeModulesExists && overrideEntries.length > 0) {
32
+ skipped.push({ ruleId: "OA004", reason: "node_modules missing" });
33
+ skipped.push({ ruleId: "OA006", reason: "node_modules missing" });
34
+ skipped.push({ ruleId: "OA008", reason: "node_modules missing" });
35
+ }
36
+ // installedVersions: top-level node_modules/<name>/package.json reads.
37
+ const installedVersions = new Map();
38
+ if (nodeModulesExists) {
39
+ for (const e of overrideEntries) {
40
+ const v = readInstalledVersionTopLevel(projectPath, e.packageName);
41
+ if (v)
42
+ installedVersions.set(e.packageName, v);
43
+ if (typeof e.value === "object" && e.value) {
44
+ for (const innerKey of Object.keys(e.value)) {
45
+ const iv = readInstalledVersionTopLevel(projectPath, innerKey);
46
+ if (iv)
47
+ installedVersions.set(innerKey, iv);
48
+ }
49
+ }
50
+ }
51
+ }
52
+ const tree = nodeModulesExists
53
+ ? walkInstalledTree(projectPath)
54
+ : { installedCopies: new Map(), parentDeclarations: new Map() };
55
+ // OA007 registry: only when --check-network. Empty otherwise.
56
+ const registryDistTags = new Map();
57
+ return {
58
+ projectPath,
59
+ packageJson: parsed,
60
+ packageJsonRaw: raw,
61
+ packageManager,
62
+ overrideEntries,
63
+ lockfilePackageNames,
64
+ installedVersions,
65
+ installedCopies: tree.installedCopies,
66
+ parentDeclarations: tree.parentDeclarations,
67
+ registryDistTags,
68
+ skippedDetectors: skipped,
69
+ auditLog: opts.auditLog,
70
+ logger: opts.logger,
71
+ };
72
+ }
73
+ function detectPackageManager(projectPath) {
74
+ if (existsSync(join(projectPath, "pnpm-lock.yaml")))
75
+ return "pnpm";
76
+ if (existsSync(join(projectPath, "yarn.lock")))
77
+ return "yarn";
78
+ if (existsSync(join(projectPath, "bun.lock")))
79
+ return "bun";
80
+ if (existsSync(join(projectPath, "package-lock.json")))
81
+ return "npm";
82
+ return "unknown";
83
+ }
84
+ function readLockfileNames(projectPath, pm) {
85
+ if (pm === "npm") {
86
+ const lockPath = join(projectPath, "package-lock.json");
87
+ if (!existsSync(lockPath))
88
+ return { kind: "absent" };
89
+ try {
90
+ const refs = loadFromPackageLock(lockPath, false);
91
+ return { kind: "ok", names: new Set(refs.map((r) => r.name)) };
92
+ }
93
+ catch (e) {
94
+ const message = e instanceof Error ? e.message : String(e);
95
+ return { kind: "error", message: `package-lock.json: ${message}` };
96
+ }
97
+ }
98
+ if (pm === "pnpm") {
99
+ const lockPath = join(projectPath, "pnpm-lock.yaml");
100
+ if (!existsSync(lockPath))
101
+ return { kind: "absent" };
102
+ try {
103
+ const refs = loadFromPnpmLock(lockPath, false);
104
+ return { kind: "ok", names: new Set(refs.map((r) => r.name)) };
105
+ }
106
+ catch (e) {
107
+ const message = e instanceof Error ? e.message : String(e);
108
+ return { kind: "error", message: `pnpm-lock.yaml: ${message}` };
109
+ }
110
+ }
111
+ if (pm === "yarn") {
112
+ const lockPath = join(projectPath, "yarn.lock");
113
+ if (!existsSync(lockPath))
114
+ return { kind: "absent" };
115
+ try {
116
+ const refs = loadFromYarnLock(lockPath);
117
+ return { kind: "ok", names: new Set(refs.map((r) => r.name)) };
118
+ }
119
+ catch (e) {
120
+ const message = e instanceof Error ? e.message : String(e);
121
+ return { kind: "error", message: `yarn.lock: ${message}` };
122
+ }
123
+ }
124
+ if (pm === "bun") {
125
+ const lockPath = join(projectPath, "bun.lock");
126
+ if (!existsSync(lockPath))
127
+ return { kind: "absent" };
128
+ try {
129
+ const refs = loadFromBunLock(lockPath, false);
130
+ return { kind: "ok", names: new Set(refs.map((r) => r.name)) };
131
+ }
132
+ catch (e) {
133
+ const message = e instanceof Error ? e.message : String(e);
134
+ return { kind: "error", message: `bun.lock: ${message}` };
135
+ }
136
+ }
137
+ return { kind: "absent" };
138
+ }
139
+ function readInstalledVersionTopLevel(projectPath, name) {
140
+ const p = join(projectPath, "node_modules", ...name.split("/"), "package.json");
141
+ try {
142
+ if (!existsSync(p))
143
+ return null;
144
+ const j = JSON.parse(readFileSync(p, "utf8"));
145
+ return typeof j.version === "string" ? j.version : null;
146
+ }
147
+ catch {
148
+ return null;
149
+ }
150
+ }
@@ -0,0 +1,3 @@
1
+ // Single context object built once per scan/audit and consumed by every
2
+ // detector. Filled by buildOverrideContext() from cve-lite's parser outputs.
3
+ export {};
@@ -0,0 +1,23 @@
1
+ import { detect as detectOA001 } from "./oa001-orphaned-target.js";
2
+ import { detect as detectOA002 } from "./oa002-floating-tag.js";
3
+ import { detect as detectOA003 } from "./oa003-wrong-section.js";
4
+ import { detect as detectOA004 } from "./oa004-surpassed-pin.js";
5
+ import { detect as detectOA005 } from "./oa005-nested-ineffective.js";
6
+ import { detect as detectOA006 } from "./oa006-coupled-platform-binary.js";
7
+ import { detect as detectOA007 } from "./oa007-frozen-latest.js";
8
+ import { detect as detectOA008 } from "./oa008-materialized.js";
9
+ export const ALL_DETECTORS = [
10
+ { ruleId: "OA001", detect: detectOA001 },
11
+ { ruleId: "OA002", detect: detectOA002 },
12
+ { ruleId: "OA003", detect: detectOA003 },
13
+ { ruleId: "OA004", detect: detectOA004 },
14
+ { ruleId: "OA005", detect: detectOA005 },
15
+ { ruleId: "OA006", detect: detectOA006 },
16
+ { ruleId: "OA007", detect: detectOA007 },
17
+ { ruleId: "OA008", detect: detectOA008 },
18
+ ];
19
+ /** Verify subset - just OA001 and OA008 - for the post-fix verify path. */
20
+ export const VERIFY_DETECTORS = [
21
+ { ruleId: "OA001", detect: detectOA001 },
22
+ { ruleId: "OA008", detect: detectOA008 },
23
+ ];
@@ -0,0 +1,36 @@
1
+ import { jsonPointer } from "../parsing/json-pointer.js";
2
+ const RULE_ID = "OA001";
3
+ export function detect(ctx) {
4
+ if (ctx.skippedDetectors.some((s) => s.ruleId === RULE_ID))
5
+ return [];
6
+ if (ctx.lockfilePackageNames.size === 0)
7
+ return [];
8
+ const findings = [];
9
+ for (const entry of ctx.overrideEntries) {
10
+ // pnpm selective `parent>child` keys are nested overrides, not simple
11
+ // orphan candidates. OA005 owns the "is this nested override sensible"
12
+ // question; OA001 stays out of pnpm nested syntax (see #14/#15).
13
+ if (entry.parentScope !== undefined)
14
+ continue;
15
+ if (ctx.lockfilePackageNames.has(entry.packageName))
16
+ continue;
17
+ findings.push({
18
+ ruleId: RULE_ID,
19
+ severity: "high",
20
+ package: { name: entry.packageName },
21
+ location: { file: "package.json", jsonPath: jsonPointer(entry.path) },
22
+ message: "Override target not in resolved tree",
23
+ details: `${entry.packageName} is declared in ${entry.container} but no package depends on it. ` +
24
+ `The override has no effect.`,
25
+ fix: {
26
+ type: "rfc6902",
27
+ patch: [{ op: "remove", path: jsonPointer(entry.path) }],
28
+ runnableCommand: `cve-lite overrides --fix --rule OA001`,
29
+ },
30
+ references: [
31
+ "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA001.md",
32
+ ],
33
+ });
34
+ }
35
+ return findings;
36
+ }
@@ -0,0 +1,40 @@
1
+ import { jsonPointer } from "../parsing/json-pointer.js";
2
+ import { isValidRange } from "../../utils/version.js";
3
+ const RULE_ID = "OA002";
4
+ const FLOATING = new Set(['latest', 'next', '*', 'x', '']);
5
+ export function detect(ctx) {
6
+ if (ctx.skippedDetectors.some(s => s.ruleId === RULE_ID))
7
+ return [];
8
+ const findings = [];
9
+ for (const entry of ctx.overrideEntries) {
10
+ if (typeof entry.value !== 'string')
11
+ continue; // OA005 handles nested objects
12
+ const v = entry.value.trim();
13
+ if (v.startsWith('workspace:') || v.startsWith('file:') || v.startsWith('link:') || v.startsWith('npm:'))
14
+ continue;
15
+ const isFloating = FLOATING.has(v.toLowerCase());
16
+ const isInvalidRange = !isFloating && !isValidRange(v);
17
+ if (!isFloating && !isInvalidRange)
18
+ continue;
19
+ const installed = ctx.installedVersions.get(entry.packageName);
20
+ const floor = installed ? `>=${installed}` : null;
21
+ const finding = {
22
+ ruleId: RULE_ID,
23
+ severity: 'medium',
24
+ package: { name: entry.packageName },
25
+ location: { file: 'package.json', jsonPath: jsonPointer(entry.path) },
26
+ message: 'Override pinned to floating tag',
27
+ details: `${entry.packageName} is pinned to "${v}" - every install may re-resolve the version, defeating the override.`,
28
+ references: ['https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA002.md'],
29
+ };
30
+ if (floor) {
31
+ finding.fix = {
32
+ type: 'rfc6902',
33
+ patch: [{ op: 'replace', path: jsonPointer(entry.path), value: floor }],
34
+ runnableCommand: `cve-lite overrides --fix --rule OA002`,
35
+ };
36
+ }
37
+ findings.push(finding);
38
+ }
39
+ return findings;
40
+ }
@@ -0,0 +1,48 @@
1
+ import { jsonPointer } from "../parsing/json-pointer.js";
2
+ const RULE_ID = "OA003";
3
+ const EXPECTED_CONTAINER = {
4
+ npm: "overrides",
5
+ pnpm: "pnpm.overrides",
6
+ yarn: "resolutions",
7
+ bun: "overrides",
8
+ };
9
+ const EXPECTED_PATH_PREFIX = {
10
+ npm: ["overrides"],
11
+ pnpm: ["pnpm", "overrides"],
12
+ yarn: ["resolutions"],
13
+ bun: ["overrides"],
14
+ };
15
+ export function detect(ctx) {
16
+ const expected = EXPECTED_CONTAINER[ctx.packageManager];
17
+ const expectedPath = EXPECTED_PATH_PREFIX[ctx.packageManager];
18
+ if (!expected || !expectedPath)
19
+ return [];
20
+ const findings = [];
21
+ for (const entry of ctx.overrideEntries) {
22
+ if (entry.container === expected)
23
+ continue;
24
+ const destination = [...expectedPath, entry.key];
25
+ findings.push({
26
+ ruleId: RULE_ID,
27
+ severity: "high",
28
+ package: { name: entry.packageName },
29
+ location: { file: "package.json", jsonPath: jsonPointer(entry.path) },
30
+ message: "Override declared in wrong package-manager section",
31
+ details: `Project uses ${ctx.packageManager}, but override "${entry.key}" lives in ${entry.container}. ` +
32
+ `${ctx.packageManager} silently ignores this section - the override has no effect.`,
33
+ fix: {
34
+ type: "rfc6902",
35
+ patch: [{
36
+ op: "move",
37
+ from: jsonPointer(entry.path),
38
+ path: jsonPointer(destination),
39
+ }],
40
+ runnableCommand: `cve-lite overrides --fix --rule OA003`,
41
+ },
42
+ references: [
43
+ "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA003.md",
44
+ ],
45
+ });
46
+ }
47
+ return findings;
48
+ }
@@ -0,0 +1,49 @@
1
+ import { jsonPointer } from "../parsing/json-pointer.js";
2
+ import { compareVersions, looksLikeVersion, majorVersion } from "../../utils/version.js";
3
+ const RULE_ID = "OA004";
4
+ export function detect(ctx) {
5
+ if (ctx.skippedDetectors.some((s) => s.ruleId === RULE_ID))
6
+ return [];
7
+ const findings = [];
8
+ for (const entry of ctx.overrideEntries) {
9
+ if (typeof entry.value !== "string")
10
+ continue; // OA005 handles nested
11
+ const pin = entry.value.trim();
12
+ // Concrete version only - not a range, not a floating tag.
13
+ if (!looksLikeVersion(pin))
14
+ continue;
15
+ const installed = ctx.installedVersions.get(entry.packageName);
16
+ if (!installed)
17
+ continue;
18
+ if (!looksLikeVersion(installed))
19
+ continue;
20
+ if (!(compareVersions(installed, pin) > 0))
21
+ continue;
22
+ // Safety heuristic for v1: same major -> safe remove; otherwise suggest.
23
+ // Fuller "parent depends on >=pin" check deferred (Spec 12.1).
24
+ const installedMajor = majorVersion(installed);
25
+ const pinMajor = majorVersion(pin);
26
+ const safe = installedMajor !== null && pinMajor !== null && installedMajor === pinMajor;
27
+ const finding = {
28
+ ruleId: RULE_ID,
29
+ severity: "low",
30
+ package: { name: entry.packageName },
31
+ location: { file: "package.json", jsonPath: jsonPointer(entry.path) },
32
+ message: "Installed version surpasses concrete pin",
33
+ details: `${entry.packageName} is pinned to ${pin}; node_modules has ${installed}. ` +
34
+ `The override no longer raises the floor.`,
35
+ references: [
36
+ "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA004.md",
37
+ ],
38
+ };
39
+ if (safe) {
40
+ finding.fix = {
41
+ type: "rfc6902",
42
+ patch: [{ op: "remove", path: jsonPointer(entry.path) }],
43
+ runnableCommand: `cve-lite overrides --fix --rule OA004`,
44
+ };
45
+ }
46
+ findings.push(finding);
47
+ }
48
+ return findings;
49
+ }