cve-lite-cli 1.23.1 → 1.25.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.
- package/README.md +56 -0
- package/dist/audit-log/events.js +3 -0
- package/dist/audit-log/handle.js +20 -0
- package/dist/audit-log/index.js +16 -0
- package/dist/audit-log/ndjson-writer.js +28 -0
- package/dist/cli/args.js +71 -3
- package/dist/cli/fix-overrides-hook.js +64 -0
- package/dist/cli/help.js +22 -0
- package/dist/cli/overrides.js +67 -0
- package/dist/index.js +270 -12
- package/dist/osv/cache.js +23 -3
- package/dist/output/formatters.js +23 -4
- package/dist/output/html-reporter.js +34 -4
- package/dist/output/override-findings-html.js +57 -0
- package/dist/output/override-findings-json.js +3 -0
- package/dist/output/override-findings-sarif.js +52 -0
- package/dist/output/override-findings-terminal.js +37 -0
- package/dist/output/printers.js +25 -8
- package/dist/output/sarif.js +77 -8
- package/dist/output/write-outputs.js +7 -3
- package/dist/overrides/api.js +79 -0
- package/dist/overrides/composite.js +23 -0
- package/dist/overrides/context-builder.js +150 -0
- package/dist/overrides/context.js +3 -0
- package/dist/overrides/detectors/index.js +23 -0
- package/dist/overrides/detectors/oa001-orphaned-target.js +36 -0
- package/dist/overrides/detectors/oa002-floating-tag.js +40 -0
- package/dist/overrides/detectors/oa003-wrong-section.js +48 -0
- package/dist/overrides/detectors/oa004-surpassed-pin.js +49 -0
- package/dist/overrides/detectors/oa005-nested-ineffective.js +128 -0
- package/dist/overrides/detectors/oa006-coupled-platform-binary.js +170 -0
- package/dist/overrides/detectors/oa007-frozen-latest.js +69 -0
- package/dist/overrides/detectors/oa008-materialized.js +75 -0
- package/dist/overrides/detectors/platform-binary.js +37 -0
- package/dist/overrides/fixer.js +199 -0
- package/dist/overrides/index.js +5 -0
- package/dist/overrides/parsing/installed-tree.js +164 -0
- package/dist/overrides/parsing/json-pointer.js +8 -0
- package/dist/overrides/parsing/node-modules.js +19 -0
- package/dist/overrides/parsing/package-json.js +139 -0
- package/dist/overrides/parsing/registry.js +66 -0
- package/dist/overrides/types.js +2 -0
- package/dist/parsers/yarn-lock.js +2 -2
- package/dist/remediation/fix-commands.js +110 -29
- package/dist/remediation/npm-registry.js +30 -0
- package/dist/remediation/npm-transitive-resolution.js +2 -2
- package/dist/remediation/transitive-chain-resolver.js +100 -0
- package/dist/scan/multi-folder-scan.js +26 -0
- package/dist/scanner.js +61 -5
- package/dist/types.js +13 -1
- package/dist/utils/baseline.js +16 -0
- package/dist/utils/create-pr.js +19 -4
- package/dist/utils/string.js +34 -0
- package/dist/utils/version.js +115 -0
- package/package.json +4 -2
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function esc(s) {
|
|
2
|
+
return s
|
|
3
|
+
.replace(/&/g, "&")
|
|
4
|
+
.replace(/</g, "<")
|
|
5
|
+
.replace(/>/g, ">")
|
|
6
|
+
.replace(/"/g, """);
|
|
7
|
+
}
|
|
8
|
+
const SEVERITY_ORDER = ["critical", "high", "medium", "low", "info"];
|
|
9
|
+
export function renderOverrideFindingsHtml(findings) {
|
|
10
|
+
// undefined = override hygiene was never requested -> render nothing, so a plain
|
|
11
|
+
// `cve-lite .` report shows no Override hygiene panel at all. An empty array =
|
|
12
|
+
// it ran and found nothing -> render the "no findings" reassurance.
|
|
13
|
+
if (findings === undefined) {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
if (findings.length === 0) {
|
|
17
|
+
return `
|
|
18
|
+
<section class="override-hygiene">
|
|
19
|
+
<h2>Override hygiene</h2>
|
|
20
|
+
<p>No override hygiene findings.</p>
|
|
21
|
+
</section>
|
|
22
|
+
`;
|
|
23
|
+
}
|
|
24
|
+
const grouped = new Map();
|
|
25
|
+
for (const sev of SEVERITY_ORDER)
|
|
26
|
+
grouped.set(sev, []);
|
|
27
|
+
for (const f of findings)
|
|
28
|
+
grouped.get(f.severity)?.push(f);
|
|
29
|
+
const rows = [];
|
|
30
|
+
for (const sev of SEVERITY_ORDER) {
|
|
31
|
+
const bucket = grouped.get(sev) ?? [];
|
|
32
|
+
if (bucket.length === 0)
|
|
33
|
+
continue;
|
|
34
|
+
rows.push(` <tr class="severity-group"><th colspan="4">${esc(sev.toUpperCase())} (${bucket.length})</th></tr>`);
|
|
35
|
+
for (const f of bucket) {
|
|
36
|
+
rows.push(` <tr class="finding ${esc(f.severity)}">` +
|
|
37
|
+
`<td>${esc(f.ruleId)}</td>` +
|
|
38
|
+
`<td>${esc(f.package.name)}</td>` +
|
|
39
|
+
`<td>${esc(f.location.file)}${f.location.jsonPath ? esc(f.location.jsonPath) : ""}</td>` +
|
|
40
|
+
`<td>${esc(f.message)}</td>` +
|
|
41
|
+
`</tr>`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return `
|
|
45
|
+
<section class="override-hygiene">
|
|
46
|
+
<h2>Override hygiene</h2>
|
|
47
|
+
<table>
|
|
48
|
+
<thead>
|
|
49
|
+
<tr><th>Rule</th><th>Package</th><th>Location</th><th>Message</th></tr>
|
|
50
|
+
</thead>
|
|
51
|
+
<tbody>
|
|
52
|
+
${rows.join("\n")}
|
|
53
|
+
</tbody>
|
|
54
|
+
</table>
|
|
55
|
+
</section>
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getCliVersion } from "../utils/version-info.js";
|
|
2
|
+
const OA_RULES = [
|
|
3
|
+
{ id: "OA001", name: "OrphanedTarget", shortDescription: "Override target not in resolved tree", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA001.md" },
|
|
4
|
+
{ id: "OA002", name: "FloatingTag", shortDescription: "Override pins to a moving tag", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA002.md" },
|
|
5
|
+
{ id: "OA003", name: "WrongSection", shortDescription: "Override in unrecognised package-manager section", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA003.md" },
|
|
6
|
+
{ id: "OA004", name: "SurpassedPin", shortDescription: "Installed version surpasses the override pin", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA004.md" },
|
|
7
|
+
{ id: "OA005", name: "NestedIneffective", shortDescription: "Nested override has no effective scope", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA005.md" },
|
|
8
|
+
{ id: "OA006", name: "CoupledPlatformBinary", shortDescription: "Override fights exact-pinned parent", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA006.md" },
|
|
9
|
+
{ id: "OA007", name: "FrozenLatest", shortDescription: "\"latest\" tag has moved", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA007.md" },
|
|
10
|
+
{ id: "OA008", name: "MaterializedVulnerable", shortDescription: "Vulnerable copy still on disk", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA008.md" },
|
|
11
|
+
];
|
|
12
|
+
const SEVERITY_TO_LEVEL = {
|
|
13
|
+
critical: "error",
|
|
14
|
+
high: "error",
|
|
15
|
+
medium: "warning",
|
|
16
|
+
low: "note",
|
|
17
|
+
info: "note",
|
|
18
|
+
};
|
|
19
|
+
export function buildOverrideSarifComponent() {
|
|
20
|
+
return {
|
|
21
|
+
name: "cve-lite-cli-overrides",
|
|
22
|
+
version: getCliVersion(),
|
|
23
|
+
informationUri: "https://github.com/OWASP/cve-lite-cli",
|
|
24
|
+
rules: OA_RULES.map((r) => ({
|
|
25
|
+
id: r.id,
|
|
26
|
+
name: r.name,
|
|
27
|
+
shortDescription: { text: r.shortDescription },
|
|
28
|
+
helpUri: r.helpUri,
|
|
29
|
+
})),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function buildOverrideSarifResults(findings) {
|
|
33
|
+
return findings.map((f) => ({
|
|
34
|
+
ruleId: f.ruleId,
|
|
35
|
+
rule: { id: f.ruleId, toolComponent: { index: 0 } },
|
|
36
|
+
level: SEVERITY_TO_LEVEL[f.severity] ?? "warning",
|
|
37
|
+
message: { text: f.message },
|
|
38
|
+
locations: [
|
|
39
|
+
{
|
|
40
|
+
physicalLocation: {
|
|
41
|
+
artifactLocation: { uri: f.location.file, uriBaseId: "%SRCROOT%" },
|
|
42
|
+
region: { startLine: f.location.line ?? 1 },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
properties: {
|
|
47
|
+
package: f.package.name,
|
|
48
|
+
jsonPath: f.location.jsonPath,
|
|
49
|
+
severity: f.severity,
|
|
50
|
+
},
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const SEVERITY_ORDER = ["critical", "high", "medium", "low", "info"];
|
|
2
|
+
export function renderOverrideFindings(findings) {
|
|
3
|
+
if (findings.length === 0) {
|
|
4
|
+
return "No override hygiene findings.";
|
|
5
|
+
}
|
|
6
|
+
const lines = [];
|
|
7
|
+
lines.push("");
|
|
8
|
+
lines.push("Override hygiene");
|
|
9
|
+
lines.push("================");
|
|
10
|
+
lines.push("");
|
|
11
|
+
const grouped = new Map();
|
|
12
|
+
for (const sev of SEVERITY_ORDER)
|
|
13
|
+
grouped.set(sev, []);
|
|
14
|
+
for (const f of findings) {
|
|
15
|
+
grouped.get(f.severity)?.push(f);
|
|
16
|
+
}
|
|
17
|
+
for (const sev of SEVERITY_ORDER) {
|
|
18
|
+
const bucket = grouped.get(sev) ?? [];
|
|
19
|
+
if (bucket.length === 0)
|
|
20
|
+
continue;
|
|
21
|
+
lines.push(`${sev.toUpperCase()} (${bucket.length})`);
|
|
22
|
+
lines.push("-".repeat(`${sev.toUpperCase()} (${bucket.length})`.length));
|
|
23
|
+
for (const f of bucket) {
|
|
24
|
+
lines.push(` ${f.ruleId} ${f.package.name}`);
|
|
25
|
+
lines.push(` ${f.location.file}${f.location.jsonPath ? `${f.location.jsonPath}` : ""}`);
|
|
26
|
+
lines.push(` ${f.message}`);
|
|
27
|
+
if (f.fix) {
|
|
28
|
+
lines.push(` fix: autofix available (${f.fix.patch.length} op${f.fix.patch.length === 1 ? "" : "s"})`);
|
|
29
|
+
if (f.fix.runnableCommand) {
|
|
30
|
+
lines.push(` run: ${f.fix.runnableCommand}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
lines.push("");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return lines.join("\n");
|
|
37
|
+
}
|
package/dist/output/printers.js
CHANGED
|
@@ -2,7 +2,7 @@ import { chalk, stripAnsi } from "../utils/chalk.js";
|
|
|
2
2
|
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
3
3
|
import { isMajorVersionBump } from "../utils/version.js";
|
|
4
4
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
5
|
-
import { countUniqueAdvisories, formatSeverityLabel, formatRelationshipLabel, formatRelLabel } from "./formatters.js";
|
|
5
|
+
import { countUniqueAdvisories, formatSeverityLabel, formatRelationshipLabel, formatRelLabel, formatFixCommandWithPublishDates, } from "./formatters.js";
|
|
6
6
|
import { pluralize } from "../utils/string.js";
|
|
7
7
|
import { selectFindingsForCompact } from "./finding-display.js";
|
|
8
8
|
import { MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE, MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, MAL_GIT_SOURCE_COMPACT_MESSAGE, MAL_GIT_SOURCE_LEGEND_MESSAGE, MAL_GIT_SOURCE_PINNED_DISPLAY, MAL_GIT_SOURCE_FLOATING_DISPLAY, } from "../constants.js";
|
|
@@ -47,6 +47,20 @@ export function printActionSummary(findings) {
|
|
|
47
47
|
console.log(`- ${chalk.blueBright(String(uniqueAdvisories))} ${pluralize(uniqueAdvisories, "CVE")} matched overall.`);
|
|
48
48
|
console.log(`- ${chalk.blue(String(fixable))} ${pluralize(fixable, "package")} include a fixed-version hint from OSV.`);
|
|
49
49
|
}
|
|
50
|
+
function printChainProofLines(targets) {
|
|
51
|
+
for (const target of targets) {
|
|
52
|
+
if (!target.chainProof || !target.chainSafeVersion)
|
|
53
|
+
continue;
|
|
54
|
+
const pkgLabel = target.chainVulnerablePackage
|
|
55
|
+
? `${target.chainVulnerablePackage}@${target.chainSafeVersion}`
|
|
56
|
+
: target.chainSafeVersion;
|
|
57
|
+
const hops = target.chainProof.map(h => `${h.name}@${h.version}`);
|
|
58
|
+
const proof = hops.length > 0
|
|
59
|
+
? ` resolves via ${hops.join(" -> ")} -> ${pkgLabel} (safe)`
|
|
60
|
+
: ` resolves to ${pkgLabel} (safe)`;
|
|
61
|
+
console.log(chalk.gray(proof));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
50
64
|
export function printSuggestedFixCommands(findings, scanInput, options) {
|
|
51
65
|
const plan = buildSuggestedFixCommandPlan(findings, scanInput, options);
|
|
52
66
|
if (!plan)
|
|
@@ -56,7 +70,7 @@ export function printSuggestedFixCommands(findings, scanInput, options) {
|
|
|
56
70
|
const sharedDirectTableWidths = computeSharedDirectTableWidths(plan.sections);
|
|
57
71
|
const sharedParentUpgradeTableWidths = computeSharedParentUpgradeTableWidths(plan.sections);
|
|
58
72
|
console.log("");
|
|
59
|
-
console.log(chalk.bold.yellow("🛠
|
|
73
|
+
console.log(chalk.bold.yellow("🛠 Suggested Fix Commands"));
|
|
60
74
|
console.log(`${chalk.gray("Detected package manager:")} ${chalk.cyan(plan.packageManager)} ${chalk.gray(`(${plan.sourceLabel})`)}`);
|
|
61
75
|
console.log(chalk.white(formatFixCommandSummary(plan)));
|
|
62
76
|
for (const section of plan.sections) {
|
|
@@ -90,7 +104,8 @@ export function printSuggestedFixCommands(findings, scanInput, options) {
|
|
|
90
104
|
else if (shouldRenderParentUpgradeTable(section.targets)) {
|
|
91
105
|
printParentUpgradeTargetsTable(section.targets, sharedParentUpgradeTableWidths);
|
|
92
106
|
}
|
|
93
|
-
console.log(renderCommandCallout(section.command));
|
|
107
|
+
console.log(renderCommandCallout(section.command, section.targets));
|
|
108
|
+
printChainProofLines(section.targets);
|
|
94
109
|
}
|
|
95
110
|
if (plan.coveredFindingCount > 0) {
|
|
96
111
|
console.log("");
|
|
@@ -356,7 +371,7 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
356
371
|
}
|
|
357
372
|
}
|
|
358
373
|
else if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
359
|
-
console.log(` ${chalk.gray(`Fix:
|
|
374
|
+
console.log(` ${chalk.gray(`Fix: run \`npm install\` - ${finding.recommendedNpmTransitiveRemediation.package} already permits a safe version`)}`);
|
|
360
375
|
}
|
|
361
376
|
else if (finding.recommendedParentUpgrade) {
|
|
362
377
|
console.log(` ${chalk.gray(`Fix: upgrade ${finding.recommendedParentUpgrade.package} to ${finding.recommendedParentUpgrade.targetVersion}`)}`);
|
|
@@ -394,7 +409,7 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
394
409
|
if (plan) {
|
|
395
410
|
if (plan?.sections.length) {
|
|
396
411
|
console.log("────────────────────────────────");
|
|
397
|
-
console.log(chalk.bold.yellow("🛠
|
|
412
|
+
console.log(chalk.bold.yellow("🛠 Suggested Fix Commands"));
|
|
398
413
|
console.log("────────────────────────────────\n");
|
|
399
414
|
console.log(`${chalk.gray("Detected package manager:")} ${chalk.cyan(plan.packageManager)} ${chalk.gray(`(${plan.sourceLabel})`)}`);
|
|
400
415
|
console.log(formatFixCommandSummary(plan));
|
|
@@ -412,7 +427,8 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
412
427
|
console.log(chalk.gray(` Note: ${target.adjustmentNote}`));
|
|
413
428
|
}
|
|
414
429
|
}
|
|
415
|
-
console.log(renderCommandCallout(section.command));
|
|
430
|
+
console.log(renderCommandCallout(section.command, section.targets));
|
|
431
|
+
printChainProofLines(section.targets);
|
|
416
432
|
console.log("");
|
|
417
433
|
}
|
|
418
434
|
}
|
|
@@ -545,8 +561,9 @@ function formatFixCommandSummary(plan) {
|
|
|
545
561
|
const sectionLabel = sectionCount === 1 ? "group" : "groups";
|
|
546
562
|
return `${sectionCount} command ${sectionLabel} ready across ${packageCount} ${packageLabel}${severitySummary ? ` (${severitySummary})` : ""}.`;
|
|
547
563
|
}
|
|
548
|
-
function renderCommandCallout(command) {
|
|
549
|
-
|
|
564
|
+
function renderCommandCallout(command, targets) {
|
|
565
|
+
const display = targets ? formatFixCommandWithPublishDates(command, targets) : command;
|
|
566
|
+
return chalk.bold.cyan(`> ${display}`);
|
|
550
567
|
}
|
|
551
568
|
function summarizeAdjustedValidation(targets) {
|
|
552
569
|
let checked = 0;
|
package/dist/output/sarif.js
CHANGED
|
@@ -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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
+
}
|