cve-lite-cli 1.13.0 → 1.14.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/dist/cli/args.js +4 -0
- package/dist/cli/help.js +1 -0
- package/dist/index.js +3 -0
- package/dist/osv/cache.js +36 -11
- package/dist/output/formatters.js +2 -2
- package/dist/output/html-reporter.js +36 -2
- package/dist/output/printers.js +2 -2
- package/dist/scanner.js +14 -11
- package/dist/utils/array.js +13 -0
- package/package.json +1 -1
package/dist/cli/args.js
CHANGED
|
@@ -157,6 +157,10 @@ export function parseArgs(argv) {
|
|
|
157
157
|
options.noOpen = true;
|
|
158
158
|
continue;
|
|
159
159
|
}
|
|
160
|
+
if (arg === "--no-cache") {
|
|
161
|
+
options.noCache = true;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
160
164
|
if (arg.startsWith("-"))
|
|
161
165
|
throw new Error(`Unknown option: ${arg}`);
|
|
162
166
|
if (!projectArg) {
|
package/dist/cli/help.js
CHANGED
|
@@ -44,6 +44,7 @@ export function printHelp() {
|
|
|
44
44
|
" --offline Scan using the local advisory database",
|
|
45
45
|
" --offline-db <path> Use a specific local advisory database file",
|
|
46
46
|
" --cache-dir <path> Override cache directory",
|
|
47
|
+
" --no-cache Skip the query cache and fetch fresh results from OSV",
|
|
47
48
|
" --search-depth <number> Recursive search depth (default: 4)",
|
|
48
49
|
" --all Show all findings in the main table",
|
|
49
50
|
" --min-severity <level> Minimum severity shown in table (default: medium)",
|
package/dist/index.js
CHANGED
|
@@ -77,6 +77,9 @@ if (parsedArgs) {
|
|
|
77
77
|
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
78
78
|
throw new Error("--offline/--offline-db cannot be used with --osv-url");
|
|
79
79
|
}
|
|
80
|
+
if (options.noCache && (options.offline || options.offlineDb)) {
|
|
81
|
+
throw new Error("--no-cache cannot be used with --offline or --offline-db");
|
|
82
|
+
}
|
|
80
83
|
if (options.osvUrl) {
|
|
81
84
|
try {
|
|
82
85
|
new URL(options.osvUrl);
|
package/dist/osv/cache.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
function createEmptyCache() {
|
|
5
|
-
return { version:
|
|
5
|
+
return { version: 3, createdAt: new Date().toISOString(), entries: {}, queryEntries: {} };
|
|
6
6
|
}
|
|
7
7
|
export function getCacheFilePath(cacheDirOverride) {
|
|
8
8
|
const baseDir = cacheDirOverride
|
|
@@ -11,6 +11,9 @@ export function getCacheFilePath(cacheDirOverride) {
|
|
|
11
11
|
fs.mkdirSync(baseDir, { recursive: true });
|
|
12
12
|
return path.join(baseDir, "osv-vulns.json");
|
|
13
13
|
}
|
|
14
|
+
export function isEntryStale(entry, nowMs) {
|
|
15
|
+
return nowMs - new Date(entry.cachedAt).getTime() > 30 * 60 * 1000;
|
|
16
|
+
}
|
|
14
17
|
export function loadCache(cacheDirOverride) {
|
|
15
18
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
16
19
|
if (!fs.existsSync(filePath)) {
|
|
@@ -18,19 +21,41 @@ export function loadCache(cacheDirOverride) {
|
|
|
18
21
|
}
|
|
19
22
|
try {
|
|
20
23
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
21
|
-
if (parsed
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
25
|
+
return createEmptyCache();
|
|
26
|
+
const entries = (parsed.entries && typeof parsed.entries === "object")
|
|
27
|
+
? parsed.entries
|
|
28
|
+
: {};
|
|
29
|
+
// v2: queryEntries values are string[] — migrate to { vulnIds, cachedAt: epoch }
|
|
30
|
+
if (parsed.version === 2) {
|
|
31
|
+
const rawQuery = parsed.queryEntries;
|
|
32
|
+
const queryEntries = {};
|
|
33
|
+
for (const [key, vulnIds] of Object.entries(rawQuery ?? {})) {
|
|
34
|
+
queryEntries[key] = { vulnIds: Array.isArray(vulnIds) ? vulnIds : [], cachedAt: new Date(0).toISOString() };
|
|
35
|
+
}
|
|
36
|
+
return { version: 3, createdAt: String(parsed.createdAt ?? new Date().toISOString()), entries, queryEntries };
|
|
37
|
+
}
|
|
38
|
+
// v1 or unknown: no queryEntries
|
|
39
|
+
if (parsed.version !== 3) {
|
|
40
|
+
return { version: 3, createdAt: new Date().toISOString(), entries, queryEntries: {} };
|
|
28
41
|
}
|
|
42
|
+
const rawQuery = parsed.queryEntries;
|
|
43
|
+
const queryEntries = {};
|
|
44
|
+
for (const [key, value] of Object.entries(rawQuery ?? {})) {
|
|
45
|
+
if (value && typeof value === "object" && "vulnIds" in value && "cachedAt" in value) {
|
|
46
|
+
queryEntries[key] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
version: 3,
|
|
51
|
+
createdAt: String(parsed.createdAt ?? new Date().toISOString()),
|
|
52
|
+
entries,
|
|
53
|
+
queryEntries,
|
|
54
|
+
};
|
|
29
55
|
}
|
|
30
|
-
catch
|
|
31
|
-
|
|
56
|
+
catch {
|
|
57
|
+
return createEmptyCache();
|
|
32
58
|
}
|
|
33
|
-
return createEmptyCache();
|
|
34
59
|
}
|
|
35
60
|
export function saveCache(cache, cacheDirOverride) {
|
|
36
61
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
@@ -35,7 +35,7 @@ export function getRecommendedAction(finding) {
|
|
|
35
35
|
return `Upgrade ${finding.pkg.name} to ${directTarget}+ in this project.`;
|
|
36
36
|
}
|
|
37
37
|
if (finding.relationship === "direct") {
|
|
38
|
-
return `
|
|
38
|
+
return `No known fix exists for ${finding.pkg.name}. Consider replacing it with an actively maintained alternative.`;
|
|
39
39
|
}
|
|
40
40
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
41
41
|
return `Update ${finding.recommendedNpmTransitiveRemediation.package} within its current dependency range to pull in vulnerable ${finding.pkg.name}@${finding.recommendedNpmTransitiveRemediation.targetChildVersion}.`;
|
|
@@ -112,7 +112,7 @@ export function summarizeNextAction(finding) {
|
|
|
112
112
|
return `Upgrade ${finding.pkg.name} toward ${directTarget}.`;
|
|
113
113
|
}
|
|
114
114
|
if (finding.relationship === "direct") {
|
|
115
|
-
return `
|
|
115
|
+
return `No known fix exists for ${finding.pkg.name}. Consider replacing it with an actively maintained alternative.`;
|
|
116
116
|
}
|
|
117
117
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
118
118
|
return `Update ${finding.recommendedNpmTransitiveRemediation.package} within its current dependency range.`;
|
|
@@ -128,7 +128,7 @@ button.header-link:hover{color:#58a6ff;border-color:#58a6ff}
|
|
|
128
128
|
.cve-link{font-size:11px;color:#58a6ff;font-family:monospace;text-decoration:none;border-bottom:1px dotted #58a6ff66}
|
|
129
129
|
.cve-link:hover{color:#79c0ff}
|
|
130
130
|
.fix-hint{font-size:11px;color:#3fb950;font-family:monospace}
|
|
131
|
-
.fix-hint.none{color:#
|
|
131
|
+
.fix-hint.none{color:#e3b341}
|
|
132
132
|
.expand-icon{color:#8b949e;font-size:10px}
|
|
133
133
|
.detail-row{background:#0d1117;border-top:1px solid #21262d;display:none}
|
|
134
134
|
.detail-row.visible{display:table-row}
|
|
@@ -164,6 +164,9 @@ button.header-link:hover{color:#58a6ff;border-color:#58a6ff}
|
|
|
164
164
|
.fix-target-stats{color:#6b7280;font-size:10px}
|
|
165
165
|
.fix-target-note{color:#6b7280;font-style:italic;font-size:10px}
|
|
166
166
|
.break-badge{font-size:10px;font-weight:700;background:#fb850022;color:#fb8500;border:1px solid #fb850066;border-radius:4px;padding:1px 5px}
|
|
167
|
+
.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}
|
|
168
|
+
.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}
|
|
169
|
+
.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}
|
|
167
170
|
</style>
|
|
168
171
|
</head>
|
|
169
172
|
<body>
|
|
@@ -388,7 +391,7 @@ function renderFindingRow(finding, idx) {
|
|
|
388
391
|
? `<span class="fix-hint">${escapeHtml(finding.validatedFirstFixedVersion)}</span>`
|
|
389
392
|
: finding.firstFixedVersion
|
|
390
393
|
? `<span class="fix-hint">${escapeHtml(finding.firstFixedVersion)}</span>`
|
|
391
|
-
: `<span class="fix-hint none"
|
|
394
|
+
: `<span class="fix-hint none" title="No known fix — consider replacing this package">⚠ No fix</span>`;
|
|
392
395
|
const depPathHtml = finding.dependencyPaths.length > 0
|
|
393
396
|
? finding.dependencyPaths[0].map((node, i, arr) => {
|
|
394
397
|
const isLast = i === arr.length - 1;
|
|
@@ -403,6 +406,9 @@ function renderFindingRow(finding, idx) {
|
|
|
403
406
|
<button class="copy-btn" data-cmd="${escapeHtml(runnable)}">Copy</button>
|
|
404
407
|
</div>`
|
|
405
408
|
: `<p class="fix-cmd-note">${escapeHtml(finding.recommendedAction ?? "")}</p>`;
|
|
409
|
+
const contextColHtml = finding.relationship === "transitive"
|
|
410
|
+
? renderTransitiveContextCol(finding)
|
|
411
|
+
: "";
|
|
406
412
|
return ` <tr id="row-${idx}" onclick="toggleRow(${idx})">
|
|
407
413
|
<td><span class="expand-icon" id="icon-${idx}">▶</span></td>
|
|
408
414
|
<td><div class="pkg-name">${escapeHtml(finding.package)}</div><div class="pkg-version">${escapeHtml(finding.version)}</div></td>
|
|
@@ -422,6 +428,7 @@ function renderFindingRow(finding, idx) {
|
|
|
422
428
|
<h4>Dependency path</h4>
|
|
423
429
|
<div class="dep-path">${depPathHtml}</div>
|
|
424
430
|
</div>
|
|
431
|
+
${contextColHtml}
|
|
425
432
|
<div class="detail-col">
|
|
426
433
|
<h4>Recommended action</h4>
|
|
427
434
|
${recommendedActionHtml}
|
|
@@ -430,6 +437,33 @@ function renderFindingRow(finding, idx) {
|
|
|
430
437
|
</td>
|
|
431
438
|
</tr>`;
|
|
432
439
|
}
|
|
440
|
+
function renderTransitiveContextCol(finding) {
|
|
441
|
+
const hasFixAvailable = finding.runnableFixCommand != null ||
|
|
442
|
+
finding.recommendedNpmTransitiveRemediation != null ||
|
|
443
|
+
finding.recommendedParentUpgrade != null;
|
|
444
|
+
if (hasFixAvailable) {
|
|
445
|
+
const parentLine = finding.primaryParent
|
|
446
|
+
? `<p style="font-size:12px;color:#8b949e;margin-top:4px">Parent: ${escapeHtml(finding.primaryParent)}</p>`
|
|
447
|
+
: "";
|
|
448
|
+
return `<div class="detail-col" style="max-width:200px">
|
|
449
|
+
<h4>Context</h4>
|
|
450
|
+
<span class="tier-ok">✓ Fix available</span>
|
|
451
|
+
${parentLine}
|
|
452
|
+
</div>`;
|
|
453
|
+
}
|
|
454
|
+
if (finding.primaryParent) {
|
|
455
|
+
return `<div class="detail-col" style="max-width:200px">
|
|
456
|
+
<h4>Context</h4>
|
|
457
|
+
<span class="tier-warn">⚠ No safe version identified</span>
|
|
458
|
+
<p style="font-size:12px;color:#8b949e;margin-top:4px">Parent: ${escapeHtml(finding.primaryParent)}</p>
|
|
459
|
+
</div>`;
|
|
460
|
+
}
|
|
461
|
+
return `<div class="detail-col" style="max-width:200px">
|
|
462
|
+
<h4>Context</h4>
|
|
463
|
+
<span class="tier-err">✕ No parent identified</span>
|
|
464
|
+
<p style="font-size:12px;color:#8b949e;margin-top:4px">Run <code>npm ls ${escapeHtml(finding.package)}</code> to find which package pulls it in.</p>
|
|
465
|
+
</div>`;
|
|
466
|
+
}
|
|
433
467
|
function renderNotices(notes, warnings) {
|
|
434
468
|
if (notes.length === 0 && warnings.length === 0)
|
|
435
469
|
return "";
|
package/dist/output/printers.js
CHANGED
|
@@ -149,11 +149,11 @@ export function printTable(findings, threshold) {
|
|
|
149
149
|
f.severity,
|
|
150
150
|
f.relationship,
|
|
151
151
|
usageText,
|
|
152
|
-
f.firstFixedVersion ?? "
|
|
152
|
+
f.firstFixedVersion ?? chalk.yellow("⚠ no fix"),
|
|
153
153
|
f.vulnerabilities.map(v => v.id).join(", ")
|
|
154
154
|
];
|
|
155
155
|
});
|
|
156
|
-
const widths = headers.map((header, index) => Math.min(40, Math.max(header.length, ...rawRows.map(r => String(r[index]).length))));
|
|
156
|
+
const widths = headers.map((header, index) => Math.min(40, Math.max(header.length, ...rawRows.map(r => stripAnsi(String(r[index])).length))));
|
|
157
157
|
console.log("");
|
|
158
158
|
if (threshold) {
|
|
159
159
|
console.log(chalk.bold(`Showing ${threshold}+ findings in the main table. Use --all to show everything.`));
|
package/dist/scanner.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { chunk, unique } from "./utils/array.js";
|
|
1
|
+
import { chunk, unique, runWithConcurrency } from "./utils/array.js";
|
|
2
2
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "./utils/version.js";
|
|
3
|
-
import { loadCache, saveCache } from "./osv/cache.js";
|
|
3
|
+
import { loadCache, saveCache, isEntryStale } from "./osv/cache.js";
|
|
4
4
|
import { maxSeverity } from "./osv/severity.js";
|
|
5
5
|
import { createSpinner } from "./output/spinner.js";
|
|
6
6
|
import { OsvAdvisorySource } from "./advisory/osv-advisory-source.js";
|
|
@@ -56,28 +56,31 @@ export async function scanPackages(packages, batchSize, options, context) {
|
|
|
56
56
|
const results = [];
|
|
57
57
|
const uncachedPackages = [];
|
|
58
58
|
if (!offline) {
|
|
59
|
+
const nowMs = Date.now();
|
|
59
60
|
for (const pkg of packages) {
|
|
60
61
|
const cacheKey = getPackageCacheKey(pkg);
|
|
61
|
-
if (
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
|
|
62
|
+
if (!options.noCache) {
|
|
63
|
+
const cached = cache.queryEntries[cacheKey];
|
|
64
|
+
if (cached && !isEntryStale(cached, nowMs)) {
|
|
65
|
+
if (cached.vulnIds.length > 0) {
|
|
66
|
+
results.push({ pkg, vulnIds: cached.vulnIds });
|
|
67
|
+
}
|
|
68
|
+
continue;
|
|
65
69
|
}
|
|
66
|
-
continue;
|
|
67
70
|
}
|
|
68
71
|
uncachedPackages.push(pkg);
|
|
69
72
|
}
|
|
70
73
|
const chunks = chunk(uncachedPackages, batchSize);
|
|
74
|
+
spinner.update(`Scanning OSV in ${chunks.length} parallel batch${chunks.length === 1 ? "" : "es"}...`);
|
|
75
|
+
const allAdvisoryResults = await runWithConcurrency(chunks, 5, c => advisorySource.queryBatch(c));
|
|
71
76
|
for (let i = 0; i < chunks.length; i++) {
|
|
72
|
-
spinner.update(`Scanning OSV batch ${i + 1}/${chunks.length}...`);
|
|
73
77
|
const chunkItems = chunks[i];
|
|
74
|
-
const
|
|
75
|
-
const rows = advisoryResult ?? [];
|
|
78
|
+
const rows = allAdvisoryResults[i] ?? [];
|
|
76
79
|
for (let j = 0; j < chunkItems.length; j++) {
|
|
77
80
|
const pkg = chunkItems[j];
|
|
78
81
|
const row = rows[j];
|
|
79
82
|
const vulnIds = (row?.vulnerabilities ?? []).map(v => v.id).filter(Boolean);
|
|
80
|
-
cache.queryEntries[getPackageCacheKey(pkg)] = vulnIds;
|
|
83
|
+
cache.queryEntries[getPackageCacheKey(pkg)] = { vulnIds, cachedAt: new Date().toISOString() };
|
|
81
84
|
if (vulnIds.length > 0) {
|
|
82
85
|
results.push({ pkg, vulnIds });
|
|
83
86
|
}
|
package/dist/utils/array.js
CHANGED
|
@@ -20,3 +20,16 @@ export function uniquePathArrays(paths) {
|
|
|
20
20
|
}
|
|
21
21
|
return output;
|
|
22
22
|
}
|
|
23
|
+
export async function runWithConcurrency(items, limit, fn) {
|
|
24
|
+
const results = new Array(items.length);
|
|
25
|
+
const queue = items.map((item, index) => ({ item, index }));
|
|
26
|
+
let next = 0;
|
|
27
|
+
async function worker() {
|
|
28
|
+
while (next < queue.length) {
|
|
29
|
+
const { item, index } = queue[next++];
|
|
30
|
+
results[index] = await fn(item);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
34
|
+
return results;
|
|
35
|
+
}
|