cve-lite-cli 1.0.5 → 1.1.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 +161 -16
- package/dist/advisory/local-advisory-source.js +21 -0
- package/dist/advisory/local-db.js +188 -0
- package/dist/advisory/osv-sync.js +165 -0
- package/dist/cli/args.js +38 -1
- package/dist/cli/help.js +9 -3
- package/dist/index.js +61 -14
- package/dist/osv/cache.js +12 -4
- package/dist/output/formatters.js +42 -13
- package/dist/output/printers.js +18 -3
- package/dist/output/spinner.js +1 -0
- package/dist/remediation/parent-upgrade.js +224 -0
- package/dist/scanner.js +114 -15
- package/package.json +10 -2
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { unzipSync } from "fflate";
|
|
5
|
+
import { LocalAdvisoryDatabase } from "./local-db.js";
|
|
6
|
+
const DEFAULT_OSV_NPM_DUMP_URL = "https://storage.googleapis.com/osv-vulnerabilities/npm/all.zip";
|
|
7
|
+
export function getDefaultAdvisoryDbPath(outputPath) {
|
|
8
|
+
if (outputPath) {
|
|
9
|
+
return path.resolve(outputPath);
|
|
10
|
+
}
|
|
11
|
+
if (process.platform === "win32") {
|
|
12
|
+
const appData = process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
|
|
13
|
+
return path.join(appData, "cve-lite", "advisories.db");
|
|
14
|
+
}
|
|
15
|
+
return path.join(os.homedir(), ".cache", "cve-lite", "advisories.db");
|
|
16
|
+
}
|
|
17
|
+
export async function syncOsvAdvisories(options = {}) {
|
|
18
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
19
|
+
const onProgress = options.onProgress;
|
|
20
|
+
const sourceUrl = options.sourceUrl ?? DEFAULT_OSV_NPM_DUMP_URL;
|
|
21
|
+
const dbPath = getDefaultAdvisoryDbPath(options.outputPath);
|
|
22
|
+
onProgress?.({
|
|
23
|
+
phase: "init",
|
|
24
|
+
sourceUrl,
|
|
25
|
+
dbPath,
|
|
26
|
+
message: `Sync initiated. Downloading advisory dump from ${sourceUrl}`,
|
|
27
|
+
});
|
|
28
|
+
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
29
|
+
if (fs.existsSync(dbPath)) {
|
|
30
|
+
fs.rmSync(dbPath, { force: true });
|
|
31
|
+
}
|
|
32
|
+
const response = await fetchImpl(sourceUrl);
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw new Error(`OSV dump download failed: ${response.status} ${response.statusText}`);
|
|
35
|
+
}
|
|
36
|
+
const totalBytesHeader = response.headers.get("content-length");
|
|
37
|
+
const totalBytes = totalBytesHeader ? Number(totalBytesHeader) : null;
|
|
38
|
+
const zippedBytes = await readResponseBytes(response, (bytesReceived) => {
|
|
39
|
+
onProgress?.({
|
|
40
|
+
phase: "download",
|
|
41
|
+
bytesReceived,
|
|
42
|
+
totalBytes,
|
|
43
|
+
message: totalBytes && totalBytes > 0
|
|
44
|
+
? `Downloading advisory dump: ${formatBytes(bytesReceived)} / ${formatBytes(totalBytes)}`
|
|
45
|
+
: `Downloading advisory dump: ${formatBytes(bytesReceived)}`,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
onProgress?.({
|
|
49
|
+
phase: "download-complete",
|
|
50
|
+
bytesReceived: zippedBytes.byteLength,
|
|
51
|
+
totalBytes,
|
|
52
|
+
message: totalBytes && totalBytes > 0
|
|
53
|
+
? `Download complete: ${formatBytes(zippedBytes.byteLength)} / ${formatBytes(totalBytes)}`
|
|
54
|
+
: `Download complete: ${formatBytes(zippedBytes.byteLength)}`,
|
|
55
|
+
});
|
|
56
|
+
await yieldToEventLoop();
|
|
57
|
+
const archiveEntries = unzipSync(zippedBytes);
|
|
58
|
+
const advisoryEntries = Object.keys(archiveEntries).filter(entryName => entryName.endsWith(".json"));
|
|
59
|
+
onProgress?.({
|
|
60
|
+
phase: "extract",
|
|
61
|
+
totalEntries: Object.keys(archiveEntries).length,
|
|
62
|
+
advisoryEntries: advisoryEntries.length,
|
|
63
|
+
message: `Archive loaded. Processing ${advisoryEntries.length} advisory record${advisoryEntries.length === 1 ? "" : "s"}`,
|
|
64
|
+
});
|
|
65
|
+
await yieldToEventLoop();
|
|
66
|
+
const db = new LocalAdvisoryDatabase(dbPath);
|
|
67
|
+
try {
|
|
68
|
+
let advisoryCount = 0;
|
|
69
|
+
const progressInterval = 250;
|
|
70
|
+
for (const [entryName, bytes] of Object.entries(archiveEntries)) {
|
|
71
|
+
if (!entryName.endsWith(".json")) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const text = Buffer.from(bytes).toString("utf8");
|
|
75
|
+
const vuln = JSON.parse(text);
|
|
76
|
+
if (!vuln.id) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
db.upsertVulnerability(vuln);
|
|
80
|
+
advisoryCount += 1;
|
|
81
|
+
if (advisoryCount === 1 ||
|
|
82
|
+
advisoryCount % progressInterval === 0 ||
|
|
83
|
+
advisoryCount === advisoryEntries.length) {
|
|
84
|
+
onProgress?.({
|
|
85
|
+
phase: "ingest",
|
|
86
|
+
processedAdvisories: advisoryCount,
|
|
87
|
+
totalAdvisories: advisoryEntries.length,
|
|
88
|
+
message: `Processing advisory records: ${advisoryCount} / ${advisoryEntries.length}`,
|
|
89
|
+
});
|
|
90
|
+
await yieldToEventLoop();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
onProgress?.({
|
|
94
|
+
phase: "complete",
|
|
95
|
+
advisoryCount,
|
|
96
|
+
dbPath,
|
|
97
|
+
message: `Sync complete. Stored ${advisoryCount} advisory record${advisoryCount === 1 ? "" : "s"} in ${dbPath}`,
|
|
98
|
+
});
|
|
99
|
+
return { advisoryCount, dbPath, sourceUrl };
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
try {
|
|
103
|
+
db.close();
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
if (fs.existsSync(dbPath)) {
|
|
107
|
+
fs.rmSync(dbPath, { force: true });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
try {
|
|
114
|
+
db.close();
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// ignore close errors during sync cleanup
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function readResponseBytes(response, onChunk) {
|
|
122
|
+
if (!response.body) {
|
|
123
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
124
|
+
onChunk(bytes.byteLength);
|
|
125
|
+
return bytes;
|
|
126
|
+
}
|
|
127
|
+
const reader = response.body.getReader();
|
|
128
|
+
const chunks = [];
|
|
129
|
+
let bytesReceived = 0;
|
|
130
|
+
while (true) {
|
|
131
|
+
const { done, value } = await reader.read();
|
|
132
|
+
if (done) {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
if (value) {
|
|
136
|
+
chunks.push(value);
|
|
137
|
+
bytesReceived += value.byteLength;
|
|
138
|
+
onChunk(bytesReceived);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const combined = new Uint8Array(bytesReceived);
|
|
142
|
+
let offset = 0;
|
|
143
|
+
for (const chunk of chunks) {
|
|
144
|
+
combined.set(chunk, offset);
|
|
145
|
+
offset += chunk.byteLength;
|
|
146
|
+
}
|
|
147
|
+
return combined;
|
|
148
|
+
}
|
|
149
|
+
function formatBytes(bytes) {
|
|
150
|
+
if (bytes < 1024)
|
|
151
|
+
return `${bytes} B`;
|
|
152
|
+
const units = ["KB", "MB", "GB"];
|
|
153
|
+
let value = bytes / 1024;
|
|
154
|
+
let unitIndex = 0;
|
|
155
|
+
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
156
|
+
value /= 1024;
|
|
157
|
+
unitIndex += 1;
|
|
158
|
+
}
|
|
159
|
+
return `${value.toFixed(value >= 10 ? 0 : 1)} ${units[unitIndex]}`;
|
|
160
|
+
}
|
|
161
|
+
async function yieldToEventLoop() {
|
|
162
|
+
await new Promise(resolve => {
|
|
163
|
+
setImmediate(resolve);
|
|
164
|
+
});
|
|
165
|
+
}
|
package/dist/cli/args.js
CHANGED
|
@@ -5,6 +5,27 @@ export function parseArgs(argv) {
|
|
|
5
5
|
searchDepth: "4",
|
|
6
6
|
minSeverity: "medium"
|
|
7
7
|
};
|
|
8
|
+
if (argv[0] === "advisories" && argv[1] === "sync") {
|
|
9
|
+
for (let i = 2; i < argv.length; i++) {
|
|
10
|
+
const arg = argv[i];
|
|
11
|
+
if (arg === "-h" || arg === "--help") {
|
|
12
|
+
options.help = true;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (arg === "--output") {
|
|
16
|
+
options.output = argv[++i];
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (arg.startsWith("--output=")) {
|
|
20
|
+
options.output = arg.slice("--output=".length);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (arg.startsWith("-"))
|
|
24
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
25
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
26
|
+
}
|
|
27
|
+
return { command: "advisories-sync", options };
|
|
28
|
+
}
|
|
8
29
|
let projectArg;
|
|
9
30
|
for (let i = 0; i < argv.length; i++) {
|
|
10
31
|
const arg = argv[i];
|
|
@@ -28,6 +49,14 @@ export function parseArgs(argv) {
|
|
|
28
49
|
options.offline = true;
|
|
29
50
|
continue;
|
|
30
51
|
}
|
|
52
|
+
if (arg === "--offline-db") {
|
|
53
|
+
options.offlineDb = argv[++i];
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (arg.startsWith("--offline-db=")) {
|
|
57
|
+
options.offlineDb = arg.slice("--offline-db=".length);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
31
60
|
if (arg === "--all") {
|
|
32
61
|
options.all = true;
|
|
33
62
|
continue;
|
|
@@ -64,6 +93,14 @@ export function parseArgs(argv) {
|
|
|
64
93
|
options.osvUrl = arg.slice("--osv-url=".length);
|
|
65
94
|
continue;
|
|
66
95
|
}
|
|
96
|
+
if (arg === "--output") {
|
|
97
|
+
options.output = argv[++i];
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (arg.startsWith("--output=")) {
|
|
101
|
+
options.output = arg.slice("--output=".length);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
67
104
|
if (arg === "--search-depth") {
|
|
68
105
|
options.searchDepth = argv[++i] ?? options.searchDepth;
|
|
69
106
|
continue;
|
|
@@ -88,5 +125,5 @@ export function parseArgs(argv) {
|
|
|
88
125
|
}
|
|
89
126
|
throw new Error(`Unexpected argument: ${arg}`);
|
|
90
127
|
}
|
|
91
|
-
return { options, projectArg };
|
|
128
|
+
return { command: "scan", options, projectArg };
|
|
92
129
|
}
|
package/dist/cli/help.js
CHANGED
|
@@ -23,19 +23,25 @@ export function printHelp() {
|
|
|
23
23
|
"",
|
|
24
24
|
"Usage:",
|
|
25
25
|
" cve-lite [projectPath] [options]",
|
|
26
|
+
" cve-lite advisories sync [options]",
|
|
26
27
|
"",
|
|
27
|
-
"
|
|
28
|
+
"Scan options:",
|
|
28
29
|
" --json Print JSON output",
|
|
29
|
-
" --osv-url <url>
|
|
30
|
+
" --osv-url <url> Use a custom OSV-compatible advisory endpoint",
|
|
30
31
|
" --verbose Show detailed output with fix plan, paths, and full table",
|
|
31
32
|
" --prod-only Exclude dev dependencies where available",
|
|
32
33
|
" --fail-on <severity> Exit non-zero at or above severity (default: critical)",
|
|
33
34
|
" --batch-size <number> OSV batch size (default: 100)",
|
|
34
|
-
" --offline
|
|
35
|
+
" --offline Scan using the local advisory database",
|
|
36
|
+
" --offline-db <path> Use a specific local advisory database file",
|
|
35
37
|
" --cache-dir <path> Override cache directory",
|
|
36
38
|
" --search-depth <number> Recursive search depth (default: 4)",
|
|
37
39
|
" --all Show all findings in the main table",
|
|
38
40
|
" --min-severity <level> Minimum severity shown in table (default: medium)",
|
|
41
|
+
"",
|
|
42
|
+
"Advisory sync options:",
|
|
43
|
+
" --output <path> Write the local advisory database to this path",
|
|
44
|
+
"",
|
|
39
45
|
" -h, --help Show this help message"
|
|
40
46
|
];
|
|
41
47
|
console.log(lines.join("\n"));
|
package/dist/index.js
CHANGED
|
@@ -4,13 +4,15 @@ import process from "node:process";
|
|
|
4
4
|
import { parseArgs } from "./cli/args.js";
|
|
5
5
|
import { printBanner, printHelp } from "./cli/help.js";
|
|
6
6
|
import { loadPackages, buildNoPackagesMessage } from "./parsers/index.js";
|
|
7
|
-
import { scanPackages, buildCoverageNotes } from "./scanner.js";
|
|
7
|
+
import { scanPackages, buildCoverageNotes, createAdvisorySource } from "./scanner.js";
|
|
8
|
+
import { syncOsvAdvisories } from "./advisory/osv-sync.js";
|
|
8
9
|
import { normalizeSeverity } from "./osv/severity.js";
|
|
9
10
|
import { severityOrder } from "./constants.js";
|
|
10
11
|
import { chalk } from "./utils/chalk.js";
|
|
12
|
+
import { createSpinner } from "./output/spinner.js";
|
|
11
13
|
import { logInfo, logWarn, printCacheSummary, serializeFinding } from "./output/formatters.js";
|
|
12
14
|
import { printSummary, printActionSummary, printPriorityFixes, printFixPlan, printCoverage, printSkippedDependencies, printGroupSummary, printTable, printPathHints, printFinalStatus, printCompactOutput } from "./output/printers.js";
|
|
13
|
-
const { options, projectArg } = parseArgs(process.argv.slice(2));
|
|
15
|
+
const { command, options, projectArg } = parseArgs(process.argv.slice(2));
|
|
14
16
|
if (options.help) {
|
|
15
17
|
printHelp();
|
|
16
18
|
process.exit(0);
|
|
@@ -22,18 +24,34 @@ async function main() {
|
|
|
22
24
|
if (!options.json) {
|
|
23
25
|
printBanner();
|
|
24
26
|
}
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
if (command === "advisories-sync") {
|
|
28
|
+
const spinner = createSpinner("Preparing advisory sync...", options);
|
|
29
|
+
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
30
|
+
const result = await syncOsvAdvisories({
|
|
31
|
+
outputPath: options.output,
|
|
32
|
+
onProgress: event => {
|
|
33
|
+
if (event.phase === "complete") {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (usePlainProgressLogs) {
|
|
37
|
+
console.log(event.message);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
spinner.update(event.message);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
if (usePlainProgressLogs) {
|
|
44
|
+
console.log(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
spinner.succeed(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
48
|
+
}
|
|
49
|
+
console.log(`${chalk.gray("Advisory database:")} synced ${result.advisoryCount} record${result.advisoryCount === 1 ? "" : "s"} to ${chalk.cyan(result.dbPath)}`);
|
|
50
|
+
process.exit(0);
|
|
51
|
+
return;
|
|
34
52
|
}
|
|
35
|
-
|
|
36
|
-
|
|
53
|
+
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
54
|
+
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
37
55
|
}
|
|
38
56
|
if (options.osvUrl) {
|
|
39
57
|
try {
|
|
@@ -43,6 +61,26 @@ async function main() {
|
|
|
43
61
|
throw new Error(`Invalid value for --osv-url: ${options.osvUrl}`);
|
|
44
62
|
}
|
|
45
63
|
}
|
|
64
|
+
let advisorySourceLine;
|
|
65
|
+
try {
|
|
66
|
+
const advisorySource = createAdvisorySource({
|
|
67
|
+
osvUrl: options.osvUrl,
|
|
68
|
+
offline: options.offline,
|
|
69
|
+
offlineDb: options.offlineDb,
|
|
70
|
+
});
|
|
71
|
+
advisorySourceLine = advisorySource.sourceLabel;
|
|
72
|
+
advisorySource.cleanup();
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (options.offline || options.offlineDb) {
|
|
76
|
+
throw new Error(`Offline advisory database is not available: ${error instanceof Error ? error.message : String(error)}`);
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
if (options.offline || options.offlineDb) {
|
|
81
|
+
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
82
|
+
}
|
|
83
|
+
console.log(`${chalk.gray("Advisory source:")} ${formatAdvisorySourceLine(advisorySourceLine)}`);
|
|
46
84
|
const scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
47
85
|
const packages = scanInput.packages;
|
|
48
86
|
logInfo(`Parsed ${packages.length} package${packages.length === 1 ? "" : "s"} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
@@ -55,10 +93,11 @@ async function main() {
|
|
|
55
93
|
if (packages.length === 0) {
|
|
56
94
|
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
57
95
|
process.exit(0);
|
|
96
|
+
return;
|
|
58
97
|
}
|
|
59
98
|
const findings = await scanPackages(packages, batchSize, options);
|
|
60
99
|
const sorted = findings.sort((a, b) => severityOrder[b.severity] - severityOrder[a.severity]);
|
|
61
|
-
const coverage = buildCoverageNotes(scanInput, !!options.offline);
|
|
100
|
+
const coverage = buildCoverageNotes(scanInput, !!options.offline || !!options.offlineDb);
|
|
62
101
|
const minSeverity = normalizeSeverity(options.minSeverity || "medium");
|
|
63
102
|
const tableFindings = options.all ? sorted : sorted.filter(f => severityOrder[f.severity] >= severityOrder[minSeverity]);
|
|
64
103
|
if (options.json) {
|
|
@@ -103,8 +142,16 @@ async function main() {
|
|
|
103
142
|
const failLevel = normalizeSeverity(options.failOn);
|
|
104
143
|
const shouldFail = sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
105
144
|
process.exit(shouldFail ? 1 : 0);
|
|
145
|
+
return;
|
|
106
146
|
}
|
|
107
147
|
main().catch((error) => {
|
|
108
148
|
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
109
149
|
process.exit(1);
|
|
110
150
|
});
|
|
151
|
+
function formatAdvisorySourceLine(sourceLabel) {
|
|
152
|
+
const match = sourceLabel.match(/^(.*) \((.*)\)$/);
|
|
153
|
+
if (!match) {
|
|
154
|
+
return sourceLabel;
|
|
155
|
+
}
|
|
156
|
+
return `${match[1]} (${chalk.cyan(match[2])})`;
|
|
157
|
+
}
|
package/dist/osv/cache.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
|
+
function createEmptyCache() {
|
|
5
|
+
return { version: 2, createdAt: new Date().toISOString(), entries: {}, queryEntries: {} };
|
|
6
|
+
}
|
|
4
7
|
export function getCacheFilePath(cacheDirOverride) {
|
|
5
8
|
const baseDir = cacheDirOverride
|
|
6
9
|
? path.resolve(cacheDirOverride)
|
|
@@ -11,18 +14,23 @@ export function getCacheFilePath(cacheDirOverride) {
|
|
|
11
14
|
export function loadCache(cacheDirOverride) {
|
|
12
15
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
13
16
|
if (!fs.existsSync(filePath)) {
|
|
14
|
-
return
|
|
17
|
+
return createEmptyCache();
|
|
15
18
|
}
|
|
16
19
|
try {
|
|
17
20
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
18
|
-
if (parsed.
|
|
19
|
-
return
|
|
21
|
+
if (parsed.entries && typeof parsed.entries === "object") {
|
|
22
|
+
return {
|
|
23
|
+
version: 2,
|
|
24
|
+
createdAt: parsed.createdAt ?? new Date().toISOString(),
|
|
25
|
+
entries: parsed.entries,
|
|
26
|
+
queryEntries: parsed.queryEntries && typeof parsed.queryEntries === "object" ? parsed.queryEntries : {},
|
|
27
|
+
};
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
30
|
catch (_error) {
|
|
23
31
|
// ignore corrupt cache
|
|
24
32
|
}
|
|
25
|
-
return
|
|
33
|
+
return createEmptyCache();
|
|
26
34
|
}
|
|
27
35
|
export function saveCache(cache, cacheDirOverride) {
|
|
28
36
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { chalk } from "../utils/chalk.js";
|
|
2
|
+
import { severityOrder } from "../constants.js";
|
|
2
3
|
import { loadCache } from "../osv/cache.js";
|
|
3
4
|
import { inferSeverity } from "../osv/severity.js";
|
|
4
5
|
export function formatSeverityLabel(severity) {
|
|
5
|
-
|
|
6
|
+
const lower = severity.toLowerCase();
|
|
7
|
+
if (lower === "critical")
|
|
6
8
|
return chalk.redBright(severity);
|
|
7
|
-
if (
|
|
9
|
+
if (lower === "high")
|
|
8
10
|
return chalk.red(severity);
|
|
9
|
-
if (
|
|
11
|
+
if (lower === "medium")
|
|
10
12
|
return chalk.yellow(severity);
|
|
11
|
-
if (
|
|
13
|
+
if (lower === "low")
|
|
12
14
|
return chalk.blueBright(severity);
|
|
13
|
-
if (
|
|
15
|
+
if (lower === "unknown")
|
|
14
16
|
return chalk.magenta(severity);
|
|
15
17
|
return severity;
|
|
16
18
|
}
|
|
@@ -34,6 +36,9 @@ export function getRecommendedAction(finding) {
|
|
|
34
36
|
if (finding.relationship === "direct") {
|
|
35
37
|
return `Review and upgrade ${finding.pkg.name} directly in this project.`;
|
|
36
38
|
}
|
|
39
|
+
if (finding.recommendedParentUpgrade) {
|
|
40
|
+
return `Upgrade ${finding.recommendedParentUpgrade.package} from ${finding.recommendedParentUpgrade.currentVersion} to ${finding.recommendedParentUpgrade.targetVersion} to stop pulling in vulnerable ${finding.pkg.name}.`;
|
|
41
|
+
}
|
|
37
42
|
const parent = getPrimaryParent(finding);
|
|
38
43
|
if (parent && finding.firstFixedVersion) {
|
|
39
44
|
return `Review ${parent}; aim for a version that resolves ${finding.pkg.name} to ${finding.firstFixedVersion}+`;
|
|
@@ -53,6 +58,9 @@ export function summarizeRisk(finding) {
|
|
|
53
58
|
if (finding.severity === "high" && finding.relationship === "direct") {
|
|
54
59
|
return "High-severity direct dependency. A direct upgrade is likely the fastest path.";
|
|
55
60
|
}
|
|
61
|
+
if (finding.relationship === "transitive" && finding.recommendedParentUpgrade) {
|
|
62
|
+
return `Transitive issue. A specific parent upgrade target was found for ${finding.recommendedParentUpgrade.package}.`;
|
|
63
|
+
}
|
|
56
64
|
if (finding.relationship === "transitive" && finding.firstFixedVersion) {
|
|
57
65
|
return `Transitive issue. Look for a parent dependency upgrade that pulls in ${finding.firstFixedVersion}+`;
|
|
58
66
|
}
|
|
@@ -71,6 +79,9 @@ export function summarizeNextAction(finding) {
|
|
|
71
79
|
if (finding.relationship === "direct") {
|
|
72
80
|
return `Review and upgrade ${finding.pkg.name} directly in this project.`;
|
|
73
81
|
}
|
|
82
|
+
if (finding.recommendedParentUpgrade) {
|
|
83
|
+
return `Upgrade ${finding.recommendedParentUpgrade.package} ${finding.recommendedParentUpgrade.currentVersion} -> ${finding.recommendedParentUpgrade.targetVersion}.`;
|
|
84
|
+
}
|
|
74
85
|
if (finding.firstFixedVersion) {
|
|
75
86
|
return `Upgrade the parent dependency chain so it resolves ${finding.pkg.name} to ${finding.firstFixedVersion}+`;
|
|
76
87
|
}
|
|
@@ -85,14 +96,15 @@ export function serializeFinding(finding) {
|
|
|
85
96
|
firstFixedVersion: finding.firstFixedVersion,
|
|
86
97
|
recommendedAction: getRecommendedAction(finding),
|
|
87
98
|
primaryParent: getPrimaryParent(finding),
|
|
99
|
+
recommendedParentUpgrade: finding.recommendedParentUpgrade,
|
|
88
100
|
cves: finding.cveAliases,
|
|
89
101
|
dependencyPaths: finding.dependencyPaths,
|
|
90
102
|
vulnerabilities: finding.vulnerabilities.map(v => ({
|
|
91
103
|
id: v.id,
|
|
92
104
|
aliases: v.aliases ?? [],
|
|
93
105
|
summary: v.summary ?? "",
|
|
94
|
-
severity: inferSeverity(v)
|
|
95
|
-
}))
|
|
106
|
+
severity: inferSeverity(v),
|
|
107
|
+
})),
|
|
96
108
|
};
|
|
97
109
|
}
|
|
98
110
|
export function printCacheSummary(cacheDirOverride, options) {
|
|
@@ -100,14 +112,31 @@ export function printCacheSummary(cacheDirOverride, options) {
|
|
|
100
112
|
return;
|
|
101
113
|
const cache = loadCache(cacheDirOverride);
|
|
102
114
|
const advisoryCount = Object.entries(cache.entries).filter(([, value]) => Boolean(value)).length;
|
|
103
|
-
const
|
|
104
|
-
|
|
115
|
+
const emptyCount = Object.entries(cache.entries).filter(([, value]) => value === null).length;
|
|
116
|
+
const packageQueryCount = Object.keys(cache.queryEntries).length;
|
|
117
|
+
const totalCount = advisoryCount + emptyCount;
|
|
118
|
+
if (totalCount === 0 && packageQueryCount === 0)
|
|
119
|
+
return;
|
|
120
|
+
console.log(chalk.gray(`Cache: ${packageQueryCount} package match record${packageQueryCount === 1 ? "" : "s"}, ${advisoryCount} advisory detail record${advisoryCount === 1 ? "" : "s"}`) +
|
|
121
|
+
(emptyCount > 0
|
|
122
|
+
? chalk.gray(`, ${emptyCount} empty lookup${emptyCount === 1 ? "" : "s"}`)
|
|
123
|
+
: ""));
|
|
105
124
|
}
|
|
106
125
|
export function logInfo(message, options) {
|
|
107
|
-
if (
|
|
108
|
-
|
|
126
|
+
if (options?.json)
|
|
127
|
+
return;
|
|
128
|
+
console.log(chalk.gray(message));
|
|
109
129
|
}
|
|
110
130
|
export function logWarn(message, options) {
|
|
111
|
-
if (
|
|
112
|
-
|
|
131
|
+
if (options?.json)
|
|
132
|
+
return;
|
|
133
|
+
console.log(chalk.yellow(message));
|
|
134
|
+
}
|
|
135
|
+
export function sortFindingsForOutput(findings) {
|
|
136
|
+
return [...findings].sort((a, b) => {
|
|
137
|
+
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
138
|
+
if (sevDelta !== 0)
|
|
139
|
+
return sevDelta;
|
|
140
|
+
return a.pkg.name.localeCompare(b.pkg.name);
|
|
141
|
+
});
|
|
113
142
|
}
|
package/dist/output/printers.js
CHANGED
|
@@ -64,6 +64,9 @@ export function printPriorityFixes(findings) {
|
|
|
64
64
|
const parent = getPrimaryParent(finding);
|
|
65
65
|
if (parent)
|
|
66
66
|
console.log(` Parent: ${parent}`);
|
|
67
|
+
if (finding.recommendedParentUpgrade) {
|
|
68
|
+
console.log(` Target: ${finding.recommendedParentUpgrade.package} ${finding.recommendedParentUpgrade.currentVersion} -> ${finding.recommendedParentUpgrade.targetVersion}`);
|
|
69
|
+
}
|
|
67
70
|
console.log(` Next: ${summarizeNextAction(finding)}`);
|
|
68
71
|
}
|
|
69
72
|
}
|
|
@@ -187,6 +190,9 @@ export function printPathHints(findings) {
|
|
|
187
190
|
for (const example of examples) {
|
|
188
191
|
console.log(` ${chalk.gray(example)}`);
|
|
189
192
|
}
|
|
193
|
+
if (finding.recommendedParentUpgrade) {
|
|
194
|
+
console.log(` Recommended parent upgrade: ${chalk.bold.cyan(finding.recommendedParentUpgrade.package)} ${finding.recommendedParentUpgrade.currentVersion} -> ${finding.recommendedParentUpgrade.targetVersion}`);
|
|
195
|
+
}
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
export function printFinalStatus(findings) {
|
|
@@ -235,11 +241,17 @@ export function printCompactOutput(findings) {
|
|
|
235
241
|
.slice(0, 3);
|
|
236
242
|
for (const finding of urgentFindings) {
|
|
237
243
|
const sevLabel = finding.severity.toUpperCase().padEnd(8);
|
|
238
|
-
const typeLabel = finding.relationship === "direct"
|
|
239
|
-
|
|
244
|
+
const typeLabel = finding.relationship === "direct"
|
|
245
|
+
? "Direct dependency"
|
|
246
|
+
: finding.relationship === "transitive"
|
|
247
|
+
? "Transitive dependency"
|
|
248
|
+
: "Unknown dependency";
|
|
240
249
|
console.log(`${formatSeverityLabel(sevLabel)} ${chalk.whiteBright(finding.pkg.name)}@${finding.pkg.version}`);
|
|
241
250
|
console.log(` ${typeLabel}`);
|
|
242
|
-
if (finding.
|
|
251
|
+
if (finding.recommendedParentUpgrade) {
|
|
252
|
+
console.log(` ${chalk.gray(`Fix: upgrade ${finding.recommendedParentUpgrade.package} to ${finding.recommendedParentUpgrade.targetVersion}`)}`);
|
|
253
|
+
}
|
|
254
|
+
else if (finding.firstFixedVersion) {
|
|
243
255
|
const action = finding.relationship === "direct"
|
|
244
256
|
? `upgrade to ${finding.firstFixedVersion}`
|
|
245
257
|
: `upgrade parent chain to resolve ${finding.firstFixedVersion}+`;
|
|
@@ -265,6 +277,9 @@ export function printCompactOutput(findings) {
|
|
|
265
277
|
else if (topFinding.relationship === "direct") {
|
|
266
278
|
console.log(`Upgrade ${chalk.whiteBright(topFinding.pkg.name)} to latest safe version`);
|
|
267
279
|
}
|
|
280
|
+
else if (topFinding.recommendedParentUpgrade) {
|
|
281
|
+
console.log(`Upgrade ${chalk.whiteBright(topFinding.recommendedParentUpgrade.package)} ${topFinding.recommendedParentUpgrade.currentVersion} → ${topFinding.recommendedParentUpgrade.targetVersion}`);
|
|
282
|
+
}
|
|
268
283
|
else {
|
|
269
284
|
const parent = getPrimaryParent(topFinding);
|
|
270
285
|
if (parent) {
|