cve-lite-cli 1.27.0 → 1.29.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 +45 -3
- package/dist/advisory/osv-advisory-source.js +5 -3
- package/dist/cli/advisories-init.js +24 -0
- package/dist/cli/args.js +30 -0
- package/dist/cli/help.js +6 -2
- package/dist/cli/validate.js +6 -0
- package/dist/constants.js +1 -0
- package/dist/index.js +67 -7
- package/dist/maintenance/dm001-maintenance-risk.js +122 -0
- package/dist/maintenance/score.js +51 -0
- package/dist/maintenance/types.js +1 -0
- package/dist/osv/cache.js +49 -50
- package/dist/output/formatters.js +10 -4
- package/dist/output/html-reporter.js +163 -14
- package/dist/output/maintenance-findings-html.js +60 -0
- package/dist/output/maintenance-findings-json.js +3 -0
- package/dist/output/maintenance-findings-sarif.js +58 -0
- package/dist/output/maintenance-terminal.js +138 -0
- package/dist/output/multi-folder-html-reporter.js +61 -5
- package/dist/output/multi-folder-printer.js +11 -2
- package/dist/output/override-findings-html.js +22 -32
- package/dist/output/printers.js +95 -22
- package/dist/output/sarif.js +23 -7
- package/dist/output/spinner.js +5 -0
- package/dist/output/write-outputs.js +7 -2
- package/dist/parsers/bun-lock.js +47 -7
- package/dist/parsers/npm-lock-graph.js +90 -12
- package/dist/parsers/pnpm-lock.js +42 -6
- package/dist/parsers/utils.js +0 -15
- package/dist/parsers/yarn-lock.js +140 -58
- package/dist/remediation/cooldown.js +74 -0
- package/dist/remediation/fix-commands.js +42 -2
- package/dist/remediation/npm-registry.js +70 -42
- package/dist/remediation/parent-upgrade.js +114 -18
- package/dist/scan/completeness.js +49 -0
- package/dist/scan/multi-folder-scan.js +193 -13
- package/dist/scanner.js +284 -165
- package/dist/usage/scanner.js +12 -2
- package/dist/utils/network.js +66 -0
- package/dist/utils/vuln.js +16 -0
- package/package.json +2 -2
package/dist/osv/cache.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
|
+
import { CACHE_TTL_MS } from "../constants.js";
|
|
4
5
|
function createEmptyCache() {
|
|
5
|
-
return { version:
|
|
6
|
+
return { version: 4, createdAt: new Date().toISOString(), entries: {}, queryEntries: {}, npmVersionEntries: {} };
|
|
7
|
+
}
|
|
8
|
+
// v4 stores detail records as { vuln, cachedAt }. v1-v3 stored the OsvVuln (or
|
|
9
|
+
// null for a known-empty lookup) directly, with no timestamp. Legacy records are
|
|
10
|
+
// wrapped with an epoch-0 cachedAt so they read as stale and get refreshed on the
|
|
11
|
+
// next scan, matching how the queryEntries v2->v3 migration backdates its records.
|
|
12
|
+
function wrapLegacyDetailEntries(raw) {
|
|
13
|
+
const epoch = new Date(0).toISOString();
|
|
14
|
+
const entries = {};
|
|
15
|
+
for (const [id, value] of Object.entries(raw ?? {})) {
|
|
16
|
+
entries[id] = { vuln: value ?? null, cachedAt: epoch };
|
|
17
|
+
}
|
|
18
|
+
return entries;
|
|
19
|
+
}
|
|
20
|
+
function readDetailEntries(raw) {
|
|
21
|
+
const entries = {};
|
|
22
|
+
for (const [id, value] of Object.entries(raw ?? {})) {
|
|
23
|
+
if (value && typeof value === "object" && "vuln" in value && "cachedAt" in value) {
|
|
24
|
+
entries[id] = value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return entries;
|
|
6
28
|
}
|
|
7
29
|
export function getCacheFilePath(cacheDirOverride) {
|
|
8
30
|
const baseDir = cacheDirOverride
|
|
@@ -12,7 +34,7 @@ export function getCacheFilePath(cacheDirOverride) {
|
|
|
12
34
|
return path.join(baseDir, "osv-vulns.json");
|
|
13
35
|
}
|
|
14
36
|
export function isEntryStale(entry, nowMs) {
|
|
15
|
-
return nowMs - new Date(entry.cachedAt).getTime() >
|
|
37
|
+
return nowMs - new Date(entry.cachedAt).getTime() > CACHE_TTL_MS;
|
|
16
38
|
}
|
|
17
39
|
export function loadCache(cacheDirOverride, debugLog) {
|
|
18
40
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
@@ -31,64 +53,40 @@ export function loadCache(cacheDirOverride, debugLog) {
|
|
|
31
53
|
debugLog?.("Cache load failed", { path: filePath, reason: "invalid root object" });
|
|
32
54
|
return createEmptyCache();
|
|
33
55
|
}
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
|
|
56
|
+
const version = parsed.version;
|
|
57
|
+
const rawEntries = parsed.entries;
|
|
58
|
+
// Detail records: v4 already carries { vuln, cachedAt }; v1-v3 stored the record
|
|
59
|
+
// directly and are wrapped (and backdated) so the TTL applies uniformly.
|
|
60
|
+
const entries = version === 4 ? readDetailEntries(rawEntries) : wrapLegacyDetailEntries(rawEntries);
|
|
61
|
+
// Query records: v2 stored string[]; v3 and v4 store { vulnIds, cachedAt }; v1/unknown had none.
|
|
62
|
+
const queryEntries = {};
|
|
63
|
+
if (version === 2) {
|
|
39
64
|
const rawQuery = parsed.queryEntries;
|
|
40
|
-
const
|
|
65
|
+
const epoch = new Date(0).toISOString();
|
|
41
66
|
for (const [key, vulnIds] of Object.entries(rawQuery ?? {})) {
|
|
42
|
-
queryEntries[key] = { vulnIds: Array.isArray(vulnIds) ? vulnIds : [], cachedAt:
|
|
67
|
+
queryEntries[key] = { vulnIds: Array.isArray(vulnIds) ? vulnIds : [], cachedAt: epoch };
|
|
43
68
|
}
|
|
44
|
-
const migrated = {
|
|
45
|
-
version: 3,
|
|
46
|
-
createdAt: String(parsed.createdAt ?? new Date().toISOString()),
|
|
47
|
-
entries,
|
|
48
|
-
queryEntries,
|
|
49
|
-
npmVersionEntries: {},
|
|
50
|
-
};
|
|
51
|
-
debugLog?.("Cache loaded", {
|
|
52
|
-
path: filePath,
|
|
53
|
-
queryEntries: Object.keys(migrated.queryEntries).length,
|
|
54
|
-
detailEntries: Object.keys(migrated.entries).length,
|
|
55
|
-
migratedFrom: 2,
|
|
56
|
-
});
|
|
57
|
-
return migrated;
|
|
58
|
-
}
|
|
59
|
-
// v1 or unknown: no queryEntries
|
|
60
|
-
if (parsed.version !== 3) {
|
|
61
|
-
const upgraded = {
|
|
62
|
-
version: 3,
|
|
63
|
-
createdAt: new Date().toISOString(),
|
|
64
|
-
entries,
|
|
65
|
-
queryEntries: {},
|
|
66
|
-
npmVersionEntries: {},
|
|
67
|
-
};
|
|
68
|
-
debugLog?.("Cache loaded", {
|
|
69
|
-
path: filePath,
|
|
70
|
-
queryEntries: 0,
|
|
71
|
-
detailEntries: Object.keys(upgraded.entries).length,
|
|
72
|
-
migratedFrom: parsed.version ?? "unknown",
|
|
73
|
-
});
|
|
74
|
-
return upgraded;
|
|
75
69
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
else if (version === 3 || version === 4) {
|
|
71
|
+
const rawQuery = parsed.queryEntries;
|
|
72
|
+
for (const [key, value] of Object.entries(rawQuery ?? {})) {
|
|
73
|
+
if (value && typeof value === "object" && "vulnIds" in value && "cachedAt" in value) {
|
|
74
|
+
queryEntries[key] = value;
|
|
75
|
+
}
|
|
81
76
|
}
|
|
82
77
|
}
|
|
83
|
-
|
|
78
|
+
// npm publish-date records exist from v3 onward.
|
|
84
79
|
const npmVersionEntries = {};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
if (version === 3 || version === 4) {
|
|
81
|
+
const rawNpmVersions = parsed.npmVersionEntries;
|
|
82
|
+
for (const [key, value] of Object.entries(rawNpmVersions ?? {})) {
|
|
83
|
+
if (value && typeof value === "object" && "publishedAt" in value && "cachedAt" in value) {
|
|
84
|
+
npmVersionEntries[key] = value;
|
|
85
|
+
}
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
88
|
const loaded = {
|
|
91
|
-
version:
|
|
89
|
+
version: 4,
|
|
92
90
|
createdAt: String(parsed.createdAt ?? new Date().toISOString()),
|
|
93
91
|
entries,
|
|
94
92
|
queryEntries,
|
|
@@ -98,6 +96,7 @@ export function loadCache(cacheDirOverride, debugLog) {
|
|
|
98
96
|
path: filePath,
|
|
99
97
|
queryEntries: Object.keys(loaded.queryEntries).length,
|
|
100
98
|
detailEntries: Object.keys(loaded.entries).length,
|
|
99
|
+
...(version === 4 ? {} : { migratedFrom: version ?? "unknown" }),
|
|
101
100
|
});
|
|
102
101
|
return loaded;
|
|
103
102
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
1
|
+
import { findFixTargetForFinding, findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
2
2
|
import { chalk } from "../utils/chalk.js";
|
|
3
3
|
import { severityOrder, MAL_PRIVATE_REGISTRY_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, } from "../constants.js";
|
|
4
4
|
import { loadCache } from "../osv/cache.js";
|
|
@@ -6,6 +6,7 @@ import { inferSeverity } from "../osv/severity.js";
|
|
|
6
6
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
7
7
|
import { calculatePathCoverage, formatDependencyPath } from "../utils/path-coverage.js";
|
|
8
8
|
import { pluralize } from "../utils/string.js";
|
|
9
|
+
import { hasMaliciousAdvisory } from "../utils/vuln.js";
|
|
9
10
|
export function formatRelationshipLabel(value) {
|
|
10
11
|
if (value.startsWith("direct"))
|
|
11
12
|
return chalk.green(value);
|
|
@@ -35,7 +36,7 @@ export function formatHintLines(lines) {
|
|
|
35
36
|
}
|
|
36
37
|
// MAL-* is the OSV prefix for malicious code advisories
|
|
37
38
|
function isMaliciousAdvisory(finding) {
|
|
38
|
-
return finding.vulnerabilities
|
|
39
|
+
return hasMaliciousAdvisory(finding.vulnerabilities);
|
|
39
40
|
}
|
|
40
41
|
export function getRecommendedAction(finding) {
|
|
41
42
|
if (isMaliciousAdvisory(finding)) {
|
|
@@ -191,6 +192,9 @@ export function summarizeNextAction(finding) {
|
|
|
191
192
|
export function formatFixVersionPublishDate(iso) {
|
|
192
193
|
return iso.slice(0, 10);
|
|
193
194
|
}
|
|
195
|
+
export function formatCooldownWarning(warning) {
|
|
196
|
+
return `Published ${formatFixVersionPublishDate(warning.publishedAt)}, newer than your configured ${warning.windowLabel} release cooldown (${warning.sourceFile}); your package manager would hold this version - validate before overriding.`;
|
|
197
|
+
}
|
|
194
198
|
export function formatFixCommandPublishSuffix(targets) {
|
|
195
199
|
const dated = targets.filter(target => target.kind === "direct" && target.fixVersionPublishedAt);
|
|
196
200
|
if (dated.length === 0)
|
|
@@ -216,6 +220,7 @@ export function serializeFinding(finding, plan) {
|
|
|
216
220
|
validatedFirstFixedVersion: finding.validatedFirstFixedVersion ?? null,
|
|
217
221
|
fixVersionValidationNote: finding.fixVersionValidationNote ?? null,
|
|
218
222
|
fixVersionPublishedAt: finding.fixVersionPublishedAt ?? null,
|
|
223
|
+
cooldownWarning: plan ? (findFixTargetForFinding(plan, finding)?.cooldownWarning ?? null) : null,
|
|
219
224
|
validatedTargetScannedVersions: finding.validatedTargetScannedVersions ?? null,
|
|
220
225
|
validatedTargetKnownVulnerableVersions: finding.validatedTargetKnownVulnerableVersions ?? null,
|
|
221
226
|
recommendedAction: getRecommendedAction(finding),
|
|
@@ -229,6 +234,7 @@ export function serializeFinding(finding, plan) {
|
|
|
229
234
|
maliciousUnverifiable: finding.maliciousUnverifiable ?? false,
|
|
230
235
|
maliciousGitSource: finding.maliciousGitSource ?? false,
|
|
231
236
|
maliciousGitSourcePinned: finding.maliciousGitSourcePinned ?? false,
|
|
237
|
+
unresolvedAdvisoryIds: finding.unresolvedAdvisoryIds ?? [],
|
|
232
238
|
vulnerabilities: finding.vulnerabilities.map(v => ({
|
|
233
239
|
id: v.id,
|
|
234
240
|
aliases: v.aliases ?? [],
|
|
@@ -241,8 +247,8 @@ export function printCacheSummary(cacheDirOverride, options) {
|
|
|
241
247
|
if (options?.json)
|
|
242
248
|
return;
|
|
243
249
|
const cache = loadCache(cacheDirOverride);
|
|
244
|
-
const advisoryCount = Object.
|
|
245
|
-
const emptyCount = Object.
|
|
250
|
+
const advisoryCount = Object.values(cache.entries).filter(entry => entry.vuln).length;
|
|
251
|
+
const emptyCount = Object.values(cache.entries).filter(entry => entry.vuln === null).length;
|
|
246
252
|
const packageQueryCount = Object.keys(cache.queryEntries).length;
|
|
247
253
|
const totalCount = advisoryCount + emptyCount;
|
|
248
254
|
if (totalCount === 0 && packageQueryCount === 0)
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
|
-
import { serializeFinding, summarizeNextAction, summarizeRisk, formatFixCommandWithPublishDates } from "./formatters.js";
|
|
4
|
+
import { serializeFinding, summarizeNextAction, summarizeRisk, formatFixCommandWithPublishDates, formatCooldownWarning } from "./formatters.js";
|
|
5
5
|
import { loadLogoDataUri } from "./logos.js";
|
|
6
6
|
import { isMajorVersionBump } from "../utils/version.js";
|
|
7
7
|
import { pluralize } from "../utils/string.js";
|
|
8
|
-
import { MAL_GIT_SOURCE_PINNED_DISPLAY, MAL_GIT_SOURCE_FLOATING_DISPLAY } from "../constants.js";
|
|
8
|
+
import { MAL_GIT_SOURCE_PINNED_DISPLAY, MAL_GIT_SOURCE_FLOATING_DISPLAY, severityOrder } from "../constants.js";
|
|
9
|
+
import { hasMaliciousAdvisory } from "../utils/vuln.js";
|
|
9
10
|
import { renderOverrideFindingsHtml } from "./override-findings-html.js";
|
|
11
|
+
import { renderMaintenanceFindingsHtml } from "./maintenance-findings-html.js";
|
|
12
|
+
import { UNVERIFIED_PARENT_UPGRADE_NOTE } from "../remediation/fix-commands.js";
|
|
13
|
+
import { getCompletenessImpact } from "../scan/completeness.js";
|
|
10
14
|
export function serializeHtmlFinding(finding, plan) {
|
|
11
15
|
return {
|
|
12
16
|
...serializeFinding(finding, plan),
|
|
@@ -26,7 +30,10 @@ export function buildReportData(params) {
|
|
|
26
30
|
suggestedFixCommands: params.suggestedFixCommands,
|
|
27
31
|
notes: params.notes,
|
|
28
32
|
warnings: params.warnings,
|
|
33
|
+
skippedDependencies: params.skippedDependencies,
|
|
29
34
|
overrideFindings: params.overrideFindings,
|
|
35
|
+
maintenanceFindings: params.maintenanceFindings,
|
|
36
|
+
completeness: params.completeness,
|
|
30
37
|
};
|
|
31
38
|
}
|
|
32
39
|
export const REPORT_STYLES = `:root{--bg:#0d1117;--surface:#161b22;--surface-hi:#1c2128;--input:#21262d;--border:#30363d;--border-sub:#21262d;--text:#e6edf3;--text-2:#8b949e;--text-3:#6b7280;--link:#58a6ff;--link-h:#79c0ff;--green:#3fb950;--logo-bg:#fff}
|
|
@@ -77,6 +84,18 @@ button.header-link:hover{color:var(--link);border-color:var(--link)}
|
|
|
77
84
|
.skipped-rel.direct{color:#3fb950}
|
|
78
85
|
.skipped-rel.transitive{color:#e3b341}
|
|
79
86
|
.skipped-reason{color:var(--text-3)}
|
|
87
|
+
.skipped-deps{padding:12px 18px;display:flex;flex-direction:column;gap:4px}
|
|
88
|
+
.skipped-deps .skipped-deps-hint{font-size:11px;color:var(--text-2);margin-bottom:4px}
|
|
89
|
+
.skipped-dep{font-size:11px;padding:5px 8px;border-radius:4px;background:var(--bg);border:1px solid var(--border-sub)}
|
|
90
|
+
.dup-pkgs{padding:12px 18px;display:flex;flex-direction:column;gap:10px}
|
|
91
|
+
.dup-pkgs .dup-pkgs-hint{font-size:11px;color:var(--text-2);margin-bottom:2px}
|
|
92
|
+
.dup-pkg{background:var(--bg);border:1px solid var(--border-sub);border-radius:6px;padding:8px 10px}
|
|
93
|
+
.dup-pkg-name{font-size:13px;font-weight:600;color:var(--text);display:flex;align-items:center;gap:8px;margin-bottom:6px}
|
|
94
|
+
.dup-count{font-size:11px;font-weight:500;color:var(--text-2);background:var(--input);border:1px solid var(--border);border-radius:10px;padding:1px 7px}
|
|
95
|
+
.dup-versions{display:flex;flex-direction:column;gap:4px}
|
|
96
|
+
.dup-version{display:flex;align-items:center;gap:8px;font-size:12px;color:var(--text-2)}
|
|
97
|
+
.dup-version .dup-ver{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--text)}
|
|
98
|
+
.dup-version .dup-origin{color:var(--text-3)}
|
|
80
99
|
.fix-cmd{display:flex;align-items:center;gap:12px;background:var(--bg);border:1px solid var(--border);border-radius:6px;padding:10px 14px}
|
|
81
100
|
.fix-cmd .cmd-text{flex:1;font-family:'SF Mono','Cascadia Code','Fira Code',monospace;font-size:12px;color:var(--green)}
|
|
82
101
|
.fix-cmd .cmd-meta{font-size:11px;color:var(--text-2);white-space:nowrap}
|
|
@@ -159,6 +178,12 @@ button.header-link:hover{color:var(--link);border-color:var(--link)}
|
|
|
159
178
|
.fix-target-note{color:var(--text-3);font-style:italic;font-size:10px}
|
|
160
179
|
.fix-target-coverage{flex-basis:100%;color:var(--text-3);font-size:10px;line-height:1.45}
|
|
161
180
|
.chain-proof{font-size:0.78rem;color:var(--text-2);margin-left:6px;font-family:monospace}
|
|
181
|
+
.completeness-banner{margin:16px 32px 0;background:#e3b34111;border:1px solid #e3b34144;border-radius:8px;padding:14px 18px;display:flex;gap:14px;align-items:flex-start}
|
|
182
|
+
.completeness-banner-icon{font-size:22px;flex-shrink:0;line-height:1}
|
|
183
|
+
.completeness-banner-body strong{font-size:13px;color:var(--text);display:block;margin-bottom:4px}
|
|
184
|
+
.completeness-banner-body p{font-size:12px;color:var(--text-2);margin:0}
|
|
185
|
+
.completeness-banner-body ul{margin:8px 0 0;padding:0 0 0 18px;display:flex;flex-direction:column;gap:3px}
|
|
186
|
+
.completeness-banner-body li{font-size:11px;color:var(--text-2);line-height:1.5}
|
|
162
187
|
.break-badge{font-size:10px;font-weight:700;background:#fb850022;color:#fb8500;border:1px solid #fb850066;border-radius:4px;padding:1px 5px}
|
|
163
188
|
.tier-ok{display:inline-flex;align-items:center;gap:4px;font-size:10px;padding:2px 8px;border-radius:4px;background:#3fb95022;color:#3fb950;border:1px solid #3fb95033;margin-bottom:6px}
|
|
164
189
|
.tier-warn{display:inline-flex;align-items:center;gap:4px;font-size:10px;padding:2px 8px;border-radius:4px;background:#e3b34122;color:#e3b341;border:1px solid #e3b34133;margin-bottom:6px}
|
|
@@ -166,18 +191,21 @@ button.header-link:hover{color:var(--link);border-color:var(--link)}
|
|
|
166
191
|
.override-hygiene{margin:0 32px 32px}
|
|
167
192
|
.override-hygiene h2{font-size:13px;font-weight:600;color:var(--text);margin-bottom:12px}
|
|
168
193
|
.override-hygiene p{font-size:13px;color:var(--text-2)}
|
|
169
|
-
.override-hygiene table{width:100%;border-collapse:collapse
|
|
170
|
-
.override-hygiene table thead th{text-align:left;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;color:var(--text-2);padding:10px 14px;border-bottom:1px solid var(--border-sub);background:var(--surface-
|
|
194
|
+
.override-hygiene table{width:100%;border-collapse:collapse}
|
|
195
|
+
.override-hygiene table thead th{text-align:left;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;color:var(--text-2);padding:10px 14px;border-bottom:1px solid var(--border-sub);background:var(--surface);white-space:nowrap}
|
|
171
196
|
.override-hygiene table tbody tr{border-bottom:1px solid var(--border-sub)}
|
|
172
197
|
.override-hygiene table tbody tr:last-child{border-bottom:none}
|
|
173
|
-
.override-hygiene table tbody tr
|
|
174
|
-
.override-hygiene table tbody
|
|
175
|
-
.
|
|
176
|
-
.
|
|
177
|
-
.
|
|
178
|
-
.
|
|
179
|
-
.
|
|
180
|
-
.
|
|
198
|
+
.override-hygiene table tbody tr:hover{background:var(--surface)}
|
|
199
|
+
.override-hygiene table tbody td{padding:11px 14px;font-size:13px;color:var(--text);vertical-align:middle}
|
|
200
|
+
.maintenance-risk{margin:0 32px 32px}
|
|
201
|
+
.maintenance-risk h2{font-size:13px;font-weight:600;color:var(--text);margin-bottom:12px}
|
|
202
|
+
.maintenance-risk p{font-size:13px;color:var(--text-2)}
|
|
203
|
+
.maintenance-risk table{width:100%;border-collapse:collapse}
|
|
204
|
+
.maintenance-risk table thead th{text-align:left;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;color:var(--text-2);padding:10px 14px;border-bottom:1px solid var(--border-sub);background:var(--surface);white-space:nowrap}
|
|
205
|
+
.maintenance-risk table tbody tr{border-bottom:1px solid var(--border-sub)}
|
|
206
|
+
.maintenance-risk table tbody tr:last-child{border-bottom:none}
|
|
207
|
+
.maintenance-risk table tbody tr:hover{background:var(--surface)}
|
|
208
|
+
.maintenance-risk table tbody td{padding:11px 14px;font-size:13px;color:var(--text);vertical-align:middle}`;
|
|
181
209
|
export function renderHtmlReport(data) {
|
|
182
210
|
const projectName = path.basename(data.projectPath);
|
|
183
211
|
const scanDate = new Date(data.scannedAt).toLocaleString();
|
|
@@ -189,9 +217,12 @@ export function renderHtmlReport(data) {
|
|
|
189
217
|
}
|
|
190
218
|
const totalCVEs = new Set(data.findings.flatMap(f => f.vulnerabilities.map(v => v.id))).size;
|
|
191
219
|
const noticesHtml = renderNotices(data.notes, data.warnings);
|
|
220
|
+
const completenessBannerHtml = renderCompletenessBanner(data.completeness);
|
|
192
221
|
const fixPlanHtml = renderFixPlan(data.suggestedFixCommands);
|
|
193
222
|
const skippedKeys = new Set((data.suggestedFixCommands?.skipped ?? []).map(s => `${s.package}@${s.version}`));
|
|
194
223
|
const skippedSectionHtml = renderSkippedSection(data.suggestedFixCommands);
|
|
224
|
+
const skippedDepsHtml = renderSkippedDependenciesSection(data.skippedDependencies);
|
|
225
|
+
const duplicatePackagesHtml = renderDuplicatePackagesSection(data.findings);
|
|
195
226
|
const findingRowsHtml = data.findings.map((f, i) => renderFindingRow(f, i, skippedKeys)).join("\n");
|
|
196
227
|
const dataJson = JSON.stringify(data)
|
|
197
228
|
.replace(/</g, "\\u003c")
|
|
@@ -259,7 +290,9 @@ ${REPORT_STYLES}
|
|
|
259
290
|
<div class="sev-card total"><span class="count">${totalCVEs}</span><span class="label">CVEs</span></div>
|
|
260
291
|
</div>
|
|
261
292
|
|
|
293
|
+
${completenessBannerHtml}
|
|
262
294
|
${fixPlanHtml}
|
|
295
|
+
${duplicatePackagesHtml}
|
|
263
296
|
|
|
264
297
|
<div class="findings-section">
|
|
265
298
|
<div class="findings-header">
|
|
@@ -294,7 +327,9 @@ ${findingRowsHtml}
|
|
|
294
327
|
</table>
|
|
295
328
|
</div>
|
|
296
329
|
${renderOverrideFindingsHtml(data.overrideFindings, data.projectPath)}
|
|
330
|
+
${renderMaintenanceFindingsHtml(data.maintenanceFindings)}
|
|
297
331
|
|
|
332
|
+
${skippedDepsHtml}
|
|
298
333
|
${noticesHtml}
|
|
299
334
|
|
|
300
335
|
<div class="report-footer">
|
|
@@ -452,7 +487,7 @@ export function renderFindingRow(finding, idx, skippedKeys) {
|
|
|
452
487
|
const cveLinks = finding.cves.length > 0
|
|
453
488
|
? finding.cves.map(advisoryLink).join(", ")
|
|
454
489
|
: finding.vulnerabilities.map(v => advisoryLink(v.id)).join(", ");
|
|
455
|
-
const isMalicious = finding.vulnerabilities
|
|
490
|
+
const isMalicious = hasMaliciousAdvisory(finding.vulnerabilities);
|
|
456
491
|
const isSkipped = skippedKeys?.has(`${finding.package}@${finding.version}`);
|
|
457
492
|
const fixVersion = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
458
493
|
const fixHtml = isSkipped && fixVersion
|
|
@@ -544,6 +579,33 @@ function renderTransitiveContextCol(finding) {
|
|
|
544
579
|
<p style="font-size:12px;color:var(--text-2);margin-top:4px">Run <code>npm ls ${escapeHtml(finding.package)}</code> to find which package pulls it in.</p>
|
|
545
580
|
</div>`;
|
|
546
581
|
}
|
|
582
|
+
export function renderCompletenessBanner(completeness) {
|
|
583
|
+
if (completeness == null || completeness.complete)
|
|
584
|
+
return "";
|
|
585
|
+
const { hasDetectionGap, hasRemediationGap } = getCompletenessImpact(completeness);
|
|
586
|
+
let bannerText;
|
|
587
|
+
if (hasDetectionGap && hasRemediationGap) {
|
|
588
|
+
bannerText = "Some vulnerability findings may be incomplete, and some remediation guidance may also be unavailable because the following issues occurred:";
|
|
589
|
+
}
|
|
590
|
+
else if (hasDetectionGap) {
|
|
591
|
+
bannerText = "Some vulnerability findings may be incomplete because the following issues occurred:";
|
|
592
|
+
}
|
|
593
|
+
else if (hasRemediationGap) {
|
|
594
|
+
bannerText = "Vulnerability findings are available, but remediation guidance may be incomplete because the following issues occurred:";
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
bannerText = "The scan result may be incomplete because the following issues occurred:";
|
|
598
|
+
}
|
|
599
|
+
const diagRows = completeness.diagnostics.map(d => `<li class="diag-item ${escapeHtml(d.severity)} ${escapeHtml(d.impact)}">${escapeHtml(d.message)}</li>`).join("\n");
|
|
600
|
+
return `<div class="completeness-banner">
|
|
601
|
+
<div class="completeness-banner-icon">⚠</div>
|
|
602
|
+
<div class="completeness-banner-body">
|
|
603
|
+
<strong>Scan data is incomplete</strong>
|
|
604
|
+
<p>${bannerText}</p>
|
|
605
|
+
<ul>${diagRows}</ul>
|
|
606
|
+
</div>
|
|
607
|
+
</div>`;
|
|
608
|
+
}
|
|
547
609
|
function renderNotices(notes, warnings) {
|
|
548
610
|
if (notes.length === 0 && warnings.length === 0)
|
|
549
611
|
return "";
|
|
@@ -577,6 +639,87 @@ export function renderSkippedSection(plan) {
|
|
|
577
639
|
</div>
|
|
578
640
|
</div>`;
|
|
579
641
|
}
|
|
642
|
+
export function renderSkippedDependenciesSection(skipped) {
|
|
643
|
+
if (skipped.length === 0)
|
|
644
|
+
return "";
|
|
645
|
+
const rows = skipped
|
|
646
|
+
.map(dep => ` <div class="skipped-dep"><span class="skipped-pkg">${escapeHtml(dep)}</span></div>`)
|
|
647
|
+
.join("\n");
|
|
648
|
+
return `<div class="fix-plan">
|
|
649
|
+
<div class="fix-plan-header">
|
|
650
|
+
<h2><span class="icon">⊖</span> Skipped manifest dependencies</h2>
|
|
651
|
+
<span class="badge">${skipped.length} skipped</span>
|
|
652
|
+
</div>
|
|
653
|
+
<div class="skipped-deps">
|
|
654
|
+
<div class="skipped-deps-hint">Declared in the manifest but not scanned, because no resolvable version was found (for example private-registry packages, git or file specifiers, or version ranges that could not be parsed).</div>
|
|
655
|
+
${rows}
|
|
656
|
+
</div>
|
|
657
|
+
</div>`;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Groups vulnerable findings by package name and keeps only the packages that
|
|
661
|
+
* are installed at more than one version. This is the "same package, multiple
|
|
662
|
+
* versions" view: it shows where duplicate copies of a vulnerable package crept
|
|
663
|
+
* into the dependency tree so they can be consolidated onto one fixed version.
|
|
664
|
+
*/
|
|
665
|
+
export function collectDuplicatePackages(findings) {
|
|
666
|
+
const byName = new Map();
|
|
667
|
+
for (const finding of findings) {
|
|
668
|
+
let versions = byName.get(finding.package);
|
|
669
|
+
if (!versions) {
|
|
670
|
+
versions = new Map();
|
|
671
|
+
byName.set(finding.package, versions);
|
|
672
|
+
}
|
|
673
|
+
// First finding for a given version wins; a second advisory on the same
|
|
674
|
+
// install does not add a duplicate row.
|
|
675
|
+
if (!versions.has(finding.version))
|
|
676
|
+
versions.set(finding.version, finding);
|
|
677
|
+
}
|
|
678
|
+
const duplicates = [];
|
|
679
|
+
for (const [name, versions] of byName) {
|
|
680
|
+
if (versions.size > 1)
|
|
681
|
+
duplicates.push({ name, versions: [...versions.values()] });
|
|
682
|
+
}
|
|
683
|
+
// Most versions first, then alphabetical, so the output is stable.
|
|
684
|
+
duplicates.sort((a, b) => b.versions.length - a.versions.length || a.name.localeCompare(b.name));
|
|
685
|
+
return duplicates;
|
|
686
|
+
}
|
|
687
|
+
function duplicateOrigin(finding) {
|
|
688
|
+
if (finding.relationship === "direct")
|
|
689
|
+
return "direct dependency";
|
|
690
|
+
if (finding.primaryParent)
|
|
691
|
+
return `via ${finding.primaryParent}`;
|
|
692
|
+
return finding.relationship === "transitive" ? "transitive dependency" : "unknown origin";
|
|
693
|
+
}
|
|
694
|
+
export function renderDuplicatePackagesSection(findings) {
|
|
695
|
+
const duplicates = collectDuplicatePackages(findings);
|
|
696
|
+
if (duplicates.length === 0)
|
|
697
|
+
return "";
|
|
698
|
+
const cards = duplicates
|
|
699
|
+
.map(dup => {
|
|
700
|
+
const versionRows = [...dup.versions]
|
|
701
|
+
.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity] || a.version.localeCompare(b.version))
|
|
702
|
+
.map(f => ` <div class="dup-version"><span class="sev-badge ${escapeHtml(f.severity)}">${escapeHtml(f.severity)}</span><span class="dup-ver">${escapeHtml(f.version)}</span><span class="dup-origin">${escapeHtml(duplicateOrigin(f))}</span></div>`)
|
|
703
|
+
.join("\n");
|
|
704
|
+
return ` <div class="dup-pkg">
|
|
705
|
+
<div class="dup-pkg-name">${escapeHtml(dup.name)} <span class="dup-count">${dup.versions.length} versions</span></div>
|
|
706
|
+
<div class="dup-versions">
|
|
707
|
+
${versionRows}
|
|
708
|
+
</div>
|
|
709
|
+
</div>`;
|
|
710
|
+
})
|
|
711
|
+
.join("\n");
|
|
712
|
+
return `<div class="fix-plan">
|
|
713
|
+
<div class="fix-plan-header">
|
|
714
|
+
<h2><span class="icon">⧉</span> Duplicate package versions</h2>
|
|
715
|
+
<span class="badge">${duplicates.length} ${pluralize(duplicates.length, "package")}</span>
|
|
716
|
+
</div>
|
|
717
|
+
<div class="dup-pkgs">
|
|
718
|
+
<div class="dup-pkgs-hint">These vulnerable packages are installed at more than one version in this dependency tree. Consolidating each onto a single fixed version reduces how many places you have to patch.</div>
|
|
719
|
+
${cards}
|
|
720
|
+
</div>
|
|
721
|
+
</div>`;
|
|
722
|
+
}
|
|
580
723
|
export function renderFixPlan(plan) {
|
|
581
724
|
if (!plan || plan.sections.length === 0)
|
|
582
725
|
return "";
|
|
@@ -596,6 +739,12 @@ export function renderFixPlan(plan) {
|
|
|
596
739
|
const noteHtml = t.adjusted && t.adjustmentNote
|
|
597
740
|
? ` <span class="fix-target-note">${escapeHtml(t.adjustmentNote)}</span>`
|
|
598
741
|
: "";
|
|
742
|
+
const cooldownHtml = t.cooldownWarning
|
|
743
|
+
? ` <span class="fix-target-note">${escapeHtml(formatCooldownWarning(t.cooldownWarning))}</span>`
|
|
744
|
+
: "";
|
|
745
|
+
const unverifiedHtml = t.confidence === "unverified"
|
|
746
|
+
? ` <span class="fix-target-note">${escapeHtml(UNVERIFIED_PARENT_UPGRADE_NOTE)}</span>`
|
|
747
|
+
: "";
|
|
599
748
|
const coverageHtml = t.coverage === "partial"
|
|
600
749
|
? ` <span class="fix-target-coverage">Path-specific remediation. Run this command, then rescan; ${t.remainingPaths?.length ?? 0} other known ${pluralize(t.remainingPaths?.length ?? 0, "path")} may still need separate parent upgrades.</span>`
|
|
601
750
|
: "";
|
|
@@ -609,7 +758,7 @@ export function renderFixPlan(plan) {
|
|
|
609
758
|
return ` <span class="chain-proof">${proofText}</span>`;
|
|
610
759
|
})()
|
|
611
760
|
: "";
|
|
612
|
-
return `<div class="fix-target-row">${versionHtml}${breakBadge}${statsHtml}${noteHtml}${coverageHtml}${chainProofHtml}</div>`;
|
|
761
|
+
return `<div class="fix-target-row">${versionHtml}${breakBadge}${statsHtml}${noteHtml}${cooldownHtml}${unverifiedHtml}${coverageHtml}${chainProofHtml}</div>`;
|
|
613
762
|
}).join("\n");
|
|
614
763
|
const targetsHtml = section.targets.length > 0
|
|
615
764
|
? `<div class="fix-targets-list">${targetRows}</div>`
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { SEVERITY_ORDER } from "../utils/severity.js";
|
|
2
|
+
function esc(s) {
|
|
3
|
+
return s
|
|
4
|
+
.replace(/&/g, "&")
|
|
5
|
+
.replace(/</g, "<")
|
|
6
|
+
.replace(/>/g, ">")
|
|
7
|
+
.replace(/"/g, """);
|
|
8
|
+
}
|
|
9
|
+
function detailHtml(finding) {
|
|
10
|
+
const lines = [];
|
|
11
|
+
for (const d of finding.drag ?? []) {
|
|
12
|
+
lines.push(`Drags ${esc(d.constrainedPackage)}@${esc(d.installedVersion)} below fix ${esc(d.fixVersion)} - upgrade to ${esc(d.parentTargetVersion)}`);
|
|
13
|
+
}
|
|
14
|
+
if (finding.deprecated) {
|
|
15
|
+
lines.push(`npm deprecated: ${esc(finding.deprecated.message)}`);
|
|
16
|
+
}
|
|
17
|
+
if (finding.staleness) {
|
|
18
|
+
const year = new Date(finding.staleness.lastPublish).getUTCFullYear();
|
|
19
|
+
lines.push(`Last release: ${year} (${finding.staleness.ageYears} years ago)`);
|
|
20
|
+
}
|
|
21
|
+
if (lines.length === 0)
|
|
22
|
+
lines.push(esc(finding.message));
|
|
23
|
+
return lines.join("<br>");
|
|
24
|
+
}
|
|
25
|
+
export function renderMaintenanceFindingsHtml(findings) {
|
|
26
|
+
// undefined = maintenance risk was never requested -> render nothing, so a plain
|
|
27
|
+
// `cve-lite .` report shows no Maintenance risk panel at all. An empty array =
|
|
28
|
+
// it ran and found nothing -> render the "no findings" reassurance.
|
|
29
|
+
if (findings === undefined) {
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
if (findings.length === 0) {
|
|
33
|
+
return `
|
|
34
|
+
<section class="maintenance-risk">
|
|
35
|
+
<h2>Maintenance risk</h2>
|
|
36
|
+
<p>No maintenance risk findings.</p>
|
|
37
|
+
</section>
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
const sorted = [...findings].sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity));
|
|
41
|
+
const rows = sorted.map(f => ` <tr class="finding ${esc(f.severity)}">` +
|
|
42
|
+
`<td><span class="dep-node">${esc(f.ruleId)}</span></td>` +
|
|
43
|
+
`<td><div class="pkg-name">${esc(f.package.name)}</div><div class="pkg-version">${esc(f.package.version)}</div></td>` +
|
|
44
|
+
`<td><span class="sev-badge ${esc(f.severity)}">${esc(f.severity)}</span></td>` +
|
|
45
|
+
`<td>${detailHtml(f)}</td>` +
|
|
46
|
+
`</tr>`);
|
|
47
|
+
return `
|
|
48
|
+
<section class="maintenance-risk">
|
|
49
|
+
<h2>Maintenance risk</h2>
|
|
50
|
+
<table>
|
|
51
|
+
<thead>
|
|
52
|
+
<tr><th>Rule</th><th>Package</th><th>Severity</th><th>Details</th></tr>
|
|
53
|
+
</thead>
|
|
54
|
+
<tbody>
|
|
55
|
+
${rows.join("\n")}
|
|
56
|
+
</tbody>
|
|
57
|
+
</table>
|
|
58
|
+
</section>
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getCliVersion } from "../utils/version-info.js";
|
|
2
|
+
import { severityToSarifLevel } from "../utils/severity.js";
|
|
3
|
+
import { sarifFingerprintHash } from "../utils/sarif.js";
|
|
4
|
+
const DM_RULES = [
|
|
5
|
+
{
|
|
6
|
+
id: "DM001",
|
|
7
|
+
name: "Dependency maintenance risk",
|
|
8
|
+
shortDescription: "Parent dependency constraints block transitive CVE fix",
|
|
9
|
+
helpUri: "https://owasp.org/cve-lite-cli/docs/maintenance-risk/dm001",
|
|
10
|
+
},
|
|
11
|
+
];
|
|
12
|
+
const DM_RULE_INDEX = new Map(DM_RULES.map((r, i) => [r.id, i]));
|
|
13
|
+
export function buildMaintenanceSarifComponent() {
|
|
14
|
+
return {
|
|
15
|
+
name: "cve-lite-cli-maintenance",
|
|
16
|
+
version: getCliVersion(),
|
|
17
|
+
informationUri: "https://github.com/OWASP/cve-lite-cli",
|
|
18
|
+
rules: DM_RULES.map(r => ({
|
|
19
|
+
id: r.id,
|
|
20
|
+
name: r.name,
|
|
21
|
+
shortDescription: { text: r.shortDescription },
|
|
22
|
+
helpUri: r.helpUri,
|
|
23
|
+
})),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function buildMaintenanceSarifResults(findings, lockfileUri, toolComponentIndex = 0) {
|
|
27
|
+
return findings.map(f => {
|
|
28
|
+
const ruleIndex = DM_RULE_INDEX.get(f.ruleId);
|
|
29
|
+
if (ruleIndex === undefined) {
|
|
30
|
+
throw new Error(`DM_RULE_INDEX: unknown ruleId \"${f.ruleId}\" - add it to DM_RULES`);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
ruleId: f.ruleId,
|
|
34
|
+
ruleIndex,
|
|
35
|
+
rule: { id: f.ruleId, toolComponent: { index: toolComponentIndex } },
|
|
36
|
+
kind: "open",
|
|
37
|
+
level: severityToSarifLevel(f.severity),
|
|
38
|
+
message: { text: f.message },
|
|
39
|
+
locations: [
|
|
40
|
+
{
|
|
41
|
+
physicalLocation: {
|
|
42
|
+
artifactLocation: { uri: lockfileUri, uriBaseId: "%SRCROOT%" },
|
|
43
|
+
region: { startLine: 1 },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
partialFingerprints: {
|
|
48
|
+
primaryLocationLineHash: sarifFingerprintHash(`${f.ruleId}:${f.package.name}:${f.package.version}`),
|
|
49
|
+
},
|
|
50
|
+
properties: {
|
|
51
|
+
package: f.package.name,
|
|
52
|
+
version: f.package.version,
|
|
53
|
+
severity: f.severity,
|
|
54
|
+
...(f.staleness ? { lastPublish: f.staleness.lastPublish, ageYears: f.staleness.ageYears } : {}),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|