cve-lite-cli 1.8.0 → 1.9.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 +86 -41
- package/dist/cli/args.js +19 -0
- package/dist/cli/help.js +2 -0
- package/dist/index.js +24 -0
- package/dist/output/html-reporter.js +431 -0
- package/dist/output/logo-base64.js +1 -0
- package/dist/output/owasp-logo-base64.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { serializeFinding } from "./formatters.js";
|
|
5
|
+
import { LOGO_BASE64 } from "./logo-base64.js";
|
|
6
|
+
import { OWASP_LOGO_BASE64 } from "./owasp-logo-base64.js";
|
|
7
|
+
export function buildReportData(params) {
|
|
8
|
+
return {
|
|
9
|
+
projectPath: params.projectPath,
|
|
10
|
+
scannedAt: new Date().toISOString(),
|
|
11
|
+
cliVersion: params.cliVersion,
|
|
12
|
+
packageManager: params.packageManager,
|
|
13
|
+
lockfileSource: params.lockfileSource,
|
|
14
|
+
packageCount: params.packageCount,
|
|
15
|
+
findings: params.findings.map(serializeFinding),
|
|
16
|
+
suggestedFixCommands: params.suggestedFixCommands,
|
|
17
|
+
notes: params.notes,
|
|
18
|
+
warnings: params.warnings,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function renderHtmlReport(data) {
|
|
22
|
+
const projectName = path.basename(data.projectPath);
|
|
23
|
+
const scanDate = new Date(data.scannedAt).toLocaleString();
|
|
24
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
|
|
25
|
+
for (const f of data.findings) {
|
|
26
|
+
const sev = f.severity;
|
|
27
|
+
if (sev in counts)
|
|
28
|
+
counts[sev]++;
|
|
29
|
+
}
|
|
30
|
+
const fixPlanHtml = renderFixPlan(data.suggestedFixCommands);
|
|
31
|
+
const findingRowsHtml = data.findings.map(renderFindingRow).join("\n");
|
|
32
|
+
const dataJson = JSON.stringify(data)
|
|
33
|
+
.replace(/</g, "\\u003c")
|
|
34
|
+
.replace(/>/g, "\\u003e")
|
|
35
|
+
.replace(/&/g, "\\u0026")
|
|
36
|
+
.replace(/\u2028/g, "\\u2028")
|
|
37
|
+
.replace(/\u2029/g, "\\u2029");
|
|
38
|
+
return `<!DOCTYPE html>
|
|
39
|
+
<html lang="en">
|
|
40
|
+
<head>
|
|
41
|
+
<meta charset="UTF-8">
|
|
42
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
43
|
+
<title>CVE Lite — ${escapeHtml(projectName)}</title>
|
|
44
|
+
<style>
|
|
45
|
+
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
46
|
+
body{background:#0d1117;color:#e6edf3;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;font-size:14px;line-height:1.5}
|
|
47
|
+
.report-header{background:#161b22;border-bottom:1px solid #30363d;padding:14px 32px;display:flex;align-items:center;justify-content:space-between;gap:24px}
|
|
48
|
+
.header-left{display:flex;align-items:center;gap:20px}
|
|
49
|
+
.header-logo-pair{display:flex;align-items:center;gap:8px;background:#fff;border-radius:7px;padding:6px 12px}
|
|
50
|
+
.header-logo{height:26px;width:auto;display:block}
|
|
51
|
+
.header-logo-plus{font-size:15px;font-weight:700;color:#94a3b8;line-height:1;user-select:none}
|
|
52
|
+
.header-divider{width:1px;height:28px;background:#30363d}
|
|
53
|
+
.header-project .project-name{font-size:14px;font-weight:600;color:#e6edf3}
|
|
54
|
+
.header-project .project-meta{font-size:11px;color:#8b949e}
|
|
55
|
+
.header-right{display:flex;align-items:center;gap:20px}
|
|
56
|
+
.header-stats{display:flex;gap:16px;font-size:12px;color:#8b949e}
|
|
57
|
+
.header-stats span strong{color:#e6edf3}
|
|
58
|
+
.header-links{display:flex;gap:8px}
|
|
59
|
+
.header-link{display:flex;align-items:center;gap:5px;font-size:12px;color:#8b949e;text-decoration:none;background:#21262d;border:1px solid #30363d;border-radius:6px;padding:5px 10px}
|
|
60
|
+
.header-link:hover{color:#58a6ff;border-color:#58a6ff}
|
|
61
|
+
.header-link.owasp-link{color:#F68B1F;border-color:#F68B1F44}.header-link.owasp-link:hover{color:#F68B1F;border-color:#F68B1F;background:#F68B1F11}
|
|
62
|
+
.summary-bar{padding:20px 32px;display:flex;gap:12px;border-bottom:1px solid #21262d}
|
|
63
|
+
.sev-card{flex:1;background:#161b22;border:1px solid #30363d;border-radius:8px;padding:14px 16px;display:flex;flex-direction:column;gap:4px}
|
|
64
|
+
.sev-card .count{font-size:28px;font-weight:700;line-height:1}
|
|
65
|
+
.sev-card .label{font-size:11px;text-transform:uppercase;letter-spacing:.5px;color:#8b949e}
|
|
66
|
+
.sev-card.critical{border-top:3px solid #f85149}.sev-card.critical .count{color:#f85149}
|
|
67
|
+
.sev-card.high{border-top:3px solid #fb8500}.sev-card.high .count{color:#fb8500}
|
|
68
|
+
.sev-card.medium{border-top:3px solid #e3b341}.sev-card.medium .count{color:#e3b341}
|
|
69
|
+
.sev-card.low{border-top:3px solid #388bfd}.sev-card.low .count{color:#388bfd}
|
|
70
|
+
.sev-card.total{border-top:3px solid #30363d}.sev-card.total .count{color:#e6edf3}
|
|
71
|
+
.fix-plan{margin:24px 32px;background:#161b22;border:1px solid #30363d;border-radius:8px;overflow:hidden}
|
|
72
|
+
.fix-plan-header{padding:14px 18px;background:#1c2128;border-bottom:1px solid #30363d;display:flex;align-items:center;justify-content:space-between}
|
|
73
|
+
.fix-plan-header h2{font-size:13px;font-weight:600;color:#e6edf3;display:flex;align-items:center;gap:8px}
|
|
74
|
+
.fix-plan-header h2 .icon{color:#3fb950}
|
|
75
|
+
.fix-plan-header .badge{font-size:11px;background:#1f6feb33;color:#58a6ff;border:1px solid #1f6feb66;border-radius:12px;padding:2px 8px}
|
|
76
|
+
.fix-commands{padding:16px 18px;display:flex;flex-direction:column;gap:10px}
|
|
77
|
+
.skipped-toggle{font-size:11px;background:none;border:none;color:#58a6ff;cursor:pointer;padding:0;text-decoration:underline;text-underline-offset:2px}
|
|
78
|
+
.skipped-toggle:hover{color:#79c0ff}
|
|
79
|
+
.skipped-section{display:none;border-top:1px solid #21262d;padding:12px 18px;flex-direction:column;gap:6px}
|
|
80
|
+
.skipped-section.open{display:flex}
|
|
81
|
+
.skipped-row{display:grid;grid-template-columns:180px 80px 1fr;gap:8px;font-size:11px;padding:5px 8px;border-radius:4px;background:#0d1117;border:1px solid #21262d}
|
|
82
|
+
.skipped-pkg{font-family:'SF Mono','Cascadia Code','Fira Code',monospace;color:#8b949e}
|
|
83
|
+
.skipped-rel{color:#8b949e}
|
|
84
|
+
.skipped-rel.direct{color:#3fb950}
|
|
85
|
+
.skipped-rel.transitive{color:#e3b341}
|
|
86
|
+
.skipped-reason{color:#6b7280}
|
|
87
|
+
.fix-cmd{display:flex;align-items:center;gap:12px;background:#0d1117;border:1px solid #30363d;border-radius:6px;padding:10px 14px}
|
|
88
|
+
.fix-cmd .cmd-text{flex:1;font-family:'SF Mono','Cascadia Code','Fira Code',monospace;font-size:12px;color:#3fb950}
|
|
89
|
+
.fix-cmd .cmd-meta{font-size:11px;color:#8b949e;white-space:nowrap}
|
|
90
|
+
.fix-cmd .copy-btn{font-size:11px;color:#8b949e;background:#21262d;border:1px solid #30363d;border-radius:4px;padding:3px 8px;cursor:pointer}
|
|
91
|
+
.fix-cmd .copy-btn:hover{color:#e6edf3;background:#30363d}
|
|
92
|
+
.findings-section{margin:0 32px 32px}
|
|
93
|
+
.findings-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
|
|
94
|
+
.findings-header h2{font-size:13px;font-weight:600;color:#e6edf3}
|
|
95
|
+
.filter-bar{display:flex;gap:6px}
|
|
96
|
+
.filter-btn{font-size:11px;border-radius:20px;padding:4px 12px;border:1px solid #30363d;background:transparent;color:#8b949e;cursor:pointer}
|
|
97
|
+
.filter-btn:hover{border-color:#58a6ff;color:#58a6ff}
|
|
98
|
+
.filter-btn.active{background:#1f6feb22;border-color:#58a6ff;color:#58a6ff}
|
|
99
|
+
.findings-table{width:100%;border-collapse:collapse}
|
|
100
|
+
.findings-table thead th{text-align:left;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;color:#8b949e;padding:10px 14px;border-bottom:1px solid #21262d;background:#161b22;cursor:pointer;white-space:nowrap;user-select:none}
|
|
101
|
+
.findings-table thead th:hover{color:#e6edf3}
|
|
102
|
+
.findings-table thead th.sorted .sort-arrow{color:#58a6ff}
|
|
103
|
+
.findings-table thead th .sort-arrow{color:#30363d;margin-left:4px}
|
|
104
|
+
.findings-table tbody tr{border-bottom:1px solid #21262d;cursor:pointer}
|
|
105
|
+
.findings-table tbody tr:hover{background:#161b22}
|
|
106
|
+
.findings-table tbody tr.is-expanded{background:#161b22}
|
|
107
|
+
.findings-table tbody td{padding:11px 14px;vertical-align:middle}
|
|
108
|
+
.pkg-name{font-weight:500;color:#58a6ff;font-size:13px}
|
|
109
|
+
.pkg-version{font-size:11px;color:#8b949e}
|
|
110
|
+
.sev-badge{display:inline-block;font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.4px;padding:2px 7px;border-radius:4px}
|
|
111
|
+
.sev-badge.critical{background:#f8514922;color:#f85149;border:1px solid #f8514966}
|
|
112
|
+
.sev-badge.high{background:#fb850022;color:#fb8500;border:1px solid #fb850066}
|
|
113
|
+
.sev-badge.medium{background:#e3b34122;color:#e3b341;border:1px solid #e3b34166}
|
|
114
|
+
.sev-badge.low{background:#388bfd22;color:#388bfd;border:1px solid #388bfd66}
|
|
115
|
+
.sev-badge.unknown{background:#8b949e22;color:#8b949e;border:1px solid #8b949e66}
|
|
116
|
+
.rel-badge{font-size:11px;padding:2px 7px;border-radius:4px}
|
|
117
|
+
.rel-badge.direct{color:#3fb950;background:#3fb95022}
|
|
118
|
+
.rel-badge.transitive{color:#e3b341;background:#e3b34122}
|
|
119
|
+
.rel-badge.unknown{color:#8b949e;background:#8b949e22}
|
|
120
|
+
.cve-link{font-size:11px;color:#58a6ff;font-family:monospace;text-decoration:none;border-bottom:1px dotted #58a6ff66}
|
|
121
|
+
.cve-link:hover{color:#79c0ff}
|
|
122
|
+
.fix-hint{font-size:11px;color:#3fb950;font-family:monospace}
|
|
123
|
+
.fix-hint.none{color:#8b949e}
|
|
124
|
+
.expand-icon{color:#8b949e;font-size:10px}
|
|
125
|
+
.detail-row{background:#0d1117;border-top:1px solid #21262d;display:none}
|
|
126
|
+
.detail-row.visible{display:table-row}
|
|
127
|
+
.detail-row td{padding:0!important}
|
|
128
|
+
.expanded-inner{padding:16px 20px 20px 48px;display:flex;gap:32px}
|
|
129
|
+
.detail-col{flex:1}
|
|
130
|
+
.detail-col h4{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;color:#8b949e;margin-bottom:8px}
|
|
131
|
+
.detail-col p{font-size:12px;color:#8b949e;line-height:1.6}
|
|
132
|
+
.dep-path{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
|
|
133
|
+
.dep-node{font-size:11px;font-family:monospace;background:#161b22;border:1px solid #30363d;border-radius:4px;padding:2px 8px;color:#e6edf3}
|
|
134
|
+
.dep-node.vulnerable{border-color:#f85149;color:#f85149}
|
|
135
|
+
.dep-arrow{color:#8b949e;font-size:11px}
|
|
136
|
+
.fix-cmd-inline{display:flex;align-items:center;gap:8px;background:#161b22;border:1px solid #30363d;border-radius:6px;padding:8px 12px;margin-top:4px}
|
|
137
|
+
.fix-cmd-inline code{flex:1;font-family:monospace;font-size:12px;color:#3fb950}
|
|
138
|
+
.fix-cmd-inline .copy-btn{font-size:11px;color:#8b949e;background:#21262d;border:1px solid #30363d;border-radius:4px;padding:3px 8px;cursor:pointer}
|
|
139
|
+
.report-footer{margin:0 32px 32px;padding:12px 0;border-top:1px solid #21262d;display:flex;justify-content:space-between;font-size:11px;color:#8b949e}
|
|
140
|
+
</style>
|
|
141
|
+
</head>
|
|
142
|
+
<body>
|
|
143
|
+
|
|
144
|
+
<div class="report-header">
|
|
145
|
+
<div class="header-left">
|
|
146
|
+
<div class="header-logo-pair">
|
|
147
|
+
<img src="${LOGO_BASE64}" alt="CVE Lite" class="header-logo" />
|
|
148
|
+
<span class="header-logo-plus">+</span>
|
|
149
|
+
<a href="https://owasp.org/cve-lite-cli/" target="_blank" rel="noopener" style="display:flex;align-items:center">
|
|
150
|
+
<img src="${OWASP_LOGO_BASE64}" alt="An OWASP Foundation Project" class="header-logo" />
|
|
151
|
+
</a>
|
|
152
|
+
</div>
|
|
153
|
+
<div class="header-divider"></div>
|
|
154
|
+
<div class="header-project">
|
|
155
|
+
<span class="project-name">${escapeHtml(projectName)}</span>
|
|
156
|
+
<span class="project-meta">${escapeHtml(data.packageManager)} · ${escapeHtml(data.lockfileSource)} · ${escapeHtml(scanDate)}</span>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
<div class="header-right">
|
|
160
|
+
<div class="header-stats">
|
|
161
|
+
<span><strong>${data.packageCount}</strong> packages</span>
|
|
162
|
+
<span><strong>${data.findings.length}</strong> findings</span>
|
|
163
|
+
</div>
|
|
164
|
+
<div class="header-links">
|
|
165
|
+
<a class="header-link owasp-link" href="https://owasp.org/cve-lite-cli/" target="_blank"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 261.49332 261.50668" width="16" height="16" style="flex-shrink:0"><g transform="matrix(1.3333333,0,0,-1.3333333,0,261.50667)"><g transform="scale(0.1)"><path fill="#F68B1F" d="M 980.629,0 C 439.043,0 0,439.051 0,980.637 0,1522.22 439.043,1961.27 980.629,1961.27 1522.2,1961.27 1961.25,1522.22 1961.25,980.637 1961.25,439.051 1522.2,0 980.629,0 m -0.008,1810.35 c -458.226,0 -829.707,-371.48 -829.707,-829.705 0,-458.235 371.481,-829.715 829.707,-829.715 458.219,0 829.699,371.48 829.699,829.715 0,458.225 -371.48,829.705 -829.699,829.705"/><path fill="#F68B1F" d="m 1299.1,285.75 c -31.36,0.02 -145.64,203.41 -161,261.398 -32.11,121.411 -25.2,172.704 -23.28,189.102 5.88,50.07 54.46,75.09 57.4,142.801 0.91,20.91 11.47,125.449 19.9,207.109 -20.8,4.07 -41.52,13.45 -59.94,28 55.3,-74.17 -26.09,-163.058 -144.352,-281.332 C 862.305,707.309 583.695,590.809 583.695,590.809 c 0,0 116.508,278.613 242.024,404.132 92.269,92.259 166.636,162.079 230.101,162.079 17.89,0 34.92,-5.55 51.23,-17.7 -14.56,18.41 -23.93,39.12 -28.01,59.92 -81.661,-8.45 -186.208,-18.99 -207.106,-19.91 -67.719,-2.94 -92.743,-51.52 -142.782,-57.39 -5.761,-0.68 -15.828,-1.98 -31.722,-1.98 -29.367,0 -78.629,4.42 -157.387,25.27 -63.07,16.68 -298.078,150.37 -256.512,167.17 21.196,8.58 88.75,14.38 177.715,14.38 85.559,0 190.922,-5.36 293.844,-18.77 128.328,-16.72 246,-37.87 326.19,-53.6 1.3,4.31 2.86,8.5 4.73,12.57 l -81.98,39.29 c 0,0 -65.479,75.14 -58.487,80.32 0.27,0.2 0.613,0.3 1.023,0.3 10.27,0 62.654,-59.89 67.694,-66.71 3.88,-1.29 26.09,-8.7 49.45,-16.47 l -23.19,20.28 c 0,0 -31.74,117.55 -23.47,120.32 0.1,0.03 0.21,0.05 0.33,0.05 8.71,0 37.51,-102.22 39.98,-109.56 5.66,-4.96 24.78,-12.41 48.67,-26.19 l -25.12,64.62 c 0,0 11.37,106.61 19.88,106.61 0.07,0 0.13,-0.01 0.2,-0.02 8.57,-1.71 -1.68,-88.92 -3.85,-99.78 3.11,-4.77 22.38,-34.33 41.7,-63.97 11.89,4.48 24.68,6.69 37.81,6.69 15.07,0 30.57,-2.92 45.61,-8.67 -19.26,41.01 -17.8,83.75 7.74,109.27 8.08,8.1 17.9,13.75 28.84,17.1 1.32,7.46 4.78,14.54 10.45,20.22 7.39,7.38 17.12,11.05 26.97,11.05 10.31,0 20.76,-4.03 28.76,-12.04 7.67,-7.65 11.65,-17.54 11.99,-27.39 12.33,25.41 26.88,59.7 25.86,70.81 -2.37,25.14 -31.53,69.64 -31.8,70.09 -1.9,2.87 -1.11,6.75 1.78,8.66 1.05,0.69 2.24,1.02 3.42,1.02 2.03,0 4.02,-0.99 5.21,-2.82 1.29,-1.92 31.17,-47.54 33.83,-75.79 1.48,-16.16 -17.07,-56.88 -27.18,-77.68 14.2,-7.77 28.04,-18.03 40.68,-30.67 12.63,-12.63 22.89,-26.47 30.67,-40.68 20.01,9.73 58.4,27.26 75.71,27.26 0.69,0 1.35,-0.02 1.97,-0.08 28.24,-2.66 73.87,-32.54 75.78,-33.81 2.88,-1.89 3.68,-5.77 1.78,-8.65 -1.2,-1.82 -3.19,-2.81 -5.22,-2.81 -1.17,0 -2.36,0.33 -3.41,1.03 -0.45,0.29 -44.94,29.44 -70.09,31.79 -0.38,0.04 -0.79,0.05 -1.22,0.05 -12.23,0 -45.07,-13.97 -69.61,-25.89 9.87,-0.33 19.76,-4.33 27.4,-12 15.67,-15.65 16.1,-40.59 0.99,-55.7 -5.67,-5.68 -12.74,-9.17 -20.2,-10.47 -3.37,-10.95 -9.03,-20.77 -17.11,-28.85 -14.08,-14.09 -33.38,-20.84 -54.76,-20.84 -17.38,0 -36.13,4.47 -54.52,13.1 10.77,-28.12 11.59,-57.89 1.99,-83.41 29.62,-19.32 59.22,-38.6 63.96,-41.71 7.78,1.55 54.5,7.22 81.17,7.22 10.66,0 18.13,-0.9 18.61,-3.34 1.73,-8.56 -106.57,-20.12 -106.57,-20.12 l -64.63,25.15 c 13.79,-23.91 21.21,-43.02 26.18,-48.69 7.47,-2.5 112.26,-32.04 109.5,-40.31 -0.31,-0.96 -2.15,-1.37 -5.16,-1.37 -23.1,0 -115.14,24.85 -115.14,24.85 l -20.3,23.19 c 7.79,-23.37 15.18,-45.56 16.49,-49.45 7.1,-5.25 71.57,-61.7 66.4,-68.708 -0.27,-0.363 -0.71,-0.524 -1.32,-0.524 -11.31,0 -78.99,58.992 -78.99,58.992 l -39.3,81.99 c -4.06,-1.88 -8.26,-3.42 -12.58,-4.73 15.73,-80.19 36.89,-197.861 53.63,-326.181 27.34,-209.949 21.19,-429.969 4.39,-471.571 -1.35,-3.347 -3.46,-4.898 -6.2,-4.898"/></g></g></svg> An OWASP Foundation Project</a>
|
|
166
|
+
<a class="header-link" href="https://github.com/OWASP/cve-lite-cli" target="_blank">
|
|
167
|
+
<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
|
|
168
|
+
GitHub
|
|
169
|
+
</a>
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
<div class="summary-bar">
|
|
175
|
+
<div class="sev-card critical"><span class="count">${counts.critical}</span><span class="label">Critical</span></div>
|
|
176
|
+
<div class="sev-card high"><span class="count">${counts.high}</span><span class="label">High</span></div>
|
|
177
|
+
<div class="sev-card medium"><span class="count">${counts.medium}</span><span class="label">Medium</span></div>
|
|
178
|
+
<div class="sev-card low"><span class="count">${counts.low}</span><span class="label">Low</span></div>
|
|
179
|
+
<div class="sev-card total"><span class="count">${data.findings.length}</span><span class="label">Total</span></div>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
${fixPlanHtml}
|
|
183
|
+
|
|
184
|
+
<div class="findings-section">
|
|
185
|
+
<div class="findings-header">
|
|
186
|
+
<h2>Findings</h2>
|
|
187
|
+
<div class="filter-bar">
|
|
188
|
+
<button class="filter-btn active" onclick="setFilter('all',this)">All (${data.findings.length})</button>
|
|
189
|
+
<button class="filter-btn" onclick="setFilter('critical',this)">Critical (${counts.critical})</button>
|
|
190
|
+
<button class="filter-btn" onclick="setFilter('high',this)">High (${counts.high})</button>
|
|
191
|
+
<button class="filter-btn" onclick="setFilter('medium',this)">Medium (${counts.medium})</button>
|
|
192
|
+
<button class="filter-btn" onclick="setFilter('direct',this)">Direct only</button>
|
|
193
|
+
</div>
|
|
194
|
+
</div>
|
|
195
|
+
<table class="findings-table" id="findings-table">
|
|
196
|
+
<thead>
|
|
197
|
+
<tr>
|
|
198
|
+
<th style="width:32px"></th>
|
|
199
|
+
<th onclick="sortBy('package')">Package <span class="sort-arrow">↕</span></th>
|
|
200
|
+
<th onclick="sortBy('severity')" class="sorted">Severity <span class="sort-arrow" style="color:#58a6ff">↓</span></th>
|
|
201
|
+
<th onclick="sortBy('relationship')">Type <span class="sort-arrow">↕</span></th>
|
|
202
|
+
<th>CVE / Advisory</th>
|
|
203
|
+
<th>Fix available</th>
|
|
204
|
+
</tr>
|
|
205
|
+
</thead>
|
|
206
|
+
<tbody id="findings-tbody">
|
|
207
|
+
${findingRowsHtml}
|
|
208
|
+
</tbody>
|
|
209
|
+
</table>
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
<div class="report-footer">
|
|
213
|
+
<span>Generated by <strong>cve-lite v${escapeHtml(data.cliVersion)}</strong></span>
|
|
214
|
+
<span>${escapeHtml(data.lockfileSource)} · ${data.findings.length} findings · ${data.packageCount} packages</span>
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
<script>
|
|
218
|
+
const reportData = ${dataJson};
|
|
219
|
+
const SEV_ORDER = {critical:5,high:4,medium:3,low:2,unknown:1,none:0};
|
|
220
|
+
let sortCol = 'severity';
|
|
221
|
+
let sortAsc = false;
|
|
222
|
+
let activeFilter = 'all';
|
|
223
|
+
|
|
224
|
+
function toggleRow(idx) {
|
|
225
|
+
const detail = document.getElementById('detail-' + idx);
|
|
226
|
+
const mainRow = document.getElementById('row-' + idx);
|
|
227
|
+
const icon = document.getElementById('icon-' + idx);
|
|
228
|
+
if (!detail) return;
|
|
229
|
+
const isVisible = detail.classList.contains('visible');
|
|
230
|
+
detail.classList.toggle('visible', !isVisible);
|
|
231
|
+
mainRow.classList.toggle('is-expanded', !isVisible);
|
|
232
|
+
icon.textContent = isVisible ? '▶' : '▼';
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function setFilter(filter, btn) {
|
|
236
|
+
activeFilter = filter;
|
|
237
|
+
document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
|
|
238
|
+
btn.classList.add('active');
|
|
239
|
+
applyFilter();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function applyFilter() {
|
|
243
|
+
reportData.findings.forEach((f, i) => {
|
|
244
|
+
const mainRow = document.getElementById('row-' + i);
|
|
245
|
+
const detailRow = document.getElementById('detail-' + i);
|
|
246
|
+
let visible = true;
|
|
247
|
+
if (activeFilter === 'critical') visible = f.severity === 'critical';
|
|
248
|
+
else if (activeFilter === 'high') visible = f.severity === 'high';
|
|
249
|
+
else if (activeFilter === 'medium') visible = f.severity === 'medium';
|
|
250
|
+
else if (activeFilter === 'direct') visible = f.relationship === 'direct';
|
|
251
|
+
if (mainRow) mainRow.style.display = visible ? '' : 'none';
|
|
252
|
+
if (detailRow && !visible) {
|
|
253
|
+
detailRow.classList.remove('visible');
|
|
254
|
+
if (mainRow) mainRow.classList.remove('is-expanded');
|
|
255
|
+
const icon = document.getElementById('icon-' + i);
|
|
256
|
+
if (icon) icon.textContent = '▶';
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function sortBy(col) {
|
|
262
|
+
if (sortCol === col) { sortAsc = !sortAsc; } else { sortCol = col; sortAsc = col === 'package'; }
|
|
263
|
+
document.querySelectorAll('.findings-table thead th').forEach(th => th.classList.remove('sorted'));
|
|
264
|
+
const colIndex = ['', 'package', 'severity', 'relationship'].indexOf(col);
|
|
265
|
+
if (colIndex > 0) document.querySelectorAll('.findings-table thead th')[colIndex].classList.add('sorted');
|
|
266
|
+
|
|
267
|
+
const tbody = document.getElementById('findings-tbody');
|
|
268
|
+
const indexedFindings = reportData.findings.map((f, i) => ({ f, i }));
|
|
269
|
+
indexedFindings.sort((a, b) => {
|
|
270
|
+
let cmp = 0;
|
|
271
|
+
if (col === 'package') cmp = a.f.package.localeCompare(b.f.package);
|
|
272
|
+
else if (col === 'severity') cmp = (SEV_ORDER[b.f.severity] || 0) - (SEV_ORDER[a.f.severity] || 0);
|
|
273
|
+
else if (col === 'relationship') cmp = a.f.relationship.localeCompare(b.f.relationship);
|
|
274
|
+
return sortAsc ? -cmp : cmp;
|
|
275
|
+
});
|
|
276
|
+
indexedFindings.forEach(({ i }) => {
|
|
277
|
+
const mainRow = document.getElementById('row-' + i);
|
|
278
|
+
const detailRow = document.getElementById('detail-' + i);
|
|
279
|
+
if (mainRow) tbody.appendChild(mainRow);
|
|
280
|
+
if (detailRow) tbody.appendChild(detailRow);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function copyText(text) {
|
|
285
|
+
navigator.clipboard.writeText(text).catch(() => {});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function toggleSkipped() {
|
|
289
|
+
const section = document.getElementById('skipped-section');
|
|
290
|
+
if (!section) return;
|
|
291
|
+
const isOpen = section.classList.toggle('open');
|
|
292
|
+
document.querySelectorAll('.skipped-toggle').forEach(btn => {
|
|
293
|
+
btn.textContent = (isOpen ? '↑' : '↓') + btn.textContent.slice(1);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
document.addEventListener('click', function(e) {
|
|
298
|
+
const btn = e.target.closest('.copy-btn');
|
|
299
|
+
if (btn && btn.dataset.cmd !== undefined) {
|
|
300
|
+
e.stopPropagation();
|
|
301
|
+
copyText(btn.dataset.cmd);
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
</script>
|
|
305
|
+
</body>
|
|
306
|
+
</html>`;
|
|
307
|
+
}
|
|
308
|
+
function escapeHtml(str) {
|
|
309
|
+
return str
|
|
310
|
+
.replace(/&/g, "&")
|
|
311
|
+
.replace(/</g, "<")
|
|
312
|
+
.replace(/>/g, ">")
|
|
313
|
+
.replace(/"/g, """);
|
|
314
|
+
}
|
|
315
|
+
function advisoryLink(id) {
|
|
316
|
+
if (id.startsWith("GHSA-")) {
|
|
317
|
+
return `<a class="cve-link" href="https://github.com/advisories/${escapeHtml(id)}" target="_blank">${escapeHtml(id)}</a>`;
|
|
318
|
+
}
|
|
319
|
+
return `<a class="cve-link" href="https://osv.dev/vulnerability/${escapeHtml(id)}" target="_blank">${escapeHtml(id)}</a>`;
|
|
320
|
+
}
|
|
321
|
+
function renderFindingRow(finding, idx) {
|
|
322
|
+
const cveLinks = finding.cves.length > 0
|
|
323
|
+
? finding.cves.map(advisoryLink).join(", ")
|
|
324
|
+
: finding.vulnerabilities.map(v => advisoryLink(v.id)).join(", ");
|
|
325
|
+
const fixHtml = finding.validatedFirstFixedVersion
|
|
326
|
+
? `<span class="fix-hint">${escapeHtml(finding.validatedFirstFixedVersion)}</span>`
|
|
327
|
+
: finding.firstFixedVersion
|
|
328
|
+
? `<span class="fix-hint">${escapeHtml(finding.firstFixedVersion)}</span>`
|
|
329
|
+
: `<span class="fix-hint none">—</span>`;
|
|
330
|
+
const depPathHtml = finding.dependencyPaths.length > 0
|
|
331
|
+
? finding.dependencyPaths[0].map((node, i, arr) => {
|
|
332
|
+
const isLast = i === arr.length - 1;
|
|
333
|
+
return `<span class="dep-node${isLast ? " vulnerable" : ""}">${escapeHtml(node)}</span>${isLast ? "" : '<span class="dep-arrow">→</span>'}`;
|
|
334
|
+
}).join("")
|
|
335
|
+
: `<span class="dep-node">${escapeHtml(finding.package)}</span>`;
|
|
336
|
+
const fixCommand = finding.recommendedAction ?? "";
|
|
337
|
+
const description = finding.vulnerabilities[0]?.summary ?? "";
|
|
338
|
+
return ` <tr id="row-${idx}" onclick="toggleRow(${idx})">
|
|
339
|
+
<td><span class="expand-icon" id="icon-${idx}">▶</span></td>
|
|
340
|
+
<td><div class="pkg-name">${escapeHtml(finding.package)}</div><div class="pkg-version">${escapeHtml(finding.version)}</div></td>
|
|
341
|
+
<td><span class="sev-badge ${escapeHtml(finding.severity)}">${escapeHtml(finding.severity)}</span></td>
|
|
342
|
+
<td><span class="rel-badge ${escapeHtml(finding.relationship)}">${escapeHtml(finding.relationship)}</span></td>
|
|
343
|
+
<td>${cveLinks}</td>
|
|
344
|
+
<td>${fixHtml}</td>
|
|
345
|
+
</tr>
|
|
346
|
+
<tr id="detail-${idx}" class="detail-row">
|
|
347
|
+
<td colspan="6">
|
|
348
|
+
<div class="expanded-inner">
|
|
349
|
+
<div class="detail-col" style="max-width:320px">
|
|
350
|
+
<h4>Description</h4>
|
|
351
|
+
<p>${escapeHtml(description)}</p>
|
|
352
|
+
</div>
|
|
353
|
+
<div class="detail-col" style="max-width:320px">
|
|
354
|
+
<h4>Dependency path</h4>
|
|
355
|
+
<div class="dep-path">${depPathHtml}</div>
|
|
356
|
+
</div>
|
|
357
|
+
<div class="detail-col">
|
|
358
|
+
<h4>Recommended action</h4>
|
|
359
|
+
<div class="fix-cmd-inline">
|
|
360
|
+
<code>${escapeHtml(fixCommand)}</code>
|
|
361
|
+
<button class="copy-btn" data-cmd="${escapeHtml(fixCommand)}">Copy</button>
|
|
362
|
+
</div>
|
|
363
|
+
</div>
|
|
364
|
+
</div>
|
|
365
|
+
</td>
|
|
366
|
+
</tr>`;
|
|
367
|
+
}
|
|
368
|
+
function renderFixPlan(plan) {
|
|
369
|
+
if (!plan || plan.sections.length === 0)
|
|
370
|
+
return "";
|
|
371
|
+
const directCount = plan.targets.filter(t => t.kind === "direct").length;
|
|
372
|
+
const skippedCount = plan.skipped.length;
|
|
373
|
+
const commandRows = plan.sections.map(section => `
|
|
374
|
+
<div class="fix-cmd">
|
|
375
|
+
<span class="cmd-text">${escapeHtml(section.command)}</span>
|
|
376
|
+
<span class="cmd-meta">${escapeHtml(section.title)}</span>
|
|
377
|
+
<button class="copy-btn" data-cmd="${escapeHtml(section.command)}">Copy</button>
|
|
378
|
+
</div>`).join("\n");
|
|
379
|
+
const skippedRows = plan.skipped.map(s => `
|
|
380
|
+
<div class="skipped-row">
|
|
381
|
+
<span class="skipped-pkg">${escapeHtml(s.package)}@${escapeHtml(s.version)}</span>
|
|
382
|
+
<span class="skipped-rel ${escapeHtml(s.relationship)}">${escapeHtml(s.relationship)}</span>
|
|
383
|
+
<span class="skipped-reason">${escapeHtml(s.reason)}</span>
|
|
384
|
+
</div>`).join("\n");
|
|
385
|
+
const skippedSection = skippedCount > 0 ? `
|
|
386
|
+
<div class="skipped-section" id="skipped-section">
|
|
387
|
+
<div style="font-size:11px;font-weight:600;color:#8b949e;text-transform:uppercase;letter-spacing:.4px;margin-bottom:4px">Why were these skipped?</div>
|
|
388
|
+
${skippedRows}
|
|
389
|
+
</div>` : "";
|
|
390
|
+
const skippedBadgePart = skippedCount > 0
|
|
391
|
+
? ` · <button class="skipped-toggle" onclick="toggleSkipped()">↓ ${skippedCount} skipped</button>`
|
|
392
|
+
: "";
|
|
393
|
+
return `<div class="fix-plan">
|
|
394
|
+
<div class="fix-plan-header">
|
|
395
|
+
<h2><span class="icon">✦</span> Suggested Fix Plan</h2>
|
|
396
|
+
<span class="badge">${directCount} direct fix${directCount === 1 ? "" : "es"}${skippedBadgePart}</span>
|
|
397
|
+
</div>
|
|
398
|
+
<div class="fix-commands">${commandRows}
|
|
399
|
+
</div>${skippedSection}
|
|
400
|
+
</div>`;
|
|
401
|
+
}
|
|
402
|
+
export async function writeHtmlReport(params) {
|
|
403
|
+
fs.mkdirSync(params.outputDir, { recursive: true });
|
|
404
|
+
const indexPath = path.join(params.outputDir, "index.html");
|
|
405
|
+
const jsonPath = path.join(params.outputDir, "report.json");
|
|
406
|
+
fs.writeFileSync(jsonPath, JSON.stringify(params.data, null, 2), "utf8");
|
|
407
|
+
fs.writeFileSync(indexPath, renderHtmlReport(params.data), "utf8");
|
|
408
|
+
if (params.autoOpen) {
|
|
409
|
+
await openInBrowser(indexPath);
|
|
410
|
+
}
|
|
411
|
+
return { reportPath: indexPath };
|
|
412
|
+
}
|
|
413
|
+
async function openInBrowser(filePath) {
|
|
414
|
+
if (!path.isAbsolute(filePath))
|
|
415
|
+
return;
|
|
416
|
+
const cmd = process.platform === "darwin"
|
|
417
|
+
? "open"
|
|
418
|
+
: process.platform === "win32"
|
|
419
|
+
? "cmd"
|
|
420
|
+
: "xdg-open";
|
|
421
|
+
const args = process.platform === "win32"
|
|
422
|
+
? ["/c", "start", "", filePath]
|
|
423
|
+
: [filePath];
|
|
424
|
+
return new Promise(resolve => {
|
|
425
|
+
const child = spawn(cmd, args, { stdio: "ignore", detached: true, shell: false });
|
|
426
|
+
child.unref();
|
|
427
|
+
const timer = setTimeout(resolve, 1500);
|
|
428
|
+
child.on("error", () => { clearTimeout(timer); resolve(); });
|
|
429
|
+
child.on("close", () => { clearTimeout(timer); resolve(); });
|
|
430
|
+
});
|
|
431
|
+
}
|