cve-lite-cli 1.18.1 → 1.19.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/index.js +13 -1
- package/dist/learn/keypress.js +50 -0
- package/dist/learn/runner.js +96 -0
- package/dist/learn/scenario.js +47 -0
- package/dist/learn/session.js +36 -0
- package/dist/learn/types.js +1 -0
- package/dist/output/debug.js +38 -0
- package/dist/output/finding-display.js +30 -0
- package/dist/output/html-reporter.js +33 -32
- package/dist/output/multi-folder-html-reporter.js +323 -0
- package/dist/output/multi-folder-printer.js +46 -0
- package/dist/output/printers.js +4 -4
- package/dist/parsers/multi-package.js +58 -0
- package/dist/remediation/fix-commands.js +8 -0
- package/dist/scan/multi-folder-scan.js +97 -0
- package/dist/utils/update-check.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -212,8 +212,9 @@ CVE Lite CLI has been evaluated against real open-source projects to verify that
|
|
|
212
212
|
- [Ghost](https://owasp.org/cve-lite-cli/docs/case-studies/ghost) — 26 vulnerable packages across 4,447 resolved in a professionally maintained CMS — every one transitive, including a critical XSS in the library responsible for making user content safe
|
|
213
213
|
- [Astro](https://owasp.org/cve-lite-cli/docs/case-studies/astro) — verified baseline scan of a modern pnpm monorepo (2,228 packages, 34 findings at revision `221bb4b`) with a critical transitive SDK chain and four generated fix command groups
|
|
214
214
|
- [Turborepo](https://owasp.org/cve-lite-cli/docs/case-studies/turborepo) — verified baseline scan of a build-system pnpm monorepo (1,776 packages, 13 findings at revision `c85d410`) with a critical no-fix sandbox beta, all-transitive risk, and zero auto-generated fix commands on this snapshot
|
|
215
|
+
- [Visual Studio Code](https://owasp.org/cve-lite-cli/docs/case-studies/vscode) — verified baseline scan of the VS Code root npm lockfile (1,374 packages, 9 findings at revision `bc678ca`) with two direct Anthropic SDK advisories, a high-severity gulp toolchain chain, and two generated fix command groups
|
|
215
216
|
|
|
216
|
-
In-repo lockfile fixtures for Astro and
|
|
217
|
+
In-repo lockfile fixtures for Astro, Turborepo, and Visual Studio Code live under [`examples/`](examples/readme.md) — clone the repo and scan immediately without downloading full upstream checkouts.
|
|
217
218
|
|
|
218
219
|
These are not demos. They are documented scans against real codebases with real findings, recorded before and after applying fix commands.
|
|
219
220
|
|
|
@@ -229,6 +230,7 @@ If you maintain an open-source JavaScript or TypeScript project and want CVE Lit
|
|
|
229
230
|
- **[As AI speeds coding, CVE Lite CLI keeps security deliberately AI-free](https://www.csoonline.com/article/4176701/as-ai-speeds-coding-cve-lite-cli-keeps-security-deliberately-ai-free.html)** — CSO Online (Shweta Sharma), May 2026
|
|
230
231
|
- **[CVE Lite CLI: The Dependency Scanner That Actually Tells You What to Run](https://medium.com/@techlatest.net/cve-lite-cli-the-dependency-scanner-that-actually-tells-you-what-to-run-not-just-whats-broken-f6b518199981)** — Medium (TechLatest.Net), May 2026
|
|
231
232
|
- **[AI Security Is Changing Fast — These 6 Open-Source Tools Prove It](https://medium.com/@techlatest.net/ai-security-is-changing-fast-these-6-open-source-tools-prove-it-5c5c9081cff7)** — Medium (TechLatest.Net), May 2026
|
|
233
|
+
- **[Hottest cybersecurity open-source tools of the month: May 2026](https://www.helpnetsecurity.com/2026/05/28/hottest-cybersecurity-open-source-tools-of-the-month-may-2026/)** — Help Net Security Monthly Roundup, May 2026
|
|
232
234
|
- **[CVE Lite CLI: Open-source dependency vulnerability scanner](https://www.helpnetsecurity.com/2026/05/20/cve-lite-cli-open-source-dependency-vulnerability-scanner/)** — Help Net Security, May 2026
|
|
233
235
|
- **[Review of CVE Lite CLI](https://developmentcurated.com/testing-and-security/review-of-cve-lite-cli/)** — Development Curated (Sebastian Raiffen, IT Security Consultant), April 2026
|
|
234
236
|
|
package/dist/index.js
CHANGED
|
@@ -21,12 +21,15 @@ import { formatAdvisorySourceLine, logInfo, logWarn, printCacheSummary, sortFind
|
|
|
21
21
|
import { countBySeverity } from "./utils/severity.js";
|
|
22
22
|
import { buildReportData, writeHtmlReport } from "./output/html-reporter.js";
|
|
23
23
|
import { writeOutputs } from "./output/write-outputs.js";
|
|
24
|
+
import { selectFindingsForTable } from "./output/finding-display.js";
|
|
24
25
|
import { printSummary, printActionSummary, printSuggestedFixCommands, printSuggestedFixCommandSkips, printCoverage, printSkippedDependencies, printTable, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
25
26
|
import { installSkill } from "./skills/install.js";
|
|
26
27
|
import { readConfig, validateCaCertFile } from "./cli/config.js";
|
|
27
28
|
import { runConfigCommand } from "./cli/config-command.js";
|
|
28
29
|
import { readDirectDependencyNames } from "./utils/package-json.js";
|
|
29
30
|
import { applyFixesIfRequested, printFixModeSummary, } from "./utils/fix-runner.js";
|
|
31
|
+
import { hasRootLockfile, findNestedLockfiles } from "./parsers/multi-package.js";
|
|
32
|
+
import { handleMultiFolderScan } from "./scan/multi-folder-scan.js";
|
|
30
33
|
let parsedArgs = null;
|
|
31
34
|
try {
|
|
32
35
|
parsedArgs = parseArgs(process.argv.slice(2));
|
|
@@ -119,6 +122,13 @@ if (parsedArgs) {
|
|
|
119
122
|
return;
|
|
120
123
|
}
|
|
121
124
|
validateOptions(options);
|
|
125
|
+
// Multi-folder mode: if no root lockfile and 2+ nested lockfiles exist,
|
|
126
|
+
// route to dedicated multi-folder handler instead of single-lockfile scan
|
|
127
|
+
const nestedLockfiles = findNestedLockfiles(projectPath, searchDepth);
|
|
128
|
+
if (!hasRootLockfile(projectPath) && nestedLockfiles.length >= 2) {
|
|
129
|
+
await handleMultiFolderScan({ projectRoot: projectPath, batchSize, options });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
122
132
|
let advisorySourceLine;
|
|
123
133
|
let advisoryDbFreshnessLine = null;
|
|
124
134
|
let advisoryDbWarning = null;
|
|
@@ -172,6 +182,8 @@ if (parsedArgs) {
|
|
|
172
182
|
process.exit(0);
|
|
173
183
|
return;
|
|
174
184
|
}
|
|
185
|
+
if (!options.json)
|
|
186
|
+
console.log();
|
|
175
187
|
let scanState = await scanProject({
|
|
176
188
|
scanInput,
|
|
177
189
|
batchSize,
|
|
@@ -335,7 +347,7 @@ async function scanProject(params) {
|
|
|
335
347
|
const minSeverity = normalizeSeverity(params.options.minSeverity || "medium");
|
|
336
348
|
const tableFindings = params.options.all
|
|
337
349
|
? sorted
|
|
338
|
-
: sorted
|
|
350
|
+
: selectFindingsForTable(sorted, minSeverity);
|
|
339
351
|
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, params.scanInput, { offline });
|
|
340
352
|
return {
|
|
341
353
|
sorted,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
function cleanup(handler) {
|
|
3
|
+
process.stdin.setRawMode(false);
|
|
4
|
+
process.stdin.pause();
|
|
5
|
+
process.stdin.removeListener("data", handler);
|
|
6
|
+
}
|
|
7
|
+
function listenOnStdin(onKey) {
|
|
8
|
+
process.stdin.setRawMode(true);
|
|
9
|
+
process.stdin.resume();
|
|
10
|
+
process.stdin.setEncoding("utf8");
|
|
11
|
+
const handler = (key) => {
|
|
12
|
+
if (key === "") {
|
|
13
|
+
cleanup(handler);
|
|
14
|
+
process.exit(0);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
onKey(key, handler);
|
|
18
|
+
};
|
|
19
|
+
process.stdin.on("data", handler);
|
|
20
|
+
}
|
|
21
|
+
export function waitForKeypress(valid) {
|
|
22
|
+
if (valid.length === 0)
|
|
23
|
+
throw new Error("waitForKeypress: valid keys array must not be empty");
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
listenOnStdin((key, handler) => {
|
|
26
|
+
if (valid.includes(key.toLowerCase())) {
|
|
27
|
+
cleanup(handler);
|
|
28
|
+
resolve(key.toLowerCase());
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function waitForEnter() {
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
listenOnStdin((key, handler) => {
|
|
36
|
+
if (key === "\r" || key === "\n") {
|
|
37
|
+
cleanup(handler);
|
|
38
|
+
resolve();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export function waitForAnyKey() {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
listenOnStdin((key, handler) => {
|
|
46
|
+
cleanup(handler);
|
|
47
|
+
resolve();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fetchScenarioIndex, fetchScenario } from "./scenario.js";
|
|
5
|
+
import { runSession } from "./session.js";
|
|
6
|
+
import { loadPackages } from "../parsers/index.js";
|
|
7
|
+
import { scanPackages } from "../scanner.js";
|
|
8
|
+
import { chalk } from "../utils/chalk.js";
|
|
9
|
+
import { waitForKeypress } from "./keypress.js";
|
|
10
|
+
import { countBySeverity } from "../utils/severity.js";
|
|
11
|
+
function formatFindings(findings) {
|
|
12
|
+
const counts = countBySeverity(findings);
|
|
13
|
+
const total = findings.length;
|
|
14
|
+
const label = total === 1 ? "finding" : "findings";
|
|
15
|
+
const parts = [];
|
|
16
|
+
if (counts.critical > 0)
|
|
17
|
+
parts.push(`${counts.critical} critical`);
|
|
18
|
+
if (counts.high > 0)
|
|
19
|
+
parts.push(`${counts.high} high`);
|
|
20
|
+
if (counts.medium > 0)
|
|
21
|
+
parts.push(`${counts.medium} medium`);
|
|
22
|
+
if (counts.low > 0)
|
|
23
|
+
parts.push(`${counts.low} low`);
|
|
24
|
+
return parts.length > 0 ? `${total} ${label} (${parts.join(" · ")})` : `${total} ${label}`;
|
|
25
|
+
}
|
|
26
|
+
export async function runLearnCommand() {
|
|
27
|
+
let index;
|
|
28
|
+
try {
|
|
29
|
+
index = await fetchScenarioIndex();
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
console.error("Could not fetch scenario. Check your connection and try again.");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.log("\nCVE Lite CLI - Learn Mode\n");
|
|
37
|
+
console.log("Available scenarios:");
|
|
38
|
+
index.scenarios.forEach((s, i) => {
|
|
39
|
+
console.log(` ${i + 1}. ${s.title.padEnd(40)} (${s.difficulty})`);
|
|
40
|
+
});
|
|
41
|
+
const validKeys = index.scenarios.map((_, i) => String(i + 1));
|
|
42
|
+
process.stdout.write(`\nPick a scenario [1-${index.scenarios.length}]: `);
|
|
43
|
+
const choice = await waitForKeypress(validKeys);
|
|
44
|
+
console.log(choice);
|
|
45
|
+
const selected = index.scenarios[Number(choice) - 1];
|
|
46
|
+
let scenarioData;
|
|
47
|
+
try {
|
|
48
|
+
scenarioData = await fetchScenario(selected.id);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
console.error("Could not fetch scenario. Check your connection and try again.");
|
|
52
|
+
process.exit(1);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const { scenario, lockfileContent, fixedLockfileContent } = scenarioData;
|
|
56
|
+
const tempDir = path.join(os.tmpdir(), `cve-lite-learn-${selected.id}`);
|
|
57
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
58
|
+
try {
|
|
59
|
+
console.log(`\nScenario: ${chalk.bold(scenario.title)}`);
|
|
60
|
+
console.log("-".repeat(42));
|
|
61
|
+
console.log(scenario.concept);
|
|
62
|
+
console.log("\nScanning...");
|
|
63
|
+
fs.writeFileSync(path.join(tempDir, "package-lock.json"), lockfileContent, "utf8");
|
|
64
|
+
const initialInput = loadPackages(tempDir, false, 4);
|
|
65
|
+
const initialFindings = await scanPackages(initialInput.packages, 100, { failOn: "critical", batchSize: "100", json: true });
|
|
66
|
+
if (initialFindings.length === 0) {
|
|
67
|
+
console.error("Unexpected: no findings. The scenario may be outdated - please update CVE Lite CLI.");
|
|
68
|
+
process.exit(1);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
await runSession(scenario);
|
|
72
|
+
console.log("\nIn a real project, you would run:\n");
|
|
73
|
+
console.log(` ${chalk.cyan(scenario.fixCommand)}`);
|
|
74
|
+
console.log("\nApplying the fix for this scenario...\n");
|
|
75
|
+
console.log("Rescanning...\n");
|
|
76
|
+
fs.writeFileSync(path.join(tempDir, "package-lock.json"), fixedLockfileContent, "utf8");
|
|
77
|
+
const fixedInput = loadPackages(tempDir, false, 4);
|
|
78
|
+
const fixedFindings = await scanPackages(fixedInput.packages, 100, { failOn: "critical", batchSize: "100", json: true });
|
|
79
|
+
console.log(`Before: ${formatFindings(initialFindings)}`);
|
|
80
|
+
console.log(`After: ${formatFindings(fixedFindings)}`);
|
|
81
|
+
const beforeCounts = countBySeverity(initialFindings);
|
|
82
|
+
const afterCounts = countBySeverity(fixedFindings);
|
|
83
|
+
const improved = fixedFindings.length < initialFindings.length ||
|
|
84
|
+
(beforeCounts.critical > 0 && afterCounts.critical === 0) ||
|
|
85
|
+
(beforeCounts.high > 0 && afterCounts.high === 0);
|
|
86
|
+
if (improved || fixedFindings.length === 0) {
|
|
87
|
+
console.log(chalk.green(`\n✓ ${scenario.successMessage}`));
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
console.log(chalk.yellow("\nSome findings remain - the fix may be partially applied or the lockfile was not updated."));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
const BASE_URL = process.env["CVE_LITE_LEARN_BASE_URL"] ??
|
|
5
|
+
"https://raw.githubusercontent.com/OWASP/cve-lite-cli/main/examples/learn";
|
|
6
|
+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
7
|
+
function getCacheDir(key) {
|
|
8
|
+
return path.join(os.homedir(), ".cache", "cve-lite", "learn", key);
|
|
9
|
+
}
|
|
10
|
+
async function fetchWithCache(url, cachePath) {
|
|
11
|
+
const cacheDir = path.dirname(cachePath);
|
|
12
|
+
if (fs.existsSync(cachePath)) {
|
|
13
|
+
const { mtimeMs } = fs.statSync(cachePath);
|
|
14
|
+
if (Date.now() - mtimeMs < CACHE_TTL_MS) {
|
|
15
|
+
return fs.readFileSync(cachePath, "utf8");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const res = await fetch(url);
|
|
19
|
+
if (!res.ok)
|
|
20
|
+
throw new Error(`Fetch failed: ${url} (${res.status})`);
|
|
21
|
+
const text = await res.text();
|
|
22
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
23
|
+
fs.writeFileSync(cachePath, text, "utf8");
|
|
24
|
+
return text;
|
|
25
|
+
}
|
|
26
|
+
export async function fetchScenarioIndex() {
|
|
27
|
+
const cachePath = path.join(getCacheDir("_index"), "index.json");
|
|
28
|
+
const text = await fetchWithCache(`${BASE_URL}/index.json`, cachePath);
|
|
29
|
+
const data = JSON.parse(text);
|
|
30
|
+
if (!Array.isArray(data?.scenarios)) {
|
|
31
|
+
throw new Error("Invalid index.json: missing scenarios array");
|
|
32
|
+
}
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
export async function fetchScenario(id) {
|
|
36
|
+
const cacheDir = getCacheDir(id);
|
|
37
|
+
const [scenarioText, lockfileContent, fixedLockfileContent] = await Promise.all([
|
|
38
|
+
fetchWithCache(`${BASE_URL}/${id}/scenario.json`, path.join(cacheDir, "scenario.json")),
|
|
39
|
+
fetchWithCache(`${BASE_URL}/${id}/package-lock.json`, path.join(cacheDir, "package-lock.json")),
|
|
40
|
+
fetchWithCache(`${BASE_URL}/${id}/package-lock-fixed.json`, path.join(cacheDir, "package-lock-fixed.json")),
|
|
41
|
+
]);
|
|
42
|
+
const scenario = JSON.parse(scenarioText);
|
|
43
|
+
if (!scenario.title || !Array.isArray(scenario.steps)) {
|
|
44
|
+
throw new Error(`Invalid scenario.json for ${id}`);
|
|
45
|
+
}
|
|
46
|
+
return { scenario, lockfileContent, fixedLockfileContent };
|
|
47
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { chalk } from "../utils/chalk.js";
|
|
2
|
+
import { waitForKeypress, waitForAnyKey } from "./keypress.js";
|
|
3
|
+
async function runStep(step, stepNumber, total) {
|
|
4
|
+
console.log(`\nFinding ${stepNumber} of ${total}`);
|
|
5
|
+
console.log(`Package: ${chalk.bold(step.finding)}`);
|
|
6
|
+
console.log(`Severity: ${chalk.red(step.severity.toUpperCase())}`);
|
|
7
|
+
if (step.type) {
|
|
8
|
+
console.log(`Type: ${step.type} dependency`);
|
|
9
|
+
}
|
|
10
|
+
console.log(`\n${step.question}`);
|
|
11
|
+
step.options.forEach(opt => console.log(` ${opt}`));
|
|
12
|
+
const validKeys = step.options.map((_, i) => String.fromCharCode(97 + i));
|
|
13
|
+
process.stdout.write(`\nYour answer [a-${String.fromCharCode(96 + step.options.length)}]: `);
|
|
14
|
+
const answer = await waitForKeypress(validKeys);
|
|
15
|
+
console.log(answer);
|
|
16
|
+
const correct = answer === step.correct.toLowerCase();
|
|
17
|
+
if (correct) {
|
|
18
|
+
console.log(chalk.green(`\n✓ ${step.correct_explanation}`));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
console.log(chalk.red(`\n✗ ${step.wrong_explanation}`));
|
|
22
|
+
}
|
|
23
|
+
process.stdout.write("\nPress any key to continue...");
|
|
24
|
+
await waitForAnyKey();
|
|
25
|
+
console.log();
|
|
26
|
+
return correct;
|
|
27
|
+
}
|
|
28
|
+
export async function runSession(scenario) {
|
|
29
|
+
let correct = 0;
|
|
30
|
+
for (let i = 0; i < scenario.steps.length; i++) {
|
|
31
|
+
if (await runStep(scenario.steps[i], i + 1, scenario.steps.length)) {
|
|
32
|
+
correct++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return correct;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export function createDebugLogger(enabled) {
|
|
4
|
+
if (!enabled) {
|
|
5
|
+
return {
|
|
6
|
+
log: () => { },
|
|
7
|
+
announcePath: () => { },
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
11
|
+
const filename = `cve-lite-debug-${ts}.log`;
|
|
12
|
+
const outputPath = path.join(process.cwd(), filename);
|
|
13
|
+
let announced = false;
|
|
14
|
+
const log = (message, details) => {
|
|
15
|
+
const time = new Date().toISOString();
|
|
16
|
+
const payload = details === undefined
|
|
17
|
+
? ""
|
|
18
|
+
: ` ${formatJson(details)}`;
|
|
19
|
+
fs.appendFileSync(outputPath, `${time} [debug] ${message}${payload}\n`, "utf8");
|
|
20
|
+
};
|
|
21
|
+
const announcePath = () => {
|
|
22
|
+
if (announced)
|
|
23
|
+
return;
|
|
24
|
+
announced = true;
|
|
25
|
+
console.error(`[debug] Writing debug log to ./${filename}`);
|
|
26
|
+
};
|
|
27
|
+
return { log, announcePath };
|
|
28
|
+
}
|
|
29
|
+
function formatJson(details) {
|
|
30
|
+
if (typeof details === "string")
|
|
31
|
+
return details;
|
|
32
|
+
try {
|
|
33
|
+
return JSON.stringify(details);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return String(details);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { severityOrder } from "../constants.js";
|
|
2
|
+
import { normalizeSeverity } from "../osv/severity.js";
|
|
3
|
+
export function selectFindingsForTable(findings, minSeverity) {
|
|
4
|
+
const normalized = normalizeSeverity(minSeverity);
|
|
5
|
+
return findings.filter(finding => severityOrder[finding.severity] >= severityOrder[normalized] || finding.severity === "unknown");
|
|
6
|
+
}
|
|
7
|
+
export function selectFindingsForCompact(findings, options) {
|
|
8
|
+
const urgentLimit = options?.urgentLimit ?? 3;
|
|
9
|
+
const urgent = findings
|
|
10
|
+
.filter(finding => finding.severity === "critical" || finding.severity === "high")
|
|
11
|
+
.slice(0, urgentLimit);
|
|
12
|
+
const unknownDirect = findings.filter(finding => finding.severity === "unknown" && finding.relationship === "direct");
|
|
13
|
+
return mergeUniqueFindings(urgent, unknownDirect);
|
|
14
|
+
}
|
|
15
|
+
function mergeUniqueFindings(primary, extra) {
|
|
16
|
+
const result = [...primary];
|
|
17
|
+
const seen = new Set(result.map(findingIdentity));
|
|
18
|
+
for (const finding of extra) {
|
|
19
|
+
const id = findingIdentity(finding);
|
|
20
|
+
if (seen.has(id))
|
|
21
|
+
continue;
|
|
22
|
+
seen.add(id);
|
|
23
|
+
result.push(finding);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function findingIdentity(finding) {
|
|
28
|
+
const vulnIds = finding.vulnerabilities.map(v => v.id).sort().join(",");
|
|
29
|
+
return `${finding.pkg.name}@${finding.pkg.version}|${finding.relationship}|${finding.severity}|${vulnIds}`;
|
|
30
|
+
}
|
|
@@ -20,33 +20,7 @@ export function buildReportData(params) {
|
|
|
20
20
|
warnings: params.warnings,
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
export
|
|
24
|
-
const projectName = path.basename(data.projectPath);
|
|
25
|
-
const scanDate = new Date(data.scannedAt).toLocaleString();
|
|
26
|
-
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
|
|
27
|
-
for (const f of data.findings) {
|
|
28
|
-
const sev = f.severity;
|
|
29
|
-
if (sev in counts)
|
|
30
|
-
counts[sev]++;
|
|
31
|
-
}
|
|
32
|
-
const totalCVEs = new Set(data.findings.flatMap(f => f.vulnerabilities.map(v => v.id))).size;
|
|
33
|
-
const noticesHtml = renderNotices(data.notes, data.warnings);
|
|
34
|
-
const fixPlanHtml = renderFixPlan(data.suggestedFixCommands);
|
|
35
|
-
const findingRowsHtml = data.findings.map(renderFindingRow).join("\n");
|
|
36
|
-
const dataJson = JSON.stringify(data)
|
|
37
|
-
.replace(/</g, "\\u003c")
|
|
38
|
-
.replace(/>/g, "\\u003e")
|
|
39
|
-
.replace(/&/g, "\\u0026")
|
|
40
|
-
.replace(/\u2028/g, "\\u2028")
|
|
41
|
-
.replace(/\u2029/g, "\\u2029");
|
|
42
|
-
return `<!DOCTYPE html>
|
|
43
|
-
<html lang="en">
|
|
44
|
-
<head>
|
|
45
|
-
<meta charset="UTF-8">
|
|
46
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
47
|
-
<title>CVE Lite — ${escapeHtml(projectName)}</title>
|
|
48
|
-
<style>
|
|
49
|
-
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
23
|
+
export const REPORT_STYLES = `*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
50
24
|
body{background:#0d1117;color:#e6edf3;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;font-size:14px;line-height:1.5}
|
|
51
25
|
.report-header{background:#161b22;border-bottom:1px solid #30363d;padding:14px 32px;display:flex;align-items:center;justify-content:space-between;gap:24px}
|
|
52
26
|
.header-left{display:flex;align-items:center;gap:20px}
|
|
@@ -169,7 +143,34 @@ button.header-link:hover{color:#58a6ff;border-color:#58a6ff}
|
|
|
169
143
|
.break-badge{font-size:10px;font-weight:700;background:#fb850022;color:#fb8500;border:1px solid #fb850066;border-radius:4px;padding:1px 5px}
|
|
170
144
|
.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}
|
|
171
145
|
.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}
|
|
172
|
-
.tier-err{display:inline-flex;align-items:center;gap:4px;font-size:10px;padding:2px 8px;border-radius:4px;background:#ff000011;color:#ff7b72;border:1px solid #ff7b7222;margin-bottom:6px}
|
|
146
|
+
.tier-err{display:inline-flex;align-items:center;gap:4px;font-size:10px;padding:2px 8px;border-radius:4px;background:#ff000011;color:#ff7b72;border:1px solid #ff7b7222;margin-bottom:6px}`;
|
|
147
|
+
export function renderHtmlReport(data) {
|
|
148
|
+
const projectName = path.basename(data.projectPath);
|
|
149
|
+
const scanDate = new Date(data.scannedAt).toLocaleString();
|
|
150
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
|
|
151
|
+
for (const f of data.findings) {
|
|
152
|
+
const sev = f.severity;
|
|
153
|
+
if (sev in counts)
|
|
154
|
+
counts[sev]++;
|
|
155
|
+
}
|
|
156
|
+
const totalCVEs = new Set(data.findings.flatMap(f => f.vulnerabilities.map(v => v.id))).size;
|
|
157
|
+
const noticesHtml = renderNotices(data.notes, data.warnings);
|
|
158
|
+
const fixPlanHtml = renderFixPlan(data.suggestedFixCommands);
|
|
159
|
+
const findingRowsHtml = data.findings.map(renderFindingRow).join("\n");
|
|
160
|
+
const dataJson = JSON.stringify(data)
|
|
161
|
+
.replace(/</g, "\\u003c")
|
|
162
|
+
.replace(/>/g, "\\u003e")
|
|
163
|
+
.replace(/&/g, "\\u0026")
|
|
164
|
+
.replace(/\u2028/g, "\\u2028")
|
|
165
|
+
.replace(/\u2029/g, "\\u2029");
|
|
166
|
+
return `<!DOCTYPE html>
|
|
167
|
+
<html lang="en">
|
|
168
|
+
<head>
|
|
169
|
+
<meta charset="UTF-8">
|
|
170
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
171
|
+
<title>CVE Lite — ${escapeHtml(projectName)}</title>
|
|
172
|
+
<style>
|
|
173
|
+
${REPORT_STYLES}
|
|
173
174
|
</style>
|
|
174
175
|
</head>
|
|
175
176
|
<body>
|
|
@@ -374,7 +375,7 @@ document.addEventListener('click', function(e) {
|
|
|
374
375
|
</body>
|
|
375
376
|
</html>`;
|
|
376
377
|
}
|
|
377
|
-
function escapeHtml(str) {
|
|
378
|
+
export function escapeHtml(str) {
|
|
378
379
|
return str
|
|
379
380
|
.replace(/&/g, "&")
|
|
380
381
|
.replace(/</g, "<")
|
|
@@ -387,7 +388,7 @@ function advisoryLink(id) {
|
|
|
387
388
|
}
|
|
388
389
|
return `<a class="cve-link" href="https://osv.dev/vulnerability/${escapeHtml(id)}" target="_blank">${escapeHtml(id)}</a>`;
|
|
389
390
|
}
|
|
390
|
-
function renderFindingRow(finding, idx) {
|
|
391
|
+
export function renderFindingRow(finding, idx) {
|
|
391
392
|
const cveLinks = finding.cves.length > 0
|
|
392
393
|
? finding.cves.map(advisoryLink).join(", ")
|
|
393
394
|
: finding.vulnerabilities.map(v => advisoryLink(v.id)).join(", ");
|
|
@@ -484,7 +485,7 @@ function renderNotices(notes, warnings) {
|
|
|
484
485
|
<div class="scan-notes-body"><ul>${items}</ul></div>
|
|
485
486
|
</div>`;
|
|
486
487
|
}
|
|
487
|
-
function renderFixPlan(plan) {
|
|
488
|
+
export function renderFixPlan(plan) {
|
|
488
489
|
if (!plan || plan.sections.length === 0)
|
|
489
490
|
return "";
|
|
490
491
|
const directCount = plan.targets.filter(t => t.kind === "direct").length;
|
|
@@ -556,7 +557,7 @@ export async function writeHtmlReport(params) {
|
|
|
556
557
|
}
|
|
557
558
|
return { reportPath: indexPath };
|
|
558
559
|
}
|
|
559
|
-
function openInBrowser(filePath) {
|
|
560
|
+
export function openInBrowser(filePath) {
|
|
560
561
|
if (!path.isAbsolute(filePath))
|
|
561
562
|
return;
|
|
562
563
|
const cmd = process.platform === "darwin"
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { REPORT_STYLES, escapeHtml, renderFindingRow, renderFixPlan, openInBrowser } from "./html-reporter.js";
|
|
4
|
+
import { LOGO_BASE64 } from "./logo-base64.js";
|
|
5
|
+
import { OWASP_LOGO_BASE64 } from "./owasp-logo-base64.js";
|
|
6
|
+
import { serializeFinding } from "./formatters.js";
|
|
7
|
+
import { pluralize } from "../utils/string.js";
|
|
8
|
+
function summaryCounts(results) {
|
|
9
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
|
|
10
|
+
for (const r of results) {
|
|
11
|
+
for (const f of r.sorted) {
|
|
12
|
+
const sev = f.severity;
|
|
13
|
+
if (sev in counts)
|
|
14
|
+
counts[sev]++;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return counts;
|
|
18
|
+
}
|
|
19
|
+
function renderFolderNotices(coverage) {
|
|
20
|
+
if (coverage.length === 0)
|
|
21
|
+
return "";
|
|
22
|
+
const items = coverage.map(n => `<li>${escapeHtml(n)}</li>`).join("\n");
|
|
23
|
+
return `<div class="scan-notes" style="margin:16px 32px 0">
|
|
24
|
+
<button class="scan-notes-toggle" onclick="toggleNotes(this)"><span class="arrow">▶</span> Scan notes (${coverage.length})</button>
|
|
25
|
+
<div class="scan-notes-body"><ul>${items}</ul></div>
|
|
26
|
+
</div>`;
|
|
27
|
+
}
|
|
28
|
+
function renderFolderSection(result, folderIdx, idxOffset, serialized) {
|
|
29
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0 };
|
|
30
|
+
for (const f of result.sorted) {
|
|
31
|
+
const sev = f.severity;
|
|
32
|
+
if (sev in counts)
|
|
33
|
+
counts[sev]++;
|
|
34
|
+
}
|
|
35
|
+
const severityParts = ["critical", "high", "medium", "low", "unknown"]
|
|
36
|
+
.filter(s => counts[s] > 0)
|
|
37
|
+
.map(s => `${counts[s]} ${s}`)
|
|
38
|
+
.join(", ");
|
|
39
|
+
const summaryText = severityParts || "no findings";
|
|
40
|
+
const isOpen = counts.critical > 0;
|
|
41
|
+
const fi = folderIdx;
|
|
42
|
+
const findingRowsHtml = serialized.map((f, i) => renderFindingRow(f, idxOffset + i)).join("\n");
|
|
43
|
+
const fixPlanHtml = renderFixPlan(result.suggestedFixCommands);
|
|
44
|
+
const noticesHtml = renderFolderNotices(result.coverage);
|
|
45
|
+
const emptyRow = result.sorted.length === 0
|
|
46
|
+
? `<tr><td colspan="6" style="text-align:center;padding:24px;color:#8b949e">No findings</td></tr>`
|
|
47
|
+
: "";
|
|
48
|
+
return `
|
|
49
|
+
<details class="folder-section"${isOpen ? " open" : ""}>
|
|
50
|
+
<summary class="folder-summary">
|
|
51
|
+
<span class="folder-name">${escapeHtml(result.subfolder)}/</span>
|
|
52
|
+
<span class="folder-counts">${escapeHtml(summaryText)}</span>
|
|
53
|
+
</summary>
|
|
54
|
+
<div class="folder-body">
|
|
55
|
+
${fixPlanHtml}
|
|
56
|
+
${noticesHtml}
|
|
57
|
+
<div class="findings-section" style="margin:16px 32px 32px">
|
|
58
|
+
<div class="findings-header">
|
|
59
|
+
<h2>Findings</h2>
|
|
60
|
+
<div style="display:flex;align-items:center;gap:8px;flex-wrap:wrap">
|
|
61
|
+
<input class="search-input" type="text" id="findings-search-${fi}" placeholder="Search package, version, CVE…" oninput="applyFilters(${fi})" />
|
|
62
|
+
<div class="filter-bar">
|
|
63
|
+
<button class="filter-btn active" onclick="setFilter('all',this,${fi})">All (${result.sorted.length})</button>
|
|
64
|
+
<button class="filter-btn" onclick="setFilter('critical',this,${fi})">Critical (${counts.critical})</button>
|
|
65
|
+
<button class="filter-btn" onclick="setFilter('high',this,${fi})">High (${counts.high})</button>
|
|
66
|
+
<button class="filter-btn" onclick="setFilter('medium',this,${fi})">Medium (${counts.medium})</button>
|
|
67
|
+
<button class="filter-btn" onclick="setFilter('direct',this,${fi})">Direct only</button>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
<table class="findings-table" id="findings-table-${fi}">
|
|
72
|
+
<thead>
|
|
73
|
+
<tr>
|
|
74
|
+
<th style="width:32px"></th>
|
|
75
|
+
<th onclick="sortBy('package',${fi})">Package <span class="sort-arrow">↕</span></th>
|
|
76
|
+
<th>Fix available</th>
|
|
77
|
+
<th onclick="sortBy('severity',${fi})" class="sorted">Severity <span class="sort-arrow" style="color:#58a6ff">↓</span></th>
|
|
78
|
+
<th onclick="sortBy('relationship',${fi})">Type <span class="sort-arrow">↕</span></th>
|
|
79
|
+
<th>CVE / Advisory</th>
|
|
80
|
+
</tr>
|
|
81
|
+
</thead>
|
|
82
|
+
<tbody id="findings-tbody-${fi}" data-offset="${idxOffset}">
|
|
83
|
+
${emptyRow}${findingRowsHtml}
|
|
84
|
+
<tr id="no-results-row-${fi}" style="display:none"><td colspan="6" class="no-results">No findings match your search.</td></tr>
|
|
85
|
+
</tbody>
|
|
86
|
+
</table>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
</details>`;
|
|
90
|
+
}
|
|
91
|
+
export async function writeMultiFolderHtmlReport(params) {
|
|
92
|
+
fs.mkdirSync(params.outputDir, { recursive: true });
|
|
93
|
+
const projectName = path.basename(params.projectPath);
|
|
94
|
+
const scanDate = new Date().toLocaleString();
|
|
95
|
+
const counts = summaryCounts(params.results);
|
|
96
|
+
const totalFindings = params.results.reduce((sum, r) => sum + r.sorted.length, 0);
|
|
97
|
+
const totalCVEs = params.results.reduce((sum, r) => sum + r.sorted.reduce((s, f) => s + f.cveAliases.length, 0), 0);
|
|
98
|
+
const folderCount = params.results.length;
|
|
99
|
+
// Pre-serialize findings once per folder for both HTML rendering and JS filter/sort
|
|
100
|
+
const allSerialized = params.results.map(r => r.sorted.map(f => serializeFinding(f, r.suggestedFixCommands)));
|
|
101
|
+
// Compact per-folder findings for JavaScript (only fields needed for filter/sort/search)
|
|
102
|
+
const folderFindingsJson = JSON.stringify(allSerialized.map(findings => findings.map(f => ({
|
|
103
|
+
package: f.package,
|
|
104
|
+
version: f.version,
|
|
105
|
+
severity: f.severity,
|
|
106
|
+
relationship: f.relationship,
|
|
107
|
+
cves: f.cves,
|
|
108
|
+
vulnerabilities: f.vulnerabilities.map(v => ({ id: v.id })),
|
|
109
|
+
}))))
|
|
110
|
+
.replace(/</g, "\\u003c")
|
|
111
|
+
.replace(/>/g, "\\u003e")
|
|
112
|
+
.replace(/&/g, "\\u0026");
|
|
113
|
+
let idxOffset = 0;
|
|
114
|
+
const folderSectionsHtml = params.results
|
|
115
|
+
.map((r, fi) => {
|
|
116
|
+
const html = renderFolderSection(r, fi, idxOffset, allSerialized[fi]);
|
|
117
|
+
idxOffset += r.sorted.length;
|
|
118
|
+
return html;
|
|
119
|
+
})
|
|
120
|
+
.join("\n");
|
|
121
|
+
// The OWASP SVG inline icon used in the header link
|
|
122
|
+
const owaspSvg = `<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>`;
|
|
123
|
+
const html = `<!DOCTYPE html>
|
|
124
|
+
<html lang="en">
|
|
125
|
+
<head>
|
|
126
|
+
<meta charset="UTF-8">
|
|
127
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
128
|
+
<title>CVE Lite — ${escapeHtml(projectName)}</title>
|
|
129
|
+
<style>
|
|
130
|
+
${REPORT_STYLES}
|
|
131
|
+
.folder-section{margin:0 32px 16px;background:#161b22;border:1px solid #30363d;border-radius:8px;overflow:hidden}
|
|
132
|
+
.folder-summary{display:flex;align-items:center;gap:12px;padding:12px 18px;cursor:pointer;user-select:none;list-style:none;background:#1c2128;border-bottom:1px solid #30363d}
|
|
133
|
+
.folder-summary::-webkit-details-marker{display:none}
|
|
134
|
+
.folder-summary::before{content:"▶";font-size:10px;color:#8b949e;transition:transform .15s;flex-shrink:0}
|
|
135
|
+
details[open] .folder-summary::before{transform:rotate(90deg)}
|
|
136
|
+
.folder-name{font-size:13px;font-weight:600;color:#e6edf3;font-family:'SF Mono','Cascadia Code','Fira Code',monospace}
|
|
137
|
+
.folder-counts{font-size:11px;color:#8b949e;margin-left:auto}
|
|
138
|
+
.folder-body{padding:0}
|
|
139
|
+
.folder-body .fix-plan{margin:24px 32px 0}
|
|
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">${folderCount} ${pluralize(folderCount, "folder")} · ${escapeHtml(scanDate)} · CVE Lite ${escapeHtml(params.cliVersion)}</span>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
<div class="header-right">
|
|
160
|
+
<div class="header-stats">
|
|
161
|
+
<span><strong>${folderCount}</strong> ${pluralize(folderCount, "folder")}</span>
|
|
162
|
+
<span><strong>${totalFindings}</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">${owaspSvg} 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">${totalFindings}</span><span class="label">Findings</span></div>
|
|
180
|
+
<div class="sev-card total"><span class="count">${totalCVEs}</span><span class="label">CVEs</span></div>
|
|
181
|
+
</div>
|
|
182
|
+
|
|
183
|
+
${folderSectionsHtml}
|
|
184
|
+
|
|
185
|
+
<div class="report-footer">
|
|
186
|
+
<span>Generated by <strong>cve-lite v${escapeHtml(params.cliVersion)}</strong></span>
|
|
187
|
+
<span>${folderCount} ${pluralize(folderCount, "folder")} · ${totalFindings} findings · ${totalCVEs} CVEs</span>
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<script>
|
|
191
|
+
const SEV_ORDER = {critical:5,high:4,medium:3,low:2,unknown:1,none:0};
|
|
192
|
+
const folderFindings = ${folderFindingsJson};
|
|
193
|
+
const folderState = {};
|
|
194
|
+
|
|
195
|
+
function getFolderState(fi) {
|
|
196
|
+
if (!folderState[fi]) folderState[fi] = { sortCol: 'severity', sortAsc: false, activeFilter: 'all' };
|
|
197
|
+
return folderState[fi];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function toggleRow(idx) {
|
|
201
|
+
const detail = document.getElementById('detail-' + idx);
|
|
202
|
+
const mainRow = document.getElementById('row-' + idx);
|
|
203
|
+
const icon = document.getElementById('icon-' + idx);
|
|
204
|
+
if (!detail) return;
|
|
205
|
+
const isVisible = detail.classList.contains('visible');
|
|
206
|
+
detail.classList.toggle('visible', !isVisible);
|
|
207
|
+
mainRow.classList.toggle('is-expanded', !isVisible);
|
|
208
|
+
icon.textContent = isVisible ? '▶' : '▼';
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function toggleNotes(btn) {
|
|
212
|
+
btn.classList.toggle('open');
|
|
213
|
+
btn.nextElementSibling.classList.toggle('open');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// toggleSkipped is called inline by renderFixPlan; actual work is done via event delegation below
|
|
217
|
+
function toggleSkipped() {}
|
|
218
|
+
|
|
219
|
+
function setFilter(filter, btn, fi) {
|
|
220
|
+
const state = getFolderState(fi);
|
|
221
|
+
state.activeFilter = filter;
|
|
222
|
+
const table = document.getElementById('findings-table-' + fi);
|
|
223
|
+
if (table) table.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
|
|
224
|
+
btn.classList.add('active');
|
|
225
|
+
applyFilters(fi);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function applyFilters(fi) {
|
|
229
|
+
const state = getFolderState(fi);
|
|
230
|
+
const searchEl = document.getElementById('findings-search-' + fi);
|
|
231
|
+
const query = searchEl ? (searchEl.value || '').toLowerCase().trim() : '';
|
|
232
|
+
const tbody = document.getElementById('findings-tbody-' + fi);
|
|
233
|
+
if (!tbody) return;
|
|
234
|
+
const offset = parseInt(tbody.dataset.offset || '0', 10);
|
|
235
|
+
const findings = folderFindings[fi] || [];
|
|
236
|
+
let visibleCount = 0;
|
|
237
|
+
|
|
238
|
+
findings.forEach((f, i) => {
|
|
239
|
+
const absIdx = offset + i;
|
|
240
|
+
const mainRow = document.getElementById('row-' + absIdx);
|
|
241
|
+
const detailRow = document.getElementById('detail-' + absIdx);
|
|
242
|
+
let visible = true;
|
|
243
|
+
if (state.activeFilter === 'critical') visible = f.severity === 'critical';
|
|
244
|
+
else if (state.activeFilter === 'high') visible = f.severity === 'high';
|
|
245
|
+
else if (state.activeFilter === 'medium') visible = f.severity === 'medium';
|
|
246
|
+
else if (state.activeFilter === 'direct') visible = f.relationship === 'direct';
|
|
247
|
+
if (visible && query) {
|
|
248
|
+
const ids = [...(f.cves || []), ...(f.vulnerabilities || []).map(v => v.id)].join(' ').toLowerCase();
|
|
249
|
+
visible = f.package.toLowerCase().includes(query) || f.version.toLowerCase().includes(query) || ids.includes(query);
|
|
250
|
+
}
|
|
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-' + absIdx);
|
|
256
|
+
if (icon) icon.textContent = '▶';
|
|
257
|
+
}
|
|
258
|
+
if (visible) visibleCount++;
|
|
259
|
+
});
|
|
260
|
+
const noResults = document.getElementById('no-results-row-' + fi);
|
|
261
|
+
if (noResults) noResults.style.display = visibleCount === 0 ? '' : 'none';
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function sortBy(col, fi) {
|
|
265
|
+
const state = getFolderState(fi);
|
|
266
|
+
if (state.sortCol === col) { state.sortAsc = !state.sortAsc; } else { state.sortCol = col; state.sortAsc = col === 'package'; }
|
|
267
|
+
|
|
268
|
+
const table = document.getElementById('findings-table-' + fi);
|
|
269
|
+
if (table) {
|
|
270
|
+
table.querySelectorAll('thead th').forEach(th => th.classList.remove('sorted'));
|
|
271
|
+
const colIndex = ['', 'package', '', 'severity', 'relationship'].indexOf(col);
|
|
272
|
+
if (colIndex > 0) table.querySelectorAll('thead th')[colIndex].classList.add('sorted');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const tbody = document.getElementById('findings-tbody-' + fi);
|
|
276
|
+
if (!tbody) return;
|
|
277
|
+
const offset = parseInt(tbody.dataset.offset || '0', 10);
|
|
278
|
+
const findings = folderFindings[fi] || [];
|
|
279
|
+
const indexed = findings.map((f, i) => ({ f, absIdx: offset + i }));
|
|
280
|
+
indexed.sort((a, b) => {
|
|
281
|
+
let cmp = 0;
|
|
282
|
+
if (col === 'package') cmp = a.f.package.localeCompare(b.f.package);
|
|
283
|
+
else if (col === 'severity') cmp = (SEV_ORDER[b.f.severity] || 0) - (SEV_ORDER[a.f.severity] || 0);
|
|
284
|
+
else if (col === 'relationship') cmp = a.f.relationship.localeCompare(b.f.relationship);
|
|
285
|
+
return state.sortAsc ? -cmp : cmp;
|
|
286
|
+
});
|
|
287
|
+
indexed.forEach(({ absIdx }) => {
|
|
288
|
+
const mainRow = document.getElementById('row-' + absIdx);
|
|
289
|
+
const detailRow = document.getElementById('detail-' + absIdx);
|
|
290
|
+
if (mainRow) tbody.appendChild(mainRow);
|
|
291
|
+
if (detailRow) tbody.appendChild(detailRow);
|
|
292
|
+
});
|
|
293
|
+
const noResults = document.getElementById('no-results-row-' + fi);
|
|
294
|
+
if (noResults) tbody.appendChild(noResults);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
document.addEventListener('click', function(e) {
|
|
298
|
+
// Per-folder skipped section toggle (renderFixPlan uses a shared onclick="toggleSkipped()")
|
|
299
|
+
if (e.target.classList.contains('skipped-toggle')) {
|
|
300
|
+
const fixPlan = e.target.closest('.fix-plan');
|
|
301
|
+
const section = fixPlan ? fixPlan.querySelector('.skipped-section') : null;
|
|
302
|
+
if (!section) return;
|
|
303
|
+
const isOpen = section.classList.toggle('open');
|
|
304
|
+
(fixPlan || document).querySelectorAll('.skipped-toggle').forEach(btn => {
|
|
305
|
+
btn.textContent = (isOpen ? '↑' : '↓') + btn.textContent.slice(1);
|
|
306
|
+
});
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const btn = e.target.closest('.copy-btn');
|
|
310
|
+
if (btn && btn.dataset.cmd !== undefined) {
|
|
311
|
+
e.stopPropagation();
|
|
312
|
+
navigator.clipboard.writeText(btn.dataset.cmd).catch(() => {});
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
</script>
|
|
316
|
+
</body>
|
|
317
|
+
</html>`;
|
|
318
|
+
const indexPath = path.join(params.outputDir, "index.html");
|
|
319
|
+
fs.writeFileSync(indexPath, html, "utf8");
|
|
320
|
+
if (params.autoOpen)
|
|
321
|
+
openInBrowser(indexPath);
|
|
322
|
+
return { reportPath: indexPath };
|
|
323
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { chalk } from "../utils/chalk.js";
|
|
2
|
+
import { logInfo, logWarn } from "./formatters.js";
|
|
3
|
+
import { printCompactOutput, printSummary, printActionSummary, printSuggestedFixCommands, printSuggestedFixCommandSkips, printCoverage, printSkippedDependencies, printTable, printFinalStatus, } from "./printers.js";
|
|
4
|
+
import { pluralize } from "../utils/string.js";
|
|
5
|
+
export function printMultiFolderResults(results, options) {
|
|
6
|
+
const offline = !!options.offline || !!options.offlineDb;
|
|
7
|
+
for (let i = 0; i < results.length; i++) {
|
|
8
|
+
const result = results[i];
|
|
9
|
+
console.log(`\n${chalk.bold(`📁 ${result.subfolder}/`)}`);
|
|
10
|
+
console.log(chalk.gray("─".repeat(50)));
|
|
11
|
+
if (result.scanInput.warnings.length > 0) {
|
|
12
|
+
for (const warning of result.scanInput.warnings) {
|
|
13
|
+
logWarn(warning, options);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (options.verbose) {
|
|
17
|
+
printSummary(result.sorted, result.allPackages.length, result.scanInput);
|
|
18
|
+
printActionSummary(result.sorted);
|
|
19
|
+
printSuggestedFixCommands(result.sorted, result.scanInput, { offline, subfolder: result.subfolder });
|
|
20
|
+
printSuggestedFixCommandSkips(result.sorted, result.scanInput, { offline, subfolder: result.subfolder });
|
|
21
|
+
if (result.scanInput.skippedDependencies.length > 0) {
|
|
22
|
+
printSkippedDependencies(result.scanInput.skippedDependencies);
|
|
23
|
+
}
|
|
24
|
+
if (result.sorted.length > 0) {
|
|
25
|
+
if (result.tableFindings.length > 0) {
|
|
26
|
+
printTable(result.tableFindings, options.all ? null : result.minSeverity);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
logInfo(`No findings met the table threshold of ${result.minSeverity}. Re-run with --all to show everything.`, options);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
printCoverage([...result.scanInput.notes, ...result.coverage]);
|
|
33
|
+
printFinalStatus(result.sorted);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
printCompactOutput(result.sorted, result.scanInput, { offline, all: !!options.all, subfolder: result.subfolder });
|
|
37
|
+
}
|
|
38
|
+
if (i < results.length - 1) {
|
|
39
|
+
console.log(chalk.gray("\n" + "─".repeat(50)));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const totalFindings = results.reduce((sum, r) => sum + r.sorted.length, 0);
|
|
43
|
+
const folderNames = results.map(r => `${r.subfolder}/`).join(", ");
|
|
44
|
+
console.log(chalk.gray(`\nScanned ${results.length} ${pluralize(results.length, "folder")}: ${folderNames}`));
|
|
45
|
+
console.log(chalk.gray(`${totalFindings} total ${pluralize(totalFindings, "finding")} across all folders`));
|
|
46
|
+
}
|
package/dist/output/printers.js
CHANGED
|
@@ -4,6 +4,7 @@ import { isMajorVersionBump } from "../utils/version.js";
|
|
|
4
4
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
5
5
|
import { countUniqueAdvisories, formatSeverityLabel, formatRelationshipLabel } from "./formatters.js";
|
|
6
6
|
import { pluralize } from "../utils/string.js";
|
|
7
|
+
import { selectFindingsForCompact } from "./finding-display.js";
|
|
7
8
|
export function printSummary(findings, packageCount, scanInput) {
|
|
8
9
|
if (findings.length === 0) {
|
|
9
10
|
if (scanInput.mode === "manifest-fallback") {
|
|
@@ -283,10 +284,9 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
283
284
|
console.log("────────────────────────────────");
|
|
284
285
|
console.log(chalk.bold("📦 Vulnerabilities found"));
|
|
285
286
|
console.log("────────────────────────────────\n");
|
|
286
|
-
//
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
.slice(0, 3);
|
|
287
|
+
// Reuse shared display selection logic so compact mode does not silently
|
|
288
|
+
// drop direct unknown-severity findings.
|
|
289
|
+
const urgentFindings = selectFindingsForCompact(findings, { urgentLimit: 3 });
|
|
290
290
|
for (const finding of urgentFindings) {
|
|
291
291
|
const sevLabel = finding.severity.toUpperCase().padEnd(8);
|
|
292
292
|
const typeLabel = finding.relationship === "direct"
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { EXCLUDED_DIRS } from "../constants.js";
|
|
4
|
+
import { loadPackages } from "./index.js";
|
|
5
|
+
const LOCKFILE_NAMES = ["bun.lock", "npm-shrinkwrap.json", "package-lock.json", "pnpm-lock.yaml", "yarn.lock"];
|
|
6
|
+
export function hasRootLockfile(projectRoot) {
|
|
7
|
+
return LOCKFILE_NAMES.some(name => fs.existsSync(path.join(projectRoot, name)));
|
|
8
|
+
}
|
|
9
|
+
export function findNestedLockfiles(projectRoot, maxDepth) {
|
|
10
|
+
const results = [];
|
|
11
|
+
function walk(dir, depth) {
|
|
12
|
+
if (depth > maxDepth)
|
|
13
|
+
return;
|
|
14
|
+
let entries = [];
|
|
15
|
+
try {
|
|
16
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const lockfile = entries.find(e => e.isFile() && LOCKFILE_NAMES.includes(e.name));
|
|
22
|
+
if (lockfile) {
|
|
23
|
+
results.push(path.join(dir, lockfile.name));
|
|
24
|
+
return; // stop recursing — this lockfile covers its subtree
|
|
25
|
+
}
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (!entry.isDirectory())
|
|
28
|
+
continue;
|
|
29
|
+
if (EXCLUDED_DIRS.has(entry.name))
|
|
30
|
+
continue;
|
|
31
|
+
walk(path.join(dir, entry.name), depth + 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let rootEntries = [];
|
|
35
|
+
try {
|
|
36
|
+
rootEntries = fs.readdirSync(projectRoot, { withFileTypes: true });
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return results;
|
|
40
|
+
}
|
|
41
|
+
for (const entry of rootEntries) {
|
|
42
|
+
if (!entry.isDirectory())
|
|
43
|
+
continue;
|
|
44
|
+
if (EXCLUDED_DIRS.has(entry.name))
|
|
45
|
+
continue;
|
|
46
|
+
walk(path.join(projectRoot, entry.name), 1);
|
|
47
|
+
}
|
|
48
|
+
return results;
|
|
49
|
+
}
|
|
50
|
+
export function loadMultiplePackages(projectRoot, prodOnly, maxDepth) {
|
|
51
|
+
const lockfiles = findNestedLockfiles(projectRoot, maxDepth);
|
|
52
|
+
return lockfiles.map(lockfilePath => {
|
|
53
|
+
const subfolderAbs = path.dirname(lockfilePath);
|
|
54
|
+
const subfolder = path.relative(projectRoot, subfolderAbs);
|
|
55
|
+
const scanInput = loadPackages(subfolderAbs, prodOnly, maxDepth);
|
|
56
|
+
return { scanInput, subfolder };
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -287,6 +287,14 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
287
287
|
totalFindingCount: findings.length,
|
|
288
288
|
};
|
|
289
289
|
plan.coveredFindingCount = findings.filter(f => findSuggestedCommandForFinding(plan, f) !== null).length;
|
|
290
|
+
if (options?.subfolder) {
|
|
291
|
+
const prefix = `cd ${options.subfolder} && `;
|
|
292
|
+
if (plan.command)
|
|
293
|
+
plan.command = prefix + plan.command;
|
|
294
|
+
for (const section of plan.sections) {
|
|
295
|
+
section.command = prefix + section.command;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
290
298
|
return plan;
|
|
291
299
|
}
|
|
292
300
|
function inferPackageManager(scanInput) {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { loadMultiplePackages } from "../parsers/multi-package.js";
|
|
4
|
+
import { scanPackages, buildCoverageNotes } from "../scanner.js";
|
|
5
|
+
import { sortFindingsForOutput } from "../output/formatters.js";
|
|
6
|
+
import { normalizeSeverity } from "../osv/severity.js";
|
|
7
|
+
import { selectFindingsForTable } from "../output/finding-display.js";
|
|
8
|
+
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
9
|
+
import { readDirectDependencyNames } from "../utils/package-json.js";
|
|
10
|
+
import { DEFAULT_SEARCH_DEPTH, severityOrder } from "../constants.js";
|
|
11
|
+
import { printMultiFolderResults } from "../output/multi-folder-printer.js";
|
|
12
|
+
import { writeMultiFolderHtmlReport } from "../output/multi-folder-html-reporter.js";
|
|
13
|
+
import { chalk } from "../utils/chalk.js";
|
|
14
|
+
import { getCliVersion } from "../utils/version-info.js";
|
|
15
|
+
export async function runMultiFolderScan(params) {
|
|
16
|
+
const searchDepth = Math.max(0, Number(params.options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
17
|
+
const folders = loadMultiplePackages(params.projectRoot, !!params.options.prodOnly, searchDepth);
|
|
18
|
+
const offline = !!params.options.offline || !!params.options.offlineDb;
|
|
19
|
+
const results = [];
|
|
20
|
+
for (const { scanInput, subfolder } of folders) {
|
|
21
|
+
if (scanInput.packages.length === 0)
|
|
22
|
+
continue;
|
|
23
|
+
if (!params.options.json) {
|
|
24
|
+
process.stdout.write(`\n${chalk.bold.cyan(`📁 ${subfolder}/`)}\n`);
|
|
25
|
+
}
|
|
26
|
+
const subfolderAbs = path.join(params.projectRoot, subfolder);
|
|
27
|
+
const directDependencyNames = readDirectDependencyNames(subfolderAbs, !!params.options.prodOnly);
|
|
28
|
+
const findings = await scanPackages(scanInput.packages, params.batchSize, params.options, {
|
|
29
|
+
directDependencyNames,
|
|
30
|
+
scanSource: scanInput.source,
|
|
31
|
+
scanFilePath: scanInput.filePath,
|
|
32
|
+
});
|
|
33
|
+
const sorted = sortFindingsForOutput(findings);
|
|
34
|
+
const coverage = buildCoverageNotes(scanInput, offline);
|
|
35
|
+
const minSeverity = normalizeSeverity(params.options.minSeverity || "medium");
|
|
36
|
+
const tableFindings = params.options.all ? sorted : selectFindingsForTable(sorted, minSeverity);
|
|
37
|
+
const suggestedFixCommands = buildSuggestedFixCommandPlan(sorted, scanInput, { offline, subfolder });
|
|
38
|
+
results.push({
|
|
39
|
+
subfolder,
|
|
40
|
+
scanInput,
|
|
41
|
+
sorted,
|
|
42
|
+
suggestedFixCommands,
|
|
43
|
+
coverage,
|
|
44
|
+
minSeverity,
|
|
45
|
+
tableFindings,
|
|
46
|
+
allPackages: scanInput.packages,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return results;
|
|
50
|
+
}
|
|
51
|
+
export async function handleMultiFolderScan(params) {
|
|
52
|
+
const results = await runMultiFolderScan(params);
|
|
53
|
+
if (results.length === 0) {
|
|
54
|
+
console.log(chalk.yellow("No scannable packages found in any subfolder."));
|
|
55
|
+
process.exit(0);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (params.options.fix) {
|
|
59
|
+
console.error(chalk.yellow("--fix is not yet supported in multi-folder mode. Run cve-lite . from each subfolder individually."));
|
|
60
|
+
process.exit(1);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (params.options.sarif || params.options.cdx) {
|
|
64
|
+
console.error(chalk.yellow("--sarif and --cdx are not yet supported in multi-folder mode."));
|
|
65
|
+
process.exit(1);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (params.options.json) {
|
|
69
|
+
const { serializeFinding } = await import("../output/formatters.js");
|
|
70
|
+
const allFindings = results.flatMap(r => r.sorted.map(f => ({ ...serializeFinding(f, r.suggestedFixCommands), subfolder: r.subfolder })));
|
|
71
|
+
console.log(JSON.stringify({
|
|
72
|
+
multiFolder: true,
|
|
73
|
+
folders: results.map(r => r.subfolder),
|
|
74
|
+
findings: allFindings,
|
|
75
|
+
scannedAt: new Date().toISOString(),
|
|
76
|
+
}, null, 2));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
printMultiFolderResults(results, params.options);
|
|
80
|
+
}
|
|
81
|
+
if (params.options.report) {
|
|
82
|
+
const outputDir = path.resolve(typeof params.options.report === "string" ? params.options.report : "./cve-report");
|
|
83
|
+
const cliVersion = getCliVersion();
|
|
84
|
+
const { reportPath } = await writeMultiFolderHtmlReport({
|
|
85
|
+
outputDir,
|
|
86
|
+
results,
|
|
87
|
+
projectPath: params.projectRoot,
|
|
88
|
+
cliVersion,
|
|
89
|
+
autoOpen: !params.options.noOpen,
|
|
90
|
+
});
|
|
91
|
+
console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
|
|
92
|
+
}
|
|
93
|
+
const failLevel = normalizeSeverity(params.options.failOn);
|
|
94
|
+
const allSorted = results.flatMap(r => r.sorted);
|
|
95
|
+
const shouldFail = allSorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
96
|
+
process.exit(shouldFail ? 1 : 0);
|
|
97
|
+
}
|
|
@@ -8,7 +8,8 @@ const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
|
8
8
|
const BOX_INNER_WIDTH = 50;
|
|
9
9
|
export function isNewer(latest, current) {
|
|
10
10
|
const parse = (v) => {
|
|
11
|
-
const
|
|
11
|
+
const core = v.replace(/^v/, "").split("-")[0];
|
|
12
|
+
const parts = core.split(".").map(Number);
|
|
12
13
|
return parts.length === 3 && parts.every(n => !isNaN(n)) ? parts : [];
|
|
13
14
|
};
|
|
14
15
|
const l = parse(latest);
|
package/package.json
CHANGED