cve-lite-cli 1.26.0 → 1.28.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 +147 -398
- package/dist/advisory/osv-advisory-source.js +5 -3
- package/dist/cli/advisories-init.js +24 -0
- package/dist/cli/args.js +36 -0
- package/dist/cli/help.js +9 -5
- package/dist/cli/overrides.js +20 -16
- package/dist/constants.js +1 -0
- package/dist/index.js +61 -39
- package/dist/maintenance/dm001-maintenance-risk.js +63 -0
- package/dist/maintenance/types.js +1 -0
- package/dist/osv/cache.js +49 -50
- package/dist/output/debug.js +2 -1
- package/dist/output/formatters.js +17 -3
- package/dist/output/html-reporter.js +156 -102
- package/dist/output/logos.js +1 -1
- package/dist/output/maintenance-findings-html.js +56 -0
- package/dist/output/maintenance-findings-json.js +3 -0
- package/dist/output/maintenance-terminal.js +80 -0
- package/dist/output/override-findings-html.js +24 -28
- package/dist/output/override-findings-sarif.js +34 -24
- package/dist/output/override-findings-terminal.js +19 -2
- package/dist/output/printers.js +19 -6
- package/dist/output/sarif.js +14 -6
- package/dist/output/spinner.js +5 -0
- package/dist/output/write-outputs.js +3 -1
- package/dist/overrides/context-builder.js +29 -0
- package/dist/overrides/detectors/index.js +6 -0
- package/dist/overrides/detectors/oa009-stale-floor.js +80 -0
- package/dist/overrides/detectors/pd001-override-only-phantom.js +32 -0
- package/dist/overrides/detectors/pd002-transitive-only-phantom.js +34 -0
- package/dist/overrides/detectors/phantom-utils.js +21 -0
- package/dist/overrides/fixer.js +21 -1
- package/dist/remediation/cooldown.js +74 -0
- package/dist/remediation/fix-commands.js +42 -2
- package/dist/remediation/npm-registry.js +11 -0
- package/dist/remediation/parent-upgrade.js +114 -18
- package/dist/scan/multi-folder-scan.js +35 -10
- package/dist/scanner.js +86 -22
- package/dist/usage/scanner.js +60 -1
- package/dist/utils/network.js +77 -0
- package/dist/utils/sarif.js +4 -0
- package/dist/utils/severity.js +6 -0
- package/package.json +2 -1
package/dist/osv/cache.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import os from "node:os";
|
|
4
|
+
import { CACHE_TTL_MS } from "../constants.js";
|
|
4
5
|
function createEmptyCache() {
|
|
5
|
-
return { version:
|
|
6
|
+
return { version: 4, createdAt: new Date().toISOString(), entries: {}, queryEntries: {}, npmVersionEntries: {} };
|
|
7
|
+
}
|
|
8
|
+
// v4 stores detail records as { vuln, cachedAt }. v1-v3 stored the OsvVuln (or
|
|
9
|
+
// null for a known-empty lookup) directly, with no timestamp. Legacy records are
|
|
10
|
+
// wrapped with an epoch-0 cachedAt so they read as stale and get refreshed on the
|
|
11
|
+
// next scan, matching how the queryEntries v2->v3 migration backdates its records.
|
|
12
|
+
function wrapLegacyDetailEntries(raw) {
|
|
13
|
+
const epoch = new Date(0).toISOString();
|
|
14
|
+
const entries = {};
|
|
15
|
+
for (const [id, value] of Object.entries(raw ?? {})) {
|
|
16
|
+
entries[id] = { vuln: value ?? null, cachedAt: epoch };
|
|
17
|
+
}
|
|
18
|
+
return entries;
|
|
19
|
+
}
|
|
20
|
+
function readDetailEntries(raw) {
|
|
21
|
+
const entries = {};
|
|
22
|
+
for (const [id, value] of Object.entries(raw ?? {})) {
|
|
23
|
+
if (value && typeof value === "object" && "vuln" in value && "cachedAt" in value) {
|
|
24
|
+
entries[id] = value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return entries;
|
|
6
28
|
}
|
|
7
29
|
export function getCacheFilePath(cacheDirOverride) {
|
|
8
30
|
const baseDir = cacheDirOverride
|
|
@@ -12,7 +34,7 @@ export function getCacheFilePath(cacheDirOverride) {
|
|
|
12
34
|
return path.join(baseDir, "osv-vulns.json");
|
|
13
35
|
}
|
|
14
36
|
export function isEntryStale(entry, nowMs) {
|
|
15
|
-
return nowMs - new Date(entry.cachedAt).getTime() >
|
|
37
|
+
return nowMs - new Date(entry.cachedAt).getTime() > CACHE_TTL_MS;
|
|
16
38
|
}
|
|
17
39
|
export function loadCache(cacheDirOverride, debugLog) {
|
|
18
40
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
@@ -31,64 +53,40 @@ export function loadCache(cacheDirOverride, debugLog) {
|
|
|
31
53
|
debugLog?.("Cache load failed", { path: filePath, reason: "invalid root object" });
|
|
32
54
|
return createEmptyCache();
|
|
33
55
|
}
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
|
|
56
|
+
const version = parsed.version;
|
|
57
|
+
const rawEntries = parsed.entries;
|
|
58
|
+
// Detail records: v4 already carries { vuln, cachedAt }; v1-v3 stored the record
|
|
59
|
+
// directly and are wrapped (and backdated) so the TTL applies uniformly.
|
|
60
|
+
const entries = version === 4 ? readDetailEntries(rawEntries) : wrapLegacyDetailEntries(rawEntries);
|
|
61
|
+
// Query records: v2 stored string[]; v3 and v4 store { vulnIds, cachedAt }; v1/unknown had none.
|
|
62
|
+
const queryEntries = {};
|
|
63
|
+
if (version === 2) {
|
|
39
64
|
const rawQuery = parsed.queryEntries;
|
|
40
|
-
const
|
|
65
|
+
const epoch = new Date(0).toISOString();
|
|
41
66
|
for (const [key, vulnIds] of Object.entries(rawQuery ?? {})) {
|
|
42
|
-
queryEntries[key] = { vulnIds: Array.isArray(vulnIds) ? vulnIds : [], cachedAt:
|
|
67
|
+
queryEntries[key] = { vulnIds: Array.isArray(vulnIds) ? vulnIds : [], cachedAt: epoch };
|
|
43
68
|
}
|
|
44
|
-
const migrated = {
|
|
45
|
-
version: 3,
|
|
46
|
-
createdAt: String(parsed.createdAt ?? new Date().toISOString()),
|
|
47
|
-
entries,
|
|
48
|
-
queryEntries,
|
|
49
|
-
npmVersionEntries: {},
|
|
50
|
-
};
|
|
51
|
-
debugLog?.("Cache loaded", {
|
|
52
|
-
path: filePath,
|
|
53
|
-
queryEntries: Object.keys(migrated.queryEntries).length,
|
|
54
|
-
detailEntries: Object.keys(migrated.entries).length,
|
|
55
|
-
migratedFrom: 2,
|
|
56
|
-
});
|
|
57
|
-
return migrated;
|
|
58
|
-
}
|
|
59
|
-
// v1 or unknown: no queryEntries
|
|
60
|
-
if (parsed.version !== 3) {
|
|
61
|
-
const upgraded = {
|
|
62
|
-
version: 3,
|
|
63
|
-
createdAt: new Date().toISOString(),
|
|
64
|
-
entries,
|
|
65
|
-
queryEntries: {},
|
|
66
|
-
npmVersionEntries: {},
|
|
67
|
-
};
|
|
68
|
-
debugLog?.("Cache loaded", {
|
|
69
|
-
path: filePath,
|
|
70
|
-
queryEntries: 0,
|
|
71
|
-
detailEntries: Object.keys(upgraded.entries).length,
|
|
72
|
-
migratedFrom: parsed.version ?? "unknown",
|
|
73
|
-
});
|
|
74
|
-
return upgraded;
|
|
75
69
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
else if (version === 3 || version === 4) {
|
|
71
|
+
const rawQuery = parsed.queryEntries;
|
|
72
|
+
for (const [key, value] of Object.entries(rawQuery ?? {})) {
|
|
73
|
+
if (value && typeof value === "object" && "vulnIds" in value && "cachedAt" in value) {
|
|
74
|
+
queryEntries[key] = value;
|
|
75
|
+
}
|
|
81
76
|
}
|
|
82
77
|
}
|
|
83
|
-
|
|
78
|
+
// npm publish-date records exist from v3 onward.
|
|
84
79
|
const npmVersionEntries = {};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
if (version === 3 || version === 4) {
|
|
81
|
+
const rawNpmVersions = parsed.npmVersionEntries;
|
|
82
|
+
for (const [key, value] of Object.entries(rawNpmVersions ?? {})) {
|
|
83
|
+
if (value && typeof value === "object" && "publishedAt" in value && "cachedAt" in value) {
|
|
84
|
+
npmVersionEntries[key] = value;
|
|
85
|
+
}
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
88
|
const loaded = {
|
|
91
|
-
version:
|
|
89
|
+
version: 4,
|
|
92
90
|
createdAt: String(parsed.createdAt ?? new Date().toISOString()),
|
|
93
91
|
entries,
|
|
94
92
|
queryEntries,
|
|
@@ -98,6 +96,7 @@ export function loadCache(cacheDirOverride, debugLog) {
|
|
|
98
96
|
path: filePath,
|
|
99
97
|
queryEntries: Object.keys(loaded.queryEntries).length,
|
|
100
98
|
detailEntries: Object.keys(loaded.entries).length,
|
|
99
|
+
...(version === 4 ? {} : { migratedFrom: version ?? "unknown" }),
|
|
101
100
|
});
|
|
102
101
|
return loaded;
|
|
103
102
|
}
|
package/dist/output/debug.js
CHANGED
|
@@ -5,6 +5,7 @@ export function createDebugLogger(enabled) {
|
|
|
5
5
|
return {
|
|
6
6
|
log: () => { },
|
|
7
7
|
announcePath: () => { },
|
|
8
|
+
close: () => { },
|
|
8
9
|
};
|
|
9
10
|
}
|
|
10
11
|
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
@@ -24,7 +25,7 @@ export function createDebugLogger(enabled) {
|
|
|
24
25
|
announced = true;
|
|
25
26
|
console.error(`[debug] Writing debug log to ./${filename}`);
|
|
26
27
|
};
|
|
27
|
-
return { log, announcePath };
|
|
28
|
+
return { log, announcePath, close: () => { } };
|
|
28
29
|
}
|
|
29
30
|
function formatJson(details) {
|
|
30
31
|
if (typeof details === "string")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
1
|
+
import { findFixTargetForFinding, findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
2
2
|
import { chalk } from "../utils/chalk.js";
|
|
3
3
|
import { severityOrder, MAL_PRIVATE_REGISTRY_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, } from "../constants.js";
|
|
4
4
|
import { loadCache } from "../osv/cache.js";
|
|
@@ -24,6 +24,15 @@ export function formatAdvisorySourceLine(sourceLabel) {
|
|
|
24
24
|
}
|
|
25
25
|
return `${match[1]} (${chalk.cyan(match[2])})`;
|
|
26
26
|
}
|
|
27
|
+
export function formatHintLines(lines) {
|
|
28
|
+
if (lines.length === 0)
|
|
29
|
+
return [];
|
|
30
|
+
const [first, ...rest] = lines;
|
|
31
|
+
return [
|
|
32
|
+
chalk.yellow(first),
|
|
33
|
+
...rest.map(line => chalk.gray(line)),
|
|
34
|
+
];
|
|
35
|
+
}
|
|
27
36
|
// MAL-* is the OSV prefix for malicious code advisories
|
|
28
37
|
function isMaliciousAdvisory(finding) {
|
|
29
38
|
return finding.vulnerabilities.some(v => v.id.startsWith("MAL-"));
|
|
@@ -182,6 +191,9 @@ export function summarizeNextAction(finding) {
|
|
|
182
191
|
export function formatFixVersionPublishDate(iso) {
|
|
183
192
|
return iso.slice(0, 10);
|
|
184
193
|
}
|
|
194
|
+
export function formatCooldownWarning(warning) {
|
|
195
|
+
return `Published ${formatFixVersionPublishDate(warning.publishedAt)}, newer than your configured ${warning.windowLabel} release cooldown (${warning.sourceFile}); your package manager would hold this version - validate before overriding.`;
|
|
196
|
+
}
|
|
185
197
|
export function formatFixCommandPublishSuffix(targets) {
|
|
186
198
|
const dated = targets.filter(target => target.kind === "direct" && target.fixVersionPublishedAt);
|
|
187
199
|
if (dated.length === 0)
|
|
@@ -207,6 +219,7 @@ export function serializeFinding(finding, plan) {
|
|
|
207
219
|
validatedFirstFixedVersion: finding.validatedFirstFixedVersion ?? null,
|
|
208
220
|
fixVersionValidationNote: finding.fixVersionValidationNote ?? null,
|
|
209
221
|
fixVersionPublishedAt: finding.fixVersionPublishedAt ?? null,
|
|
222
|
+
cooldownWarning: plan ? (findFixTargetForFinding(plan, finding)?.cooldownWarning ?? null) : null,
|
|
210
223
|
validatedTargetScannedVersions: finding.validatedTargetScannedVersions ?? null,
|
|
211
224
|
validatedTargetKnownVulnerableVersions: finding.validatedTargetKnownVulnerableVersions ?? null,
|
|
212
225
|
recommendedAction: getRecommendedAction(finding),
|
|
@@ -220,6 +233,7 @@ export function serializeFinding(finding, plan) {
|
|
|
220
233
|
maliciousUnverifiable: finding.maliciousUnverifiable ?? false,
|
|
221
234
|
maliciousGitSource: finding.maliciousGitSource ?? false,
|
|
222
235
|
maliciousGitSourcePinned: finding.maliciousGitSourcePinned ?? false,
|
|
236
|
+
unresolvedAdvisoryIds: finding.unresolvedAdvisoryIds ?? [],
|
|
223
237
|
vulnerabilities: finding.vulnerabilities.map(v => ({
|
|
224
238
|
id: v.id,
|
|
225
239
|
aliases: v.aliases ?? [],
|
|
@@ -232,8 +246,8 @@ export function printCacheSummary(cacheDirOverride, options) {
|
|
|
232
246
|
if (options?.json)
|
|
233
247
|
return;
|
|
234
248
|
const cache = loadCache(cacheDirOverride);
|
|
235
|
-
const advisoryCount = Object.
|
|
236
|
-
const emptyCount = Object.
|
|
249
|
+
const advisoryCount = Object.values(cache.entries).filter(entry => entry.vuln).length;
|
|
250
|
+
const emptyCount = Object.values(cache.entries).filter(entry => entry.vuln === null).length;
|
|
237
251
|
const packageQueryCount = Object.keys(cache.queryEntries).length;
|
|
238
252
|
const totalCount = advisoryCount + emptyCount;
|
|
239
253
|
if (totalCount === 0 && packageQueryCount === 0)
|