cve-lite-cli 1.31.0 → 1.32.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 +17 -15
- package/dist/advisory/npm-advisory-source.js +77 -0
- package/dist/cli/args.js +21 -0
- package/dist/cli/help.js +4 -0
- package/dist/epss/client.js +26 -0
- package/dist/index.js +32 -2
- package/dist/licenses/license-check.js +137 -0
- package/dist/licenses/types.js +1 -0
- package/dist/osv/cache.js +19 -8
- package/dist/output/formatters.js +1 -0
- package/dist/output/html-reporter.js +16 -2
- package/dist/output/license-findings-html.js +63 -0
- package/dist/output/license-findings-json.js +10 -0
- package/dist/output/license-findings-sarif.js +64 -0
- package/dist/output/license-terminal.js +35 -0
- package/dist/output/multi-folder-html-reporter.js +9 -5
- package/dist/output/printers.js +40 -10
- package/dist/output/sarif.js +10 -3
- package/dist/output/write-outputs.js +9 -2
- package/dist/remediation/parent-upgrade.js +8 -1
- package/dist/scan/completeness.js +6 -0
- package/dist/scan/multi-folder-scan.js +41 -6
- package/dist/scanner.js +75 -4
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function esc(s) {
|
|
2
|
+
return s
|
|
3
|
+
.replace(/&/g, "&")
|
|
4
|
+
.replace(/</g, "<")
|
|
5
|
+
.replace(/>/g, ">")
|
|
6
|
+
.replace(/"/g, """);
|
|
7
|
+
}
|
|
8
|
+
export function renderLicenseFindingsHtml(findings, opts) {
|
|
9
|
+
// undefined = license checking was never requested -> render nothing, so a plain
|
|
10
|
+
// `cve-lite .` report shows no License Issues panel at all. An empty array =
|
|
11
|
+
// it ran and found nothing -> render the "no findings" reassurance.
|
|
12
|
+
if (findings === undefined) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
if (findings.length === 0) {
|
|
16
|
+
const note = opts?.limitedToDirectOnly
|
|
17
|
+
? `\n <p style="margin-top:8px;font-size:12px;color:var(--text-2)">Note: license data is not available for transitive packages in pnpm/Yarn/Bun - direct dependencies only.</p>`
|
|
18
|
+
: "";
|
|
19
|
+
return `
|
|
20
|
+
<div class="findings-section">
|
|
21
|
+
<div class="findings-header">
|
|
22
|
+
<div style="display:flex;align-items:center;gap:8px">
|
|
23
|
+
<h2>License Issues</h2>
|
|
24
|
+
<span class="badge-warning">informational</span>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
<p style="color:var(--text-2);font-size:13px">No license issues found.</p>${note}
|
|
28
|
+
</div>`;
|
|
29
|
+
}
|
|
30
|
+
const rows = findings.map(f => ` <tr style="cursor:default">` +
|
|
31
|
+
`<td><span class="sev-badge ${esc(f.severity)}">${esc(f.ruleId)}</span></td>` +
|
|
32
|
+
`<td style="font-weight:500">${esc(f.package.name)}</td>` +
|
|
33
|
+
`<td style="color:var(--text-2)">${esc(f.package.version)}</td>` +
|
|
34
|
+
`<td><code style="font-size:12px;font-family:monospace;color:var(--text)">${esc(f.license ?? "(none)")}</code></td>` +
|
|
35
|
+
`<td><span class="rel-badge ${esc(f.relationship)}">${esc(f.relationship)}</span></td>` +
|
|
36
|
+
`<td style="color:var(--text-2);font-size:12px">${esc(f.message)}</td>` +
|
|
37
|
+
`</tr>`);
|
|
38
|
+
const count = findings.length;
|
|
39
|
+
const note = opts?.limitedToDirectOnly
|
|
40
|
+
? `\n <p style="margin-top:10px;font-size:12px;color:var(--text-2)">Note: license data is not available for transitive packages in pnpm/Yarn/Bun - direct dependencies only.</p>`
|
|
41
|
+
: "";
|
|
42
|
+
return `
|
|
43
|
+
<div class="findings-section">
|
|
44
|
+
<div class="findings-header">
|
|
45
|
+
<div style="display:flex;align-items:center;gap:8px">
|
|
46
|
+
<h2>License Issues</h2>
|
|
47
|
+
<span class="badge-warning">informational</span>
|
|
48
|
+
</div>
|
|
49
|
+
<span style="font-size:12px;color:var(--text-2)">${count} ${count === 1 ? "finding" : "findings"}</span>
|
|
50
|
+
</div>
|
|
51
|
+
<table class="findings-table">
|
|
52
|
+
<thead>
|
|
53
|
+
<tr>
|
|
54
|
+
<th>Rule</th><th>Package</th><th>Version</th><th>License</th><th>Relationship</th><th>Message</th>
|
|
55
|
+
</tr>
|
|
56
|
+
</thead>
|
|
57
|
+
<tbody>
|
|
58
|
+
${rows.join("\n")}
|
|
59
|
+
</tbody>
|
|
60
|
+
</table>${note}
|
|
61
|
+
</div>
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function serializeLicenseFindings(findings) {
|
|
2
|
+
return findings.map(f => ({
|
|
3
|
+
ruleId: f.ruleId,
|
|
4
|
+
severity: f.severity,
|
|
5
|
+
package: { name: f.package.name, version: f.package.version },
|
|
6
|
+
license: f.license,
|
|
7
|
+
relationship: f.relationship,
|
|
8
|
+
message: f.message,
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getCliVersion } from "../utils/version-info.js";
|
|
2
|
+
import { severityToSarifLevel } from "../utils/severity.js";
|
|
3
|
+
import { sarifFingerprintHash } from "../utils/sarif.js";
|
|
4
|
+
const LC_RULES = [
|
|
5
|
+
{
|
|
6
|
+
id: "LC001",
|
|
7
|
+
name: "Copyleft license",
|
|
8
|
+
shortDescription: "Dependency uses a copyleft license that may require open-sourcing your code",
|
|
9
|
+
helpUri: "https://owasp.org/cve-lite-cli/docs/license-scanning/lc001",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
id: "LC002",
|
|
13
|
+
name: "Unknown license",
|
|
14
|
+
shortDescription: "Dependency has no license declaration - legally ambiguous",
|
|
15
|
+
helpUri: "https://owasp.org/cve-lite-cli/docs/license-scanning/lc002",
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
const LC_RULE_INDEX = new Map(LC_RULES.map((r, i) => [r.id, i]));
|
|
19
|
+
export function buildLicenseSarifComponent() {
|
|
20
|
+
return {
|
|
21
|
+
name: "cve-lite-cli-licenses",
|
|
22
|
+
version: getCliVersion(),
|
|
23
|
+
informationUri: "https://github.com/OWASP/cve-lite-cli",
|
|
24
|
+
rules: LC_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 buildLicenseSarifResults(findings, lockfileUri, toolComponentIndex = 0) {
|
|
33
|
+
return findings.map(f => {
|
|
34
|
+
const ruleIndex = LC_RULE_INDEX.get(f.ruleId);
|
|
35
|
+
if (ruleIndex === undefined) {
|
|
36
|
+
throw new Error(`LC_RULE_INDEX: unknown ruleId "${f.ruleId}" - add it to LC_RULES`);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
ruleId: f.ruleId,
|
|
40
|
+
ruleIndex,
|
|
41
|
+
rule: { id: f.ruleId, toolComponent: { index: toolComponentIndex } },
|
|
42
|
+
kind: "open",
|
|
43
|
+
level: severityToSarifLevel(f.severity),
|
|
44
|
+
message: { text: f.message },
|
|
45
|
+
locations: [
|
|
46
|
+
{
|
|
47
|
+
physicalLocation: {
|
|
48
|
+
artifactLocation: { uri: lockfileUri, uriBaseId: "%SRCROOT%" },
|
|
49
|
+
region: { startLine: 1 },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
partialFingerprints: {
|
|
54
|
+
primaryLocationLineHash: sarifFingerprintHash(`${f.ruleId}:${f.package.name}:${f.package.version}`),
|
|
55
|
+
},
|
|
56
|
+
properties: {
|
|
57
|
+
package: f.package.name,
|
|
58
|
+
version: f.package.version,
|
|
59
|
+
license: f.license,
|
|
60
|
+
severity: f.severity,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { chalk } from "../utils/chalk.js";
|
|
2
|
+
import { formatSeverityLabel } from "../utils/severity.js";
|
|
3
|
+
const DIVIDER = "────────────────────────────────";
|
|
4
|
+
export function renderLicenseFindings(findings, opts) {
|
|
5
|
+
const lines = [
|
|
6
|
+
DIVIDER,
|
|
7
|
+
chalk.bold("⚖ License Issues"),
|
|
8
|
+
DIVIDER,
|
|
9
|
+
"",
|
|
10
|
+
];
|
|
11
|
+
if (findings.length === 0) {
|
|
12
|
+
lines.push(chalk.greenBright("✔ No license issues found."));
|
|
13
|
+
return lines.join("\n");
|
|
14
|
+
}
|
|
15
|
+
for (const f of findings) {
|
|
16
|
+
const pkg = `${f.package.name}@${f.package.version}`;
|
|
17
|
+
const sevPad = " ".repeat(Math.max(0, 8 - f.severity.length));
|
|
18
|
+
lines.push(`${formatSeverityLabel(f.severity.toUpperCase())}${sevPad} ${f.ruleId} ${pkg}`);
|
|
19
|
+
lines.push(` ${f.message}`);
|
|
20
|
+
lines.push(` Type: ${f.relationship}`);
|
|
21
|
+
lines.push("");
|
|
22
|
+
}
|
|
23
|
+
const highCount = findings.filter((f) => f.severity === "high").length;
|
|
24
|
+
const medCount = findings.filter((f) => f.severity === "medium").length;
|
|
25
|
+
const parts = [];
|
|
26
|
+
if (highCount > 0)
|
|
27
|
+
parts.push(`${highCount} high`);
|
|
28
|
+
if (medCount > 0)
|
|
29
|
+
parts.push(`${medCount} medium`);
|
|
30
|
+
lines.push(chalk.yellow(`⚖ License scan: ${parts.join(", ")} (informational)`));
|
|
31
|
+
if (opts.limitedToDirectOnly) {
|
|
32
|
+
lines.push(chalk.gray("Note: license data not available for transitive packages in pnpm/Yarn/Bun - direct dependencies only."));
|
|
33
|
+
}
|
|
34
|
+
return lines.join("\n");
|
|
35
|
+
}
|
|
@@ -4,6 +4,7 @@ import { aggregateMultiFolderCompleteness } from "../scan/completeness.js";
|
|
|
4
4
|
import { REPORT_STYLES, escapeHtml, openInBrowser, renderFindingRow, renderFixPlan, renderCompletenessBanner, serializeHtmlFinding, } from "./html-reporter.js";
|
|
5
5
|
import { renderOverrideFindingsHtml } from "./override-findings-html.js";
|
|
6
6
|
import { renderMaintenanceFindingsHtml } from "./maintenance-findings-html.js";
|
|
7
|
+
import { renderLicenseFindingsHtml } from "./license-findings-html.js";
|
|
7
8
|
import { loadLogoDataUri } from "./logos.js";
|
|
8
9
|
import { pluralize } from "../utils/string.js";
|
|
9
10
|
export function buildMultiFolderReportData(params) {
|
|
@@ -45,12 +46,12 @@ function renderFolderNotices(coverage) {
|
|
|
45
46
|
if (coverage.length === 0)
|
|
46
47
|
return "";
|
|
47
48
|
const items = coverage.map(n => `<li>${escapeHtml(n)}</li>`).join("\n");
|
|
48
|
-
return `<div class="scan-notes" style="margin:16px 32px
|
|
49
|
+
return `<div class="scan-notes" style="margin:16px 32px">
|
|
49
50
|
<button class="scan-notes-toggle" onclick="toggleNotes(this)"><span class="arrow">▶</span> Scan notes (${coverage.length})</button>
|
|
50
51
|
<div class="scan-notes-body"><ul>${items}</ul></div>
|
|
51
52
|
</div>`;
|
|
52
53
|
}
|
|
53
|
-
function renderFolderSection(result, folderIdx, idxOffset, serialized, projectRoot, includeOverrides, includeMaintenance) {
|
|
54
|
+
function renderFolderSection(result, folderIdx, idxOffset, serialized, projectRoot, includeOverrides, includeMaintenance, includeLicenses) {
|
|
54
55
|
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0 };
|
|
55
56
|
for (const f of result.sorted) {
|
|
56
57
|
const sev = f.severity;
|
|
@@ -67,7 +68,6 @@ function renderFolderSection(result, folderIdx, idxOffset, serialized, projectRo
|
|
|
67
68
|
const findingRowsHtml = serialized.map((f, i) => renderFindingRow(f, idxOffset + i)).join("\n");
|
|
68
69
|
const fixPlanHtml = renderFixPlan(result.suggestedFixCommands);
|
|
69
70
|
const noticesHtml = renderFolderNotices(result.coverage);
|
|
70
|
-
const completenessBannerHtml = renderCompletenessBanner(result.completeness);
|
|
71
71
|
const folderAbs = path.join(projectRoot, result.subfolder);
|
|
72
72
|
const overrideHtml = includeOverrides
|
|
73
73
|
? renderOverrideFindingsHtml(result.overrideFindings, folderAbs)
|
|
@@ -75,6 +75,9 @@ function renderFolderSection(result, folderIdx, idxOffset, serialized, projectRo
|
|
|
75
75
|
const maintenanceHtml = includeMaintenance
|
|
76
76
|
? renderMaintenanceFindingsHtml(result.maintenanceFindings)
|
|
77
77
|
: "";
|
|
78
|
+
const licenseHtml = includeLicenses
|
|
79
|
+
? renderLicenseFindingsHtml(result.licenseFindings, { limitedToDirectOnly: result.licenseLimitedToDirectOnly })
|
|
80
|
+
: "";
|
|
78
81
|
const emptyRow = result.sorted.length === 0
|
|
79
82
|
? `<tr><td colspan="7" style="text-align:center;padding:24px;color:#8b949e">No findings</td></tr>`
|
|
80
83
|
: "";
|
|
@@ -88,7 +91,6 @@ function renderFolderSection(result, folderIdx, idxOffset, serialized, projectRo
|
|
|
88
91
|
<span class="folder-counts">${escapeHtml(summaryText)}</span>
|
|
89
92
|
</summary>
|
|
90
93
|
<div class="folder-body">
|
|
91
|
-
${completenessBannerHtml}
|
|
92
94
|
${fixPlanHtml}
|
|
93
95
|
${noticesHtml}
|
|
94
96
|
<div class="findings-section" style="margin:16px 32px 32px">
|
|
@@ -125,6 +127,7 @@ function renderFolderSection(result, folderIdx, idxOffset, serialized, projectRo
|
|
|
125
127
|
</div>
|
|
126
128
|
${overrideHtml}
|
|
127
129
|
${maintenanceHtml}
|
|
130
|
+
${licenseHtml}
|
|
128
131
|
</div>
|
|
129
132
|
</details>`;
|
|
130
133
|
}
|
|
@@ -147,6 +150,7 @@ export async function writeMultiFolderHtmlReport(params) {
|
|
|
147
150
|
cliVersion: params.cliVersion,
|
|
148
151
|
includeOverrides: params.includeOverrides,
|
|
149
152
|
includeMaintenance: params.includeMaintenance,
|
|
153
|
+
includeLicenses: params.includeLicenses,
|
|
150
154
|
});
|
|
151
155
|
// Compact per-folder findings for JavaScript (only fields needed for filter/sort/search)
|
|
152
156
|
const folderFindingsJson = JSON.stringify(allSerialized.map(findings => findings.map(f => ({
|
|
@@ -163,7 +167,7 @@ export async function writeMultiFolderHtmlReport(params) {
|
|
|
163
167
|
let idxOffset = 0;
|
|
164
168
|
const folderSectionsHtml = params.results
|
|
165
169
|
.map((r, fi) => {
|
|
166
|
-
const html = renderFolderSection(r, fi, idxOffset, allSerialized[fi], params.projectPath, params.includeOverrides, params.includeMaintenance);
|
|
170
|
+
const html = renderFolderSection(r, fi, idxOffset, allSerialized[fi], params.projectPath, params.includeOverrides, params.includeMaintenance, params.includeLicenses);
|
|
167
171
|
idxOffset += r.sorted.length;
|
|
168
172
|
return html;
|
|
169
173
|
})
|
package/dist/output/printers.js
CHANGED
|
@@ -7,6 +7,7 @@ import { formatSeverityLabel } from "../utils/severity.js";
|
|
|
7
7
|
import { pluralize } from "../utils/string.js";
|
|
8
8
|
import { hasMaliciousAdvisory } from "../utils/vuln.js";
|
|
9
9
|
import { selectFindingsForCompact } from "./finding-display.js";
|
|
10
|
+
import { renderLicenseFindings } from "./license-terminal.js";
|
|
10
11
|
import { getCompletenessImpact } from "../scan/completeness.js";
|
|
11
12
|
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, OVERRIDES_COMMAND, } from "../constants.js";
|
|
12
13
|
export function printSummary(findings, packageCount, scanInput) {
|
|
@@ -193,7 +194,7 @@ export function printSkippedDependencies(skipped) {
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
export function printTable(findings, threshold, skippedKeys) {
|
|
196
|
-
const headers = ["Package", "Version", "Severity", "Type", "Root", "Usage", "Fixed", "IDs"];
|
|
197
|
+
const headers = ["Package", "Version", "Severity", "Type", "Root", "Usage", "Fixed", "EPSS", "IDs"];
|
|
197
198
|
const rawRows = findings.map(f => {
|
|
198
199
|
let usageText = "n/a";
|
|
199
200
|
if (f.usage) {
|
|
@@ -220,6 +221,11 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
220
221
|
else {
|
|
221
222
|
fixedDisplay = chalk.yellow("⚠ no fix");
|
|
222
223
|
}
|
|
224
|
+
let epssDisplay = "-";
|
|
225
|
+
if (f.epssScores && f.epssScores.length > 0) {
|
|
226
|
+
const best = f.epssScores.slice().sort((a, b) => b.epss - a.epss)[0];
|
|
227
|
+
epssDisplay = `${(best.epss * 100).toFixed(1)}%`;
|
|
228
|
+
}
|
|
223
229
|
return [
|
|
224
230
|
f.pkg.name,
|
|
225
231
|
f.pkg.version,
|
|
@@ -228,6 +234,7 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
228
234
|
formatRootDependencySummary(f),
|
|
229
235
|
usageText,
|
|
230
236
|
fixedDisplay,
|
|
237
|
+
epssDisplay,
|
|
231
238
|
f.vulnerabilities.map(v => v.id).join(", ")
|
|
232
239
|
];
|
|
233
240
|
});
|
|
@@ -256,7 +263,8 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
256
263
|
row[4],
|
|
257
264
|
usageDecorated,
|
|
258
265
|
row[6],
|
|
259
|
-
row[7]
|
|
266
|
+
chalk.gray(String(row[7])),
|
|
267
|
+
row[8]
|
|
260
268
|
];
|
|
261
269
|
console.log(renderRow(decorated, widths));
|
|
262
270
|
}
|
|
@@ -433,6 +441,13 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
433
441
|
}
|
|
434
442
|
console.log(`${formatSeverityLabel(sevLabel)} ${chalk.whiteBright(finding.pkg.name)}@${finding.pkg.version}`);
|
|
435
443
|
console.log(` ${typeLabel}${usageContext}`);
|
|
444
|
+
if (finding.epssScores && finding.epssScores.length > 0) {
|
|
445
|
+
const best = finding.epssScores.slice().sort((a, b) => b.epss - a.epss)[0];
|
|
446
|
+
const pct = (best.epss * 100).toFixed(1);
|
|
447
|
+
const top = ((1 - best.percentile) * 100);
|
|
448
|
+
const topStr = top < 0.01 ? "<0.01" : top < 1 ? top.toFixed(2) : top.toFixed(1);
|
|
449
|
+
console.log(` ${chalk.gray(`EPSS: ${pct}% exploitation probability - ${best.cve} (top ${topStr}% of all CVEs)`)}`);
|
|
450
|
+
}
|
|
436
451
|
const isMalicious = hasMaliciousAdvisory(finding.vulnerabilities);
|
|
437
452
|
if (isMalicious) {
|
|
438
453
|
if (finding.maliciousUnverifiable) {
|
|
@@ -511,6 +526,11 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
511
526
|
}
|
|
512
527
|
}
|
|
513
528
|
}
|
|
529
|
+
if (options?.licenseFindings) {
|
|
530
|
+
console.log(renderLicenseFindings(options.licenseFindings, { limitedToDirectOnly: !!options.licenseLimitedToDirectOnly }));
|
|
531
|
+
console.log("");
|
|
532
|
+
console.log("");
|
|
533
|
+
}
|
|
514
534
|
// Summary
|
|
515
535
|
console.log("────────────────────────────────");
|
|
516
536
|
console.log("Summary");
|
|
@@ -545,6 +565,16 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
545
565
|
console.log(`${chalk.cyan(String(direct))} ${chalk.white("direct")}` +
|
|
546
566
|
`${chalk.gray(" · ")}` +
|
|
547
567
|
`${chalk.cyan(String(transitive))} ${chalk.white("transitive")}`);
|
|
568
|
+
if (options?.licenseFindings && options.licenseFindings.length > 0) {
|
|
569
|
+
const lHigh = options.licenseFindings.filter(f => f.severity === "high").length;
|
|
570
|
+
const lMed = options.licenseFindings.filter(f => f.severity === "medium").length;
|
|
571
|
+
const lParts = [];
|
|
572
|
+
if (lHigh > 0)
|
|
573
|
+
lParts.push(chalk.red(`${lHigh} high`));
|
|
574
|
+
if (lMed > 0)
|
|
575
|
+
lParts.push(chalk.yellow(`${lMed} medium`));
|
|
576
|
+
console.log(chalk.gray("⚖ Licenses: ") + lParts.join(chalk.gray(" · ")) + chalk.gray(" (informational)"));
|
|
577
|
+
}
|
|
548
578
|
const maliciousCompact = findings.filter(f => hasMaliciousAdvisory(f.vulnerabilities));
|
|
549
579
|
if (maliciousCompact.length > 0 && !options?.all) {
|
|
550
580
|
console.log("");
|
|
@@ -585,13 +615,13 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
585
615
|
else {
|
|
586
616
|
console.log(chalk.yellow(`▲ Scan complete. ${findings.length} ${pluralize(findings.length, "issue")} found.`));
|
|
587
617
|
}
|
|
588
|
-
|
|
589
|
-
console.log(chalk.gray(`Run with ${chalk.whiteBright("--verbose")} for fix plan, paths, and full table.`));
|
|
590
|
-
}
|
|
618
|
+
printIncompleteDiagnostics(options?.completeness);
|
|
591
619
|
if (hasRemediationGap) {
|
|
592
620
|
console.log(chalk.yellow("⚠ Remediation guidance is incomplete."));
|
|
593
621
|
}
|
|
594
|
-
|
|
622
|
+
if (!options?.all) {
|
|
623
|
+
console.log(chalk.gray(`Run with ${chalk.whiteBright("--verbose")} for fix plan, paths, and full table.`));
|
|
624
|
+
}
|
|
595
625
|
if (options?.completeness?.complete !== false) {
|
|
596
626
|
console.log("");
|
|
597
627
|
}
|
|
@@ -599,12 +629,12 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
599
629
|
export function printIncompleteDiagnostics(completeness) {
|
|
600
630
|
if (!completeness || completeness.complete)
|
|
601
631
|
return;
|
|
602
|
-
console.log("");
|
|
603
632
|
for (const diag of completeness.diagnostics) {
|
|
604
|
-
const
|
|
605
|
-
console.log(
|
|
633
|
+
const color = diag.impact === "detection" ? chalk.yellow : chalk.gray;
|
|
634
|
+
console.log(color(`⚠ ${diag.message}`));
|
|
606
635
|
}
|
|
607
|
-
console.log(
|
|
636
|
+
console.log("");
|
|
637
|
+
console.log(chalk.gray("Resolve the issues above and re-run the scan."));
|
|
608
638
|
}
|
|
609
639
|
function renderSeverityTable(counts) {
|
|
610
640
|
const labels = ["Critical", "High", "Medium", "Low", "Unknown"];
|
package/dist/output/sarif.js
CHANGED
|
@@ -7,6 +7,7 @@ import { severityToSarifLevel } from "../utils/severity.js";
|
|
|
7
7
|
import { sarifFingerprintHash } from "../utils/sarif.js";
|
|
8
8
|
import { buildOverrideSarifComponent, buildOverrideSarifResults } from "./override-findings-sarif.js";
|
|
9
9
|
import { buildMaintenanceSarifComponent, buildMaintenanceSarifResults } from "./maintenance-findings-sarif.js";
|
|
10
|
+
import { buildLicenseSarifComponent, buildLicenseSarifResults } from "./license-findings-sarif.js";
|
|
10
11
|
const SARIF_SCHEMA = "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json";
|
|
11
12
|
const LOCKFILE_NAMES = {
|
|
12
13
|
"package-lock": "package-lock.json",
|
|
@@ -77,7 +78,7 @@ export function deriveLockfileUri(scanInput) {
|
|
|
77
78
|
return path.basename(scanInput.filePath);
|
|
78
79
|
return LOCKFILE_NAMES[scanInput.source] ?? "lockfile";
|
|
79
80
|
}
|
|
80
|
-
export function buildSarifOutput(findings, lockfileUri, version, plan, overrideFindings, maintenanceFindings) {
|
|
81
|
+
export function buildSarifOutput(findings, lockfileUri, version, plan, overrideFindings, maintenanceFindings, licenseFindings) {
|
|
81
82
|
const ruleMap = new Map();
|
|
82
83
|
const ruleIndexMap = new Map();
|
|
83
84
|
const results = [];
|
|
@@ -135,17 +136,23 @@ export function buildSarifOutput(findings, lockfileUri, version, plan, overrideF
|
|
|
135
136
|
}
|
|
136
137
|
const hasOverrides = overrideFindings != null && overrideFindings.length > 0;
|
|
137
138
|
const hasMaintenance = maintenanceFindings != null && maintenanceFindings.length > 0;
|
|
139
|
+
const hasLicense = licenseFindings != null && licenseFindings.length > 0;
|
|
138
140
|
const extensions = [
|
|
139
141
|
...(hasOverrides ? [buildOverrideSarifComponent()] : []),
|
|
140
142
|
...(hasMaintenance ? [buildMaintenanceSarifComponent()] : []),
|
|
143
|
+
...(hasLicense ? [buildLicenseSarifComponent()] : []),
|
|
141
144
|
];
|
|
142
145
|
const maintenanceExtensionIndex = hasOverrides ? 1 : 0;
|
|
146
|
+
const licenseExtensionIndex = (hasOverrides ? 1 : 0) + (hasMaintenance ? 1 : 0);
|
|
143
147
|
const allResults = [
|
|
144
148
|
...results,
|
|
145
149
|
...(hasOverrides ? buildOverrideSarifResults(overrideFindings) : []),
|
|
146
150
|
...(hasMaintenance
|
|
147
151
|
? buildMaintenanceSarifResults(maintenanceFindings, lockfileUri, maintenanceExtensionIndex)
|
|
148
152
|
: []),
|
|
153
|
+
...(hasLicense
|
|
154
|
+
? buildLicenseSarifResults(licenseFindings, lockfileUri, licenseExtensionIndex)
|
|
155
|
+
: []),
|
|
149
156
|
];
|
|
150
157
|
return {
|
|
151
158
|
$schema: SARIF_SCHEMA,
|
|
@@ -169,11 +176,11 @@ export function buildSarifOutput(findings, lockfileUri, version, plan, overrideF
|
|
|
169
176
|
],
|
|
170
177
|
};
|
|
171
178
|
}
|
|
172
|
-
export function writeSarifReport(findings, lockfileUri, plan, overrideFindings, maintenanceFindings) {
|
|
179
|
+
export function writeSarifReport(findings, lockfileUri, plan, overrideFindings, maintenanceFindings, licenseFindings) {
|
|
173
180
|
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
174
181
|
const filename = `cve-lite-scan-${ts}.sarif`;
|
|
175
182
|
const outputPath = path.join(process.cwd(), filename);
|
|
176
|
-
const sarif = buildSarifOutput(findings, lockfileUri, getCliVersion(), plan, overrideFindings, maintenanceFindings);
|
|
183
|
+
const sarif = buildSarifOutput(findings, lockfileUri, getCliVersion(), plan, overrideFindings, maintenanceFindings, licenseFindings);
|
|
177
184
|
try {
|
|
178
185
|
fs.writeFileSync(outputPath, JSON.stringify(sarif, null, 2));
|
|
179
186
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { chalk } from "../utils/chalk.js";
|
|
4
|
+
import { serializeLicenseFindings } from "./license-findings-json.js";
|
|
4
5
|
import { serializeFinding } from "./formatters.js";
|
|
5
6
|
import { writeSarifReport, deriveLockfileUri } from "./sarif.js";
|
|
6
7
|
import { writeCycloneDxReport } from "./cyclonedx.js";
|
|
@@ -46,13 +47,19 @@ export async function writeOutputs(options, scanState, scanInput, projectPath) {
|
|
|
46
47
|
};
|
|
47
48
|
const overridePayload = overrideFindingsToJson(scanState.overrideFindings ?? []);
|
|
48
49
|
const maintenancePayload = maintenanceFindingsToJson(scanState.maintenanceFindings ?? []);
|
|
49
|
-
const
|
|
50
|
+
const licensePayload = scanState.licenseFindings && scanState.licenseFindings.length > 0
|
|
51
|
+
? {
|
|
52
|
+
licenseFindings: serializeLicenseFindings(scanState.licenseFindings),
|
|
53
|
+
...(scanState.licenseLimitedToDirectOnly ? { licenseLimitedToDirectOnly: true } : {}),
|
|
54
|
+
}
|
|
55
|
+
: {};
|
|
56
|
+
const combined = { ...payload, ...overridePayload, ...maintenancePayload, ...licensePayload };
|
|
50
57
|
fs.writeFileSync(jsonOutputPath, JSON.stringify(combined, null, 2));
|
|
51
58
|
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
|
|
52
59
|
}
|
|
53
60
|
if (options.sarif) {
|
|
54
61
|
const lockfileUri = deriveLockfileUri(scanInput);
|
|
55
|
-
const sarifFilename = writeSarifReport(scanState.sorted, lockfileUri, scanState.suggestedFixCommands, scanState.overrideFindings, scanState.maintenanceFindings);
|
|
62
|
+
const sarifFilename = writeSarifReport(scanState.sorted, lockfileUri, scanState.suggestedFixCommands, scanState.overrideFindings, scanState.maintenanceFindings, scanState.licenseFindings);
|
|
56
63
|
console.log(`${chalk.gray("SARIF report written to")} ${chalk.cyan(sarifFilename)}`);
|
|
57
64
|
}
|
|
58
65
|
if (options.cdx) {
|
|
@@ -79,7 +79,14 @@ function resolveDirectParentContext(viaPath, packages, directDependencyNames, pa
|
|
|
79
79
|
const directParentName = directParentCandidates[0];
|
|
80
80
|
if (!directParentName)
|
|
81
81
|
return null;
|
|
82
|
-
|
|
82
|
+
// Path-based lookup disambiguates when the same package name is installed at
|
|
83
|
+
// multiple versions (e.g. eslint@9.36.0 at root AND eslint@6.14.0 nested).
|
|
84
|
+
// A name-keyed Map (last-write-wins) would return an arbitrary version, making
|
|
85
|
+
// directParentVersion wrong and potentially producing downgrade suggestions.
|
|
86
|
+
const directParentIdx = viaPath.indexOf(directParentName);
|
|
87
|
+
const directParentPathPrefix = viaPath.slice(0, directParentIdx + 1);
|
|
88
|
+
const directParent = findPackageAlongPath(packages, directParentName, directParentPathPrefix) ??
|
|
89
|
+
findDirectDependency(packages, directParentName, directDependencyNames, packagesByName);
|
|
83
90
|
if (!directParent)
|
|
84
91
|
return null;
|
|
85
92
|
return { directParentName, immediateParentName, directParent };
|
|
@@ -47,3 +47,9 @@ export function aggregateMultiFolderCompleteness(results) {
|
|
|
47
47
|
}
|
|
48
48
|
return { complete: deduped.size === 0, diagnostics: [...deduped.values()] };
|
|
49
49
|
}
|
|
50
|
+
export function shouldFailForIncompleteScan(completeness, policy) {
|
|
51
|
+
if (policy !== "error") {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return getCompletenessImpact(completeness).hasDetectionGap;
|
|
55
|
+
}
|
|
@@ -18,10 +18,12 @@ import { getCliVersion } from "../utils/version-info.js";
|
|
|
18
18
|
import { buildOverrideContext, audit } from "../overrides/index.js";
|
|
19
19
|
import { NULL_AUDIT_LOG } from "../audit-log/index.js";
|
|
20
20
|
import { detectDM001 } from "../maintenance/dm001-maintenance-risk.js";
|
|
21
|
+
import { detectLicenseIssues } from "../licenses/license-check.js";
|
|
22
|
+
import { renderLicenseFindings } from "../output/license-terminal.js";
|
|
21
23
|
import { reachesFailOn } from "../utils/severity.js";
|
|
22
24
|
import { readBaseline, writeBaseline, filterNewFindings, ratchetOutcome } from "../utils/baseline.js";
|
|
23
25
|
import { pluralize } from "../utils/string.js";
|
|
24
|
-
import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, } from "./completeness.js";
|
|
26
|
+
import { aggregateMultiFolderCompleteness, formatDiagnosticMessage, getCompletenessImpact, shouldFailForIncompleteScan, } from "./completeness.js";
|
|
25
27
|
import { scanProjectForPackageUsage } from "../usage/scanner.js";
|
|
26
28
|
export async function runMultiFolderScan(params) {
|
|
27
29
|
const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
@@ -96,6 +98,20 @@ export async function runMultiFolderScan(params) {
|
|
|
96
98
|
const directDependencies = scanInput.packages.filter(p => directDependencyNames?.has(p.name));
|
|
97
99
|
maintenanceFindings = await detectDM001(sorted, directDependencies, offline);
|
|
98
100
|
}
|
|
101
|
+
let licenseFindings = [];
|
|
102
|
+
let licenseLimitedToDirectOnly = false;
|
|
103
|
+
if (params.options.checkLicenses && !params.options.ratchet) {
|
|
104
|
+
const directDeps = scanInput.packages.filter(p => directDependencyNames?.has(p.name));
|
|
105
|
+
const isNpm = scanInput.source === "package-lock" || scanInput.source === "npm-shrinkwrap";
|
|
106
|
+
const licenseResult = await detectLicenseIssues({
|
|
107
|
+
lockfilePath: scanInput.filePath,
|
|
108
|
+
directDeps,
|
|
109
|
+
isNpm,
|
|
110
|
+
isOffline: offline,
|
|
111
|
+
});
|
|
112
|
+
licenseFindings = licenseResult.findings;
|
|
113
|
+
licenseLimitedToDirectOnly = licenseResult.limitedToDirectOnly;
|
|
114
|
+
}
|
|
99
115
|
results.push({
|
|
100
116
|
subfolder,
|
|
101
117
|
scanInput,
|
|
@@ -108,6 +124,8 @@ export async function runMultiFolderScan(params) {
|
|
|
108
124
|
completeness,
|
|
109
125
|
overrideFindings,
|
|
110
126
|
maintenanceFindings,
|
|
127
|
+
licenseFindings,
|
|
128
|
+
licenseLimitedToDirectOnly,
|
|
111
129
|
suppressedCount,
|
|
112
130
|
});
|
|
113
131
|
}
|
|
@@ -229,19 +247,19 @@ export async function handleMultiFolderScan(params) {
|
|
|
229
247
|
if (params.options.ratchet) {
|
|
230
248
|
return handleMultiFolderRatchet(results, params.projectRoot, params.options);
|
|
231
249
|
}
|
|
250
|
+
const aggregatedCompleteness = aggregateMultiFolderCompleteness(results);
|
|
232
251
|
if (params.options.json) {
|
|
233
252
|
// Match single-folder writeOutputs: timestamped file in cwd, not stdout dump.
|
|
234
253
|
// Help text and CI both treat --json as "save a JSON file".
|
|
235
254
|
const allFindings = results.flatMap(r => r.sorted.map(f => ({ ...serializeFinding(f, r.suggestedFixCommands), subfolder: r.subfolder })));
|
|
236
|
-
const completeness = aggregateMultiFolderCompleteness(results);
|
|
237
255
|
const payload = {
|
|
238
256
|
multiFolder: true,
|
|
239
257
|
projectPath: params.projectRoot,
|
|
240
258
|
folders: results.map(r => r.subfolder),
|
|
241
259
|
findingCount: allFindings.length,
|
|
242
|
-
status:
|
|
243
|
-
complete:
|
|
244
|
-
diagnostics:
|
|
260
|
+
status: aggregatedCompleteness.complete ? "ok" : "partial",
|
|
261
|
+
complete: aggregatedCompleteness.complete,
|
|
262
|
+
diagnostics: aggregatedCompleteness.diagnostics,
|
|
245
263
|
findings: allFindings,
|
|
246
264
|
...(params.options.checkOverrides
|
|
247
265
|
? {
|
|
@@ -253,6 +271,11 @@ export async function handleMultiFolderScan(params) {
|
|
|
253
271
|
maintenanceFindings: results.flatMap(r => r.maintenanceFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
254
272
|
}
|
|
255
273
|
: {}),
|
|
274
|
+
...(params.options.checkLicenses
|
|
275
|
+
? {
|
|
276
|
+
licenseFindings: results.flatMap(r => r.licenseFindings.map(f => ({ ...f, subfolder: r.subfolder }))),
|
|
277
|
+
}
|
|
278
|
+
: {}),
|
|
256
279
|
scannedAt: new Date().toISOString(),
|
|
257
280
|
};
|
|
258
281
|
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
@@ -277,6 +300,12 @@ export async function handleMultiFolderScan(params) {
|
|
|
277
300
|
console.log(renderMaintenanceFindings(r.maintenanceFindings, { verbose: !!params.options.verbose }));
|
|
278
301
|
}
|
|
279
302
|
}
|
|
303
|
+
if (params.options.checkLicenses) {
|
|
304
|
+
for (const r of results) {
|
|
305
|
+
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${r.subfolder}/`)} ${chalk.gray("license issues")}\n`);
|
|
306
|
+
console.log(renderLicenseFindings(r.licenseFindings, { limitedToDirectOnly: r.licenseLimitedToDirectOnly }));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
280
309
|
if (!params.options.checkOverrides && !params.options.ratchet) {
|
|
281
310
|
for (const r of results) {
|
|
282
311
|
const subfolderPath = path.join(params.projectRoot, r.subfolder);
|
|
@@ -300,6 +329,7 @@ export async function handleMultiFolderScan(params) {
|
|
|
300
329
|
// flag so empty panels render when the check ran with no hits.
|
|
301
330
|
includeOverrides: !!params.options.checkOverrides,
|
|
302
331
|
includeMaintenance: !!params.options.checkMaintenance,
|
|
332
|
+
includeLicenses: !!params.options.checkLicenses,
|
|
303
333
|
});
|
|
304
334
|
console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
|
|
305
335
|
}
|
|
@@ -313,7 +343,12 @@ export async function handleMultiFolderScan(params) {
|
|
|
313
343
|
const shouldFail = allSorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]) ||
|
|
314
344
|
reachesFailOn(allOverrideFindings, params.options.failOn) ||
|
|
315
345
|
reachesFailOn(allMaintenanceFindings, params.options.failOn);
|
|
316
|
-
const
|
|
346
|
+
const incompleteFailure = shouldFailForIncompleteScan(aggregatedCompleteness, params.options.incompletePolicy);
|
|
347
|
+
const exitCode = incompleteFailure
|
|
348
|
+
? EXIT_ERROR
|
|
349
|
+
: shouldFail
|
|
350
|
+
? EXIT_FINDINGS
|
|
351
|
+
: EXIT_OK;
|
|
317
352
|
auditLog.emit({
|
|
318
353
|
ts: new Date(scanFinishedAt).toISOString(),
|
|
319
354
|
type: "scan.finished",
|