cve-lite-cli 1.19.0-alpha.1 → 1.19.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 +2 -1
- package/dist/advisory/local-advisory-source.js +1 -1
- package/dist/advisory/osv-advisory-source.js +83 -13
- package/dist/cli/args.js +4 -0
- package/dist/cli/help.js +1 -0
- package/dist/index.js +66 -3
- package/dist/osv/cache.js +46 -7
- package/dist/output/sarif.js +3 -9
- package/dist/output/spinner.js +1 -1
- package/dist/parsers/pnpm-lock.js +4 -0
- package/dist/remediation/fix-commands.js +36 -4
- package/dist/remediation/npm-registry.js +44 -1
- package/dist/remediation/parent-upgrade.js +14 -8
- package/dist/scanner.js +94 -16
- package/dist/utils/fix-runner.js +6 -2
- package/dist/utils/network.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -213,8 +213,9 @@ CVE Lite CLI has been evaluated against real open-source projects to verify that
|
|
|
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
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
|
|
216
|
+
- [Storybook](https://owasp.org/cve-lite-cli/docs/case-studies/storybook) — verified baseline scan of a Yarn Berry monorepo (3,008 packages, 92 findings at revision `cc19ae1`) spanning cross-framework sandbox templates, five critical transitive chains, and one direct vite fix command
|
|
216
217
|
|
|
217
|
-
In-repo lockfile fixtures for Astro, Turborepo,
|
|
218
|
+
In-repo lockfile fixtures for Astro, Turborepo, Visual Studio Code, and Storybook live under [`examples/`](examples/readme.md) — clone the repo and scan immediately without downloading full upstream checkouts.
|
|
218
219
|
|
|
219
220
|
These are not demos. They are documented scans against real codebases with real findings, recorded before and after applying fix commands.
|
|
220
221
|
|
|
@@ -1,26 +1,57 @@
|
|
|
1
1
|
import { extractErrorMessage } from "../utils/network.js";
|
|
2
2
|
export class OsvAdvisorySource {
|
|
3
3
|
baseUrl;
|
|
4
|
-
|
|
4
|
+
debugLog;
|
|
5
|
+
constructor(baseUrl = "https://api.osv.dev", debugLog) {
|
|
5
6
|
this.baseUrl = baseUrl;
|
|
7
|
+
this.debugLog = debugLog;
|
|
6
8
|
}
|
|
7
|
-
async queryBatch(packages) {
|
|
9
|
+
async queryBatch(packages, meta) {
|
|
10
|
+
const requestUrl = `${this.baseUrl}/v1/querybatch`;
|
|
11
|
+
const payload = {
|
|
12
|
+
queries: packages.map(p => ({
|
|
13
|
+
package: {
|
|
14
|
+
ecosystem: p.ecosystem,
|
|
15
|
+
name: p.name,
|
|
16
|
+
},
|
|
17
|
+
version: p.version,
|
|
18
|
+
})),
|
|
19
|
+
};
|
|
20
|
+
const startedAt = this.debugLog ? Date.now() : 0;
|
|
8
21
|
try {
|
|
9
|
-
|
|
22
|
+
if (this.debugLog) {
|
|
23
|
+
this.debugLog("OSV request", {
|
|
24
|
+
batchId: meta?.batchId ?? null,
|
|
25
|
+
method: "POST",
|
|
26
|
+
url: requestUrl,
|
|
27
|
+
headers: {
|
|
28
|
+
"Content-Type": "application/json",
|
|
29
|
+
},
|
|
30
|
+
queryCount: packages.length,
|
|
31
|
+
sample: packages.slice(0, 3).map(p => ({
|
|
32
|
+
ecosystem: p.ecosystem,
|
|
33
|
+
name: p.name,
|
|
34
|
+
version: p.version,
|
|
35
|
+
})),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const response = await fetch(requestUrl, {
|
|
10
39
|
method: "POST",
|
|
11
40
|
headers: {
|
|
12
41
|
"Content-Type": "application/json",
|
|
13
42
|
},
|
|
14
|
-
body: JSON.stringify(
|
|
15
|
-
queries: packages.map(p => ({
|
|
16
|
-
package: {
|
|
17
|
-
ecosystem: p.ecosystem,
|
|
18
|
-
name: p.name,
|
|
19
|
-
},
|
|
20
|
-
version: p.version,
|
|
21
|
-
})),
|
|
22
|
-
}),
|
|
43
|
+
body: JSON.stringify(payload),
|
|
23
44
|
});
|
|
45
|
+
if (this.debugLog) {
|
|
46
|
+
this.debugLog("OSV response", {
|
|
47
|
+
batchId: meta?.batchId ?? null,
|
|
48
|
+
method: "POST",
|
|
49
|
+
url: requestUrl,
|
|
50
|
+
status: response.status,
|
|
51
|
+
statusText: response.statusText,
|
|
52
|
+
durationMs: Date.now() - startedAt,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
24
55
|
if (!response.ok) {
|
|
25
56
|
throw new Error(`OSV batch query failed: ${response.status} ${response.statusText}`);
|
|
26
57
|
}
|
|
@@ -32,19 +63,58 @@ export class OsvAdvisorySource {
|
|
|
32
63
|
}));
|
|
33
64
|
}
|
|
34
65
|
catch (error) {
|
|
66
|
+
if (this.debugLog) {
|
|
67
|
+
this.debugLog("OSV request failed", {
|
|
68
|
+
batchId: meta?.batchId ?? null,
|
|
69
|
+
method: "POST",
|
|
70
|
+
url: requestUrl,
|
|
71
|
+
durationMs: Date.now() - startedAt,
|
|
72
|
+
error: error instanceof Error
|
|
73
|
+
? { message: error.message, stack: error.stack }
|
|
74
|
+
: String(error),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
35
77
|
const message = extractErrorMessage(error);
|
|
36
78
|
throw new Error(`OSV batch query failed for ${this.baseUrl}: ${message}`);
|
|
37
79
|
}
|
|
38
80
|
}
|
|
39
81
|
async getVuln(id) {
|
|
82
|
+
const requestUrl = `${this.baseUrl}/v1/vulns/${encodeURIComponent(id)}`;
|
|
83
|
+
const startedAt = this.debugLog ? Date.now() : 0;
|
|
40
84
|
try {
|
|
41
|
-
|
|
85
|
+
if (this.debugLog) {
|
|
86
|
+
this.debugLog("OSV request", {
|
|
87
|
+
method: "GET",
|
|
88
|
+
url: requestUrl,
|
|
89
|
+
headers: {},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const response = await fetch(requestUrl);
|
|
93
|
+
if (this.debugLog) {
|
|
94
|
+
this.debugLog("OSV response", {
|
|
95
|
+
method: "GET",
|
|
96
|
+
url: requestUrl,
|
|
97
|
+
status: response.status,
|
|
98
|
+
statusText: response.statusText,
|
|
99
|
+
durationMs: Date.now() - startedAt,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
42
102
|
if (!response.ok) {
|
|
43
103
|
throw new Error(`OSV vuln fetch failed for ${id}: ${response.status} ${response.statusText}`);
|
|
44
104
|
}
|
|
45
105
|
return response.json();
|
|
46
106
|
}
|
|
47
107
|
catch (error) {
|
|
108
|
+
if (this.debugLog) {
|
|
109
|
+
this.debugLog("OSV request failed", {
|
|
110
|
+
method: "GET",
|
|
111
|
+
url: requestUrl,
|
|
112
|
+
durationMs: Date.now() - startedAt,
|
|
113
|
+
error: error instanceof Error
|
|
114
|
+
? { message: error.message, stack: error.stack }
|
|
115
|
+
: String(error),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
48
118
|
const message = extractErrorMessage(error);
|
|
49
119
|
throw new Error(`OSV vuln fetch failed for ${id} via ${this.baseUrl}: ${message}`);
|
|
50
120
|
}
|
package/dist/cli/args.js
CHANGED
package/dist/cli/help.js
CHANGED
|
@@ -42,6 +42,7 @@ export function printHelp() {
|
|
|
42
42
|
" --fix Apply validated direct dependency fixes and rescan",
|
|
43
43
|
" --osv-url <url> Use a custom OSV-compatible advisory endpoint",
|
|
44
44
|
" --ca-cert <path> Path to a CA certificate file for corporate SSL proxies",
|
|
45
|
+
" --debug Write verbose runtime/network diagnostics to a timestamped log file",
|
|
45
46
|
" --verbose Show detailed output with fix plan, paths, and full table",
|
|
46
47
|
" --prod-only Exclude dev dependencies where available",
|
|
47
48
|
" --fail-on <severity> Exit non-zero at or above severity (default: critical)",
|
package/dist/index.js
CHANGED
|
@@ -11,10 +11,11 @@ import { normalizeSeverity } from "./osv/severity.js";
|
|
|
11
11
|
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH, severityOrder } from "./constants.js";
|
|
12
12
|
import { chalk } from "./utils/chalk.js";
|
|
13
13
|
import { createSpinner } from "./output/spinner.js";
|
|
14
|
+
import { createDebugLogger } from "./output/debug.js";
|
|
14
15
|
import { buildSuggestedFixCommandPlan } from "./remediation/fix-commands.js";
|
|
15
16
|
import { scanProjectForPackageUsage } from "./usage/scanner.js";
|
|
16
17
|
import { getCliVersion } from "./utils/version-info.js";
|
|
17
|
-
import { blockedAdvisoryRequestHint, fetchErrorCaCertHint, isLikelyBlockedAdvisoryRequestError, isRateLimitError, isServerError, isSslCertificateError, rateLimitAdvisoryRequestHint, serverAdvisoryRequestHint, sslCertificateErrorHint, } from "./utils/network.js";
|
|
18
|
+
import { blockedAdvisoryRequestHint, fetchErrorCaCertHint, isLikelyBlockedAdvisoryRequestError, isRateLimitError, isServerError, isSslCertificateError, offlineDbSyncHint, rateLimitAdvisoryRequestHint, serverAdvisoryRequestHint, sslCertificateErrorHint, } from "./utils/network.js";
|
|
18
19
|
import { formatAdvisoryDbFreshness } from "./utils/time.js";
|
|
19
20
|
import { pluralize } from "./utils/string.js";
|
|
20
21
|
import { formatAdvisorySourceLine, logInfo, logWarn, printCacheSummary, sortFindingsForOutput } from "./output/formatters.js";
|
|
@@ -55,8 +56,16 @@ if (parsedArgs) {
|
|
|
55
56
|
const projectPath = path.resolve(projectArg || ".");
|
|
56
57
|
const batchSize = Number(options.batchSize || DEFAULT_BATCH_SIZE);
|
|
57
58
|
const searchDepth = Math.max(0, Number(options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
59
|
+
const debugSession = createDebugLogger(!!options.debug);
|
|
60
|
+
const debugLog = debugSession.log;
|
|
61
|
+
const scanStartedAt = Date.now();
|
|
58
62
|
async function main() {
|
|
59
63
|
printBanner(options);
|
|
64
|
+
debugSession.announcePath();
|
|
65
|
+
debugLog("CLI started", {
|
|
66
|
+
version: cliVersion,
|
|
67
|
+
args: process.argv.slice(2),
|
|
68
|
+
});
|
|
60
69
|
if (command === "config") {
|
|
61
70
|
const { configSubcommand } = parsedArgs;
|
|
62
71
|
if (!configSubcommand) {
|
|
@@ -90,6 +99,10 @@ if (parsedArgs) {
|
|
|
90
99
|
}
|
|
91
100
|
process.env.NODE_EXTRA_CA_CERTS = resolvedCaCert;
|
|
92
101
|
}
|
|
102
|
+
debugLog("Config loaded", {
|
|
103
|
+
caCert: resolvedCaCert ?? null,
|
|
104
|
+
nodeExtraCaCerts: process.env.NODE_EXTRA_CA_CERTS ?? null,
|
|
105
|
+
});
|
|
93
106
|
if (command === "advisories-sync") {
|
|
94
107
|
const spinner = createSpinner("Preparing advisory sync...", options);
|
|
95
108
|
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
@@ -137,8 +150,14 @@ if (parsedArgs) {
|
|
|
137
150
|
osvUrl: options.osvUrl,
|
|
138
151
|
offline: options.offline,
|
|
139
152
|
offlineDb: options.offlineDb,
|
|
153
|
+
debugLog,
|
|
140
154
|
});
|
|
141
155
|
advisorySourceLine = advisorySource.sourceLabel;
|
|
156
|
+
debugLog("Advisory source", {
|
|
157
|
+
mode: advisorySource.offline ? "offline" : "online",
|
|
158
|
+
url: options.osvUrl ?? (advisorySource.offline ? null : "https://api.osv.dev"),
|
|
159
|
+
label: advisorySourceLine,
|
|
160
|
+
});
|
|
142
161
|
if (advisorySource.offline) {
|
|
143
162
|
const metadata = advisorySource.advisoryDbMetadata;
|
|
144
163
|
advisoryDbFreshnessLine = formatAdvisoryDbFreshness(metadata?.lastSyncAt ?? null);
|
|
@@ -152,7 +171,8 @@ if (parsedArgs) {
|
|
|
152
171
|
}
|
|
153
172
|
catch (error) {
|
|
154
173
|
if (options.offline || options.offlineDb) {
|
|
155
|
-
|
|
174
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
175
|
+
throw new Error(`Offline advisory database is not available: ${reason}\n${offlineDbSyncHint(options.offlineDb).join("\n")}`);
|
|
156
176
|
}
|
|
157
177
|
throw error;
|
|
158
178
|
}
|
|
@@ -170,6 +190,16 @@ if (parsedArgs) {
|
|
|
170
190
|
}
|
|
171
191
|
let scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
172
192
|
let packages = scanInput.packages;
|
|
193
|
+
if (scanInput.filePath) {
|
|
194
|
+
debugLog("Lockfile selected", {
|
|
195
|
+
source: scanInput.source,
|
|
196
|
+
path: scanInput.filePath,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
debugLog("Packages parsed", {
|
|
200
|
+
count: packages.length,
|
|
201
|
+
source: scanInput.source,
|
|
202
|
+
});
|
|
173
203
|
logInfo(`Parsed ${packages.length} ${pluralize(packages.length, "package")} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
174
204
|
printCacheSummary(options.cacheDir, options);
|
|
175
205
|
if (scanInput.warnings.length > 0) {
|
|
@@ -178,6 +208,7 @@ if (parsedArgs) {
|
|
|
178
208
|
}
|
|
179
209
|
}
|
|
180
210
|
if (packages.length === 0) {
|
|
211
|
+
debugLog("Scan skipped", { reason: "no packages found", projectPath });
|
|
181
212
|
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
182
213
|
process.exit(0);
|
|
183
214
|
return;
|
|
@@ -189,6 +220,7 @@ if (parsedArgs) {
|
|
|
189
220
|
batchSize,
|
|
190
221
|
options,
|
|
191
222
|
projectPath,
|
|
223
|
+
debugLog,
|
|
192
224
|
});
|
|
193
225
|
const findingsBeforeFix = scanState.sorted.length;
|
|
194
226
|
let fixResult = null;
|
|
@@ -198,12 +230,14 @@ if (parsedArgs) {
|
|
|
198
230
|
projectPath,
|
|
199
231
|
totalFindings: scanState.sorted.length,
|
|
200
232
|
options,
|
|
233
|
+
debugLog,
|
|
201
234
|
});
|
|
202
235
|
if (fixResult.appliedFixCount > 0) {
|
|
203
236
|
console.log(`${chalk.cyan("⠋")} ${chalk.gray("Rescanning project...")}`);
|
|
204
237
|
scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
205
238
|
packages = scanInput.packages;
|
|
206
239
|
if (packages.length === 0) {
|
|
240
|
+
debugLog("Scan skipped", { reason: "no packages found after fix rescan", projectPath });
|
|
207
241
|
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
208
242
|
process.exit(0);
|
|
209
243
|
return;
|
|
@@ -213,6 +247,7 @@ if (parsedArgs) {
|
|
|
213
247
|
batchSize,
|
|
214
248
|
options,
|
|
215
249
|
projectPath,
|
|
250
|
+
debugLog,
|
|
216
251
|
});
|
|
217
252
|
}
|
|
218
253
|
}
|
|
@@ -279,6 +314,11 @@ if (parsedArgs) {
|
|
|
279
314
|
});
|
|
280
315
|
console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
|
|
281
316
|
}
|
|
317
|
+
debugLog("Scan finished", {
|
|
318
|
+
totalDurationMs: Date.now() - scanStartedAt,
|
|
319
|
+
findings: scanState.sorted.length,
|
|
320
|
+
packages: packages.length,
|
|
321
|
+
});
|
|
282
322
|
const failLevel = normalizeSeverity(options.failOn);
|
|
283
323
|
const shouldFail = scanState.sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
284
324
|
process.exit(shouldFail ? 1 : 0);
|
|
@@ -287,6 +327,9 @@ if (parsedArgs) {
|
|
|
287
327
|
main().catch((error) => {
|
|
288
328
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
289
329
|
console.error(chalk.red(`Error: ${errorMessage}`));
|
|
330
|
+
if (options.debug && error instanceof Error && error.stack) {
|
|
331
|
+
debugLog("Unhandled error", { message: error.message, stack: error.stack });
|
|
332
|
+
}
|
|
290
333
|
if (isSslCertificateError(error)) {
|
|
291
334
|
const [hint, ...rest] = sslCertificateErrorHint();
|
|
292
335
|
console.error(chalk.yellow(hint));
|
|
@@ -322,24 +365,44 @@ async function scanProject(params) {
|
|
|
322
365
|
directDependencyNames,
|
|
323
366
|
scanSource: params.scanInput.source,
|
|
324
367
|
scanFilePath: params.scanInput.filePath,
|
|
325
|
-
});
|
|
368
|
+
}, params.debugLog);
|
|
326
369
|
if (params.options.usage) {
|
|
327
370
|
logInfo(`Scanning project source for usage hints...`, params.options);
|
|
371
|
+
const usageStartedAt = Date.now();
|
|
328
372
|
const pkgNames = new Set(findings.map(f => f.pkg.name));
|
|
329
373
|
const usageData = scanProjectForPackageUsage(params.projectPath, pkgNames);
|
|
374
|
+
let matchedPackages = 0;
|
|
330
375
|
for (const finding of findings) {
|
|
331
376
|
const files = usageData[finding.pkg.name];
|
|
332
377
|
if (files) {
|
|
378
|
+
if (files.length > 0) {
|
|
379
|
+
matchedPackages += 1;
|
|
380
|
+
}
|
|
333
381
|
finding.usage = {
|
|
334
382
|
imported: files.length > 0,
|
|
335
383
|
files,
|
|
336
384
|
};
|
|
337
385
|
}
|
|
338
386
|
}
|
|
387
|
+
if (params.options.debug) {
|
|
388
|
+
params.debugLog("Usage scan", {
|
|
389
|
+
durationMs: Date.now() - usageStartedAt,
|
|
390
|
+
packagesChecked: pkgNames.size,
|
|
391
|
+
matchedPackages,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
339
394
|
}
|
|
340
395
|
let finalFindings = findings;
|
|
341
396
|
if (params.options.onlyUsed) {
|
|
397
|
+
const beforeCount = finalFindings.length;
|
|
342
398
|
finalFindings = finalFindings.filter(f => f.usage?.imported);
|
|
399
|
+
if (params.options.debug) {
|
|
400
|
+
params.debugLog("Findings filtered", {
|
|
401
|
+
reason: "only-used",
|
|
402
|
+
before: beforeCount,
|
|
403
|
+
after: finalFindings.length,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
343
406
|
}
|
|
344
407
|
const offline = !!params.options.offline || !!params.options.offlineDb;
|
|
345
408
|
const sorted = sortFindingsForOutput(finalFindings);
|
package/dist/osv/cache.js
CHANGED
|
@@ -14,15 +14,23 @@ export function getCacheFilePath(cacheDirOverride) {
|
|
|
14
14
|
export function isEntryStale(entry, nowMs) {
|
|
15
15
|
return nowMs - new Date(entry.cachedAt).getTime() > 30 * 60 * 1000;
|
|
16
16
|
}
|
|
17
|
-
export function loadCache(cacheDirOverride) {
|
|
17
|
+
export function loadCache(cacheDirOverride, debugLog) {
|
|
18
18
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
19
19
|
if (!fs.existsSync(filePath)) {
|
|
20
|
+
debugLog?.("Cache loaded", {
|
|
21
|
+
path: filePath,
|
|
22
|
+
queryEntries: 0,
|
|
23
|
+
detailEntries: 0,
|
|
24
|
+
exists: false,
|
|
25
|
+
});
|
|
20
26
|
return createEmptyCache();
|
|
21
27
|
}
|
|
22
28
|
try {
|
|
23
29
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
24
|
-
if (typeof parsed !== "object" || parsed === null)
|
|
30
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
31
|
+
debugLog?.("Cache load failed", { path: filePath, reason: "invalid root object" });
|
|
25
32
|
return createEmptyCache();
|
|
33
|
+
}
|
|
26
34
|
const entries = (parsed.entries && typeof parsed.entries === "object")
|
|
27
35
|
? parsed.entries
|
|
28
36
|
: {};
|
|
@@ -33,11 +41,25 @@ export function loadCache(cacheDirOverride) {
|
|
|
33
41
|
for (const [key, vulnIds] of Object.entries(rawQuery ?? {})) {
|
|
34
42
|
queryEntries[key] = { vulnIds: Array.isArray(vulnIds) ? vulnIds : [], cachedAt: new Date(0).toISOString() };
|
|
35
43
|
}
|
|
36
|
-
|
|
44
|
+
const migrated = { version: 3, createdAt: String(parsed.createdAt ?? new Date().toISOString()), entries, queryEntries };
|
|
45
|
+
debugLog?.("Cache loaded", {
|
|
46
|
+
path: filePath,
|
|
47
|
+
queryEntries: Object.keys(migrated.queryEntries).length,
|
|
48
|
+
detailEntries: Object.keys(migrated.entries).length,
|
|
49
|
+
migratedFrom: 2,
|
|
50
|
+
});
|
|
51
|
+
return migrated;
|
|
37
52
|
}
|
|
38
53
|
// v1 or unknown: no queryEntries
|
|
39
54
|
if (parsed.version !== 3) {
|
|
40
|
-
|
|
55
|
+
const upgraded = { version: 3, createdAt: new Date().toISOString(), entries, queryEntries: {} };
|
|
56
|
+
debugLog?.("Cache loaded", {
|
|
57
|
+
path: filePath,
|
|
58
|
+
queryEntries: 0,
|
|
59
|
+
detailEntries: Object.keys(upgraded.entries).length,
|
|
60
|
+
migratedFrom: parsed.version ?? "unknown",
|
|
61
|
+
});
|
|
62
|
+
return upgraded;
|
|
41
63
|
}
|
|
42
64
|
const rawQuery = parsed.queryEntries;
|
|
43
65
|
const queryEntries = {};
|
|
@@ -46,19 +68,36 @@ export function loadCache(cacheDirOverride) {
|
|
|
46
68
|
queryEntries[key] = value;
|
|
47
69
|
}
|
|
48
70
|
}
|
|
49
|
-
|
|
71
|
+
const loaded = {
|
|
50
72
|
version: 3,
|
|
51
73
|
createdAt: String(parsed.createdAt ?? new Date().toISOString()),
|
|
52
74
|
entries,
|
|
53
75
|
queryEntries,
|
|
54
76
|
};
|
|
77
|
+
debugLog?.("Cache loaded", {
|
|
78
|
+
path: filePath,
|
|
79
|
+
queryEntries: Object.keys(loaded.queryEntries).length,
|
|
80
|
+
detailEntries: Object.keys(loaded.entries).length,
|
|
81
|
+
});
|
|
82
|
+
return loaded;
|
|
55
83
|
}
|
|
56
|
-
catch {
|
|
84
|
+
catch (error) {
|
|
85
|
+
debugLog?.("Cache load failed", {
|
|
86
|
+
path: filePath,
|
|
87
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
88
|
+
});
|
|
57
89
|
return createEmptyCache();
|
|
58
90
|
}
|
|
59
91
|
}
|
|
60
|
-
export function saveCache(cache, cacheDirOverride) {
|
|
92
|
+
export function saveCache(cache, cacheDirOverride, debugLog) {
|
|
61
93
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
62
94
|
cache.createdAt = new Date().toISOString();
|
|
63
95
|
fs.writeFileSync(filePath, JSON.stringify(cache, null, 2), "utf8");
|
|
96
|
+
if (debugLog) {
|
|
97
|
+
debugLog("Cache saved", {
|
|
98
|
+
path: filePath,
|
|
99
|
+
queryEntries: Object.keys(cache.queryEntries).length,
|
|
100
|
+
detailEntries: Object.keys(cache.entries).length,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
64
103
|
}
|
package/dist/output/sarif.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
4
3
|
import { getRecommendedAction } from "./formatters.js";
|
|
5
4
|
import { getCliVersion } from "../utils/version-info.js";
|
|
6
5
|
import { severityToSarifLevel } from "../utils/severity.js";
|
|
@@ -19,13 +18,12 @@ export function deriveLockfileUri(scanInput) {
|
|
|
19
18
|
return path.basename(scanInput.filePath);
|
|
20
19
|
return LOCKFILE_NAMES[scanInput.source] ?? "lockfile";
|
|
21
20
|
}
|
|
22
|
-
export function buildSarifOutput(findings, lockfileUri, version,
|
|
21
|
+
export function buildSarifOutput(findings, lockfileUri, version, _plan) {
|
|
23
22
|
const ruleMap = new Map();
|
|
24
23
|
const results = [];
|
|
25
24
|
for (const finding of findings) {
|
|
26
25
|
const level = severityToSarifLevel(finding.severity);
|
|
27
26
|
const action = getRecommendedAction(finding);
|
|
28
|
-
const runnableFixCommand = plan ? findSuggestedCommandForFinding(plan, finding) : null;
|
|
29
27
|
const location = {
|
|
30
28
|
physicalLocation: {
|
|
31
29
|
artifactLocation: { uri: lockfileUri, uriBaseId: "%SRCROOT%" },
|
|
@@ -47,18 +45,14 @@ export function buildSarifOutput(findings, lockfileUri, version, plan) {
|
|
|
47
45
|
properties: { tags: ["security", "dependency"] },
|
|
48
46
|
});
|
|
49
47
|
}
|
|
50
|
-
|
|
48
|
+
results.push({
|
|
51
49
|
ruleId,
|
|
52
50
|
level,
|
|
53
51
|
message: {
|
|
54
52
|
text: `${finding.pkg.name}@${finding.pkg.version} is vulnerable (${finding.severity}). ${action}`,
|
|
55
53
|
},
|
|
56
54
|
locations: [location],
|
|
57
|
-
};
|
|
58
|
-
if (runnableFixCommand) {
|
|
59
|
-
result.fixes = [{ description: { text: runnableFixCommand }, artifactChanges: [] }];
|
|
60
|
-
}
|
|
61
|
-
results.push(result);
|
|
55
|
+
});
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
return {
|
package/dist/output/spinner.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
2
|
import { chalk } from "../utils/chalk.js";
|
|
3
3
|
export function createSpinner(initialMessage, options) {
|
|
4
|
-
const enabled = Boolean(process.stdout.isTTY);
|
|
4
|
+
const enabled = Boolean(process.stdout.isTTY) && !options?.json;
|
|
5
5
|
if (!enabled) {
|
|
6
6
|
return {
|
|
7
7
|
update: () => { },
|
|
@@ -219,6 +219,10 @@ function normalizePnpmDepRefV9(depName, depRef) {
|
|
|
219
219
|
return null;
|
|
220
220
|
if (looksLikeVersion(cleaned))
|
|
221
221
|
return `${depName}@${cleaned}`;
|
|
222
|
+
// Handle aliased deps where the ref is a full "pkgName@version" key (e.g. '@remix-run/dev': '@vercel/remix-run-dev@1.16.1')
|
|
223
|
+
const atIdx = cleaned.lastIndexOf("@");
|
|
224
|
+
if (atIdx > 0 && looksLikeVersion(cleaned.slice(atIdx + 1)))
|
|
225
|
+
return cleaned;
|
|
222
226
|
}
|
|
223
227
|
if (depRef && typeof depRef === "object") {
|
|
224
228
|
const version = depRef.version ?? depRef.specifier;
|
|
@@ -71,13 +71,26 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
71
71
|
];
|
|
72
72
|
for (const finding of orderedFindings) {
|
|
73
73
|
const urgent = finding.severity === "critical" || finding.severity === "high";
|
|
74
|
-
if (finding.relationship === "direct"
|
|
74
|
+
if (finding.relationship === "direct") {
|
|
75
75
|
const hasValidatedField = Object.prototype.hasOwnProperty.call(finding, "validatedFirstFixedVersion");
|
|
76
76
|
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
77
77
|
// In offline mode validateDirectFixTargets never runs, so an unset
|
|
78
78
|
// validatedFirstFixedVersion is "did not validate" rather than "validation
|
|
79
79
|
// failed" — fall back to the advisory hint instead of dropping the target.
|
|
80
80
|
const validatedFieldOk = offline || !hasValidatedField || finding.validatedFirstFixedVersion !== null;
|
|
81
|
+
const allVersionsVulnerable = finding.validatedTargetScannedVersions != null &&
|
|
82
|
+
finding.validatedTargetKnownVulnerableVersions != null &&
|
|
83
|
+
finding.validatedTargetScannedVersions > 0 &&
|
|
84
|
+
finding.validatedTargetKnownVulnerableVersions >= finding.validatedTargetScannedVersions;
|
|
85
|
+
if (directTarget && allVersionsVulnerable) {
|
|
86
|
+
skippedByKey.set(`direct:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
87
|
+
package: finding.pkg.name,
|
|
88
|
+
version: finding.pkg.version,
|
|
89
|
+
relationship: finding.relationship,
|
|
90
|
+
reason: `No safe upgrade: all ${finding.validatedTargetScannedVersions} scanned ${pluralize(finding.validatedTargetScannedVersions ?? 0, "version")} are still known-vulnerable. This package may be unmaintained.`,
|
|
91
|
+
});
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
81
94
|
if (directTarget &&
|
|
82
95
|
isUpgradeTarget(finding.pkg.version, directTarget) &&
|
|
83
96
|
validatedFieldOk) {
|
|
@@ -132,6 +145,15 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
132
145
|
}
|
|
133
146
|
continue;
|
|
134
147
|
}
|
|
148
|
+
if (finding.relationship === "unknown") {
|
|
149
|
+
skippedByKey.set(`unknown:${finding.pkg.name}@${finding.pkg.version}`, {
|
|
150
|
+
package: finding.pkg.name,
|
|
151
|
+
version: finding.pkg.version,
|
|
152
|
+
relationship: finding.relationship,
|
|
153
|
+
reason: `Dependency path for ${finding.pkg.name}@${finding.pkg.version} could not be resolved in the lockfile. Inspect your lockfile to identify which package pulls it in.`,
|
|
154
|
+
});
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
135
157
|
if (packageManager === "npm" &&
|
|
136
158
|
finding.relationship === "transitive" &&
|
|
137
159
|
finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
@@ -345,8 +367,14 @@ export function findSuggestedCommandForFinding(plan, finding) {
|
|
|
345
367
|
(item.package === finding.recommendedNpmTransitiveRemediation.package || item.package === finding.pkg.name));
|
|
346
368
|
}
|
|
347
369
|
if (finding.recommendedParentUpgrade) {
|
|
348
|
-
|
|
349
|
-
|
|
370
|
+
if (item.package !== finding.recommendedParentUpgrade.package)
|
|
371
|
+
return false;
|
|
372
|
+
if (item.targetVersion === finding.recommendedParentUpgrade.targetVersion)
|
|
373
|
+
return true;
|
|
374
|
+
// A command targeting a higher version also satisfies a lower-version recommendation
|
|
375
|
+
return (looksLikeVersion(item.targetVersion) &&
|
|
376
|
+
looksLikeVersion(finding.recommendedParentUpgrade.targetVersion) &&
|
|
377
|
+
compareVersions(item.targetVersion, finding.recommendedParentUpgrade.targetVersion) >= 0);
|
|
350
378
|
}
|
|
351
379
|
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
352
380
|
return item.package === finding.pkg.name && item.targetVersion === directTarget;
|
|
@@ -407,7 +435,11 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
407
435
|
if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
|
|
408
436
|
merged.targetVersion = next.targetVersion;
|
|
409
437
|
merged.currentVersion = next.currentVersion ?? merged.currentVersion;
|
|
410
|
-
|
|
438
|
+
// Keep the reason from the higher-severity finding so the most critical issue is visible
|
|
439
|
+
// in the context column. Only update the reason if next has strictly higher severity.
|
|
440
|
+
if (severityOrder[next.severity] > severityOrder[existing.severity]) {
|
|
441
|
+
merged.reason = next.reason;
|
|
442
|
+
}
|
|
411
443
|
merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
|
|
412
444
|
merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
|
|
413
445
|
}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
2
|
const packumentCache = new Map();
|
|
3
3
|
const DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
4
|
+
let registryDebugLog;
|
|
5
|
+
let registryBatchCounter = 0;
|
|
6
|
+
export function configureNpmRegistryDebug(debugLog) {
|
|
7
|
+
registryDebugLog = debugLog;
|
|
8
|
+
registryBatchCounter = 0;
|
|
9
|
+
}
|
|
10
|
+
function nextRegistryBatchId() {
|
|
11
|
+
registryBatchCounter += 1;
|
|
12
|
+
return `r-${String(registryBatchCounter).padStart(2, "0")}`;
|
|
13
|
+
}
|
|
4
14
|
export function clearPackumentCache() {
|
|
5
15
|
packumentCache.clear();
|
|
6
16
|
}
|
|
@@ -11,17 +21,50 @@ export async function fetchPackument(packageName) {
|
|
|
11
21
|
const url = `${DEFAULT_NPM_REGISTRY_URL}/${encodeURIComponent(packageName)
|
|
12
22
|
.replace(/%40/g, "@")
|
|
13
23
|
.replace(/%2F/g, "/")}`;
|
|
24
|
+
const batchId = registryDebugLog ? nextRegistryBatchId() : "";
|
|
25
|
+
const startedAt = registryDebugLog ? Date.now() : 0;
|
|
26
|
+
if (registryDebugLog) {
|
|
27
|
+
registryDebugLog("Registry fetch", { batchId, package: packageName, url });
|
|
28
|
+
}
|
|
14
29
|
try {
|
|
15
30
|
const response = await fetch(url);
|
|
16
31
|
if (!response.ok) {
|
|
32
|
+
if (registryDebugLog) {
|
|
33
|
+
registryDebugLog("Registry response", {
|
|
34
|
+
batchId,
|
|
35
|
+
package: packageName,
|
|
36
|
+
status: response.status,
|
|
37
|
+
durationMs: Date.now() - startedAt,
|
|
38
|
+
versionsCount: 0,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
17
41
|
packumentCache.set(packageName, null);
|
|
18
42
|
return null;
|
|
19
43
|
}
|
|
20
44
|
const json = (await response.json());
|
|
45
|
+
if (registryDebugLog) {
|
|
46
|
+
registryDebugLog("Registry response", {
|
|
47
|
+
batchId,
|
|
48
|
+
package: packageName,
|
|
49
|
+
status: response.status,
|
|
50
|
+
durationMs: Date.now() - startedAt,
|
|
51
|
+
versionsCount: Object.keys(json.versions ?? {}).length,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
21
54
|
packumentCache.set(packageName, json);
|
|
22
55
|
return json;
|
|
23
56
|
}
|
|
24
|
-
catch {
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (registryDebugLog) {
|
|
59
|
+
registryDebugLog("Registry fetch failed", {
|
|
60
|
+
batchId,
|
|
61
|
+
package: packageName,
|
|
62
|
+
durationMs: Date.now() - startedAt,
|
|
63
|
+
error: error instanceof Error
|
|
64
|
+
? { message: error.message, stack: error.stack }
|
|
65
|
+
: String(error),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
25
68
|
packumentCache.set(packageName, null);
|
|
26
69
|
return null;
|
|
27
70
|
}
|
|
@@ -28,11 +28,17 @@ export async function resolveRecommendedParentUpgrade(finding, packages, directD
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
// Best-effort fallback for deeper chains.
|
|
31
|
+
// Use the immediate child of the direct parent (not the immediate parent of the vulnerable
|
|
32
|
+
// package) — that's what the direct parent actually lists in its own dependencies.
|
|
33
|
+
const directParentIdx = viaPath.indexOf(directParentName);
|
|
34
|
+
if (directParentIdx < 0)
|
|
35
|
+
return null;
|
|
36
|
+
const immediateChildName = viaPath[directParentIdx + 1] ?? immediateParentName;
|
|
31
37
|
return findUpgradeForImmediateIntermediate({
|
|
32
38
|
directParentName,
|
|
33
39
|
directParentVersion: directParent.version,
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
immediateChildName,
|
|
41
|
+
immediateChildInstalledVersion: findPackageVersion(packages, immediateChildName, viaPath.slice(0, directParentIdx + 2)) ?? "",
|
|
36
42
|
vulnerableName,
|
|
37
43
|
viaPath,
|
|
38
44
|
});
|
|
@@ -123,7 +129,7 @@ async function findUpgradeForExactDirectChild(args) {
|
|
|
123
129
|
return null;
|
|
124
130
|
}
|
|
125
131
|
async function findUpgradeForImmediateIntermediate(args) {
|
|
126
|
-
if (!args.
|
|
132
|
+
if (!args.immediateChildInstalledVersion || !looksLikeVersion(args.immediateChildInstalledVersion)) {
|
|
127
133
|
return null;
|
|
128
134
|
}
|
|
129
135
|
const packument = await fetchPackument(args.directParentName);
|
|
@@ -134,12 +140,12 @@ async function findUpgradeForImmediateIntermediate(args) {
|
|
|
134
140
|
.sort(compareVersions);
|
|
135
141
|
for (const version of versions) {
|
|
136
142
|
const manifest = packument?.versions?.[version];
|
|
137
|
-
const depRange = manifest?.dependencies?.[args.
|
|
138
|
-
manifest?.optionalDependencies?.[args.
|
|
143
|
+
const depRange = manifest?.dependencies?.[args.immediateChildName] ??
|
|
144
|
+
manifest?.optionalDependencies?.[args.immediateChildName];
|
|
139
145
|
if (!depRange)
|
|
140
146
|
continue;
|
|
141
|
-
const
|
|
142
|
-
if (!
|
|
147
|
+
const stillAllowsInstalledChild = versionSatisfiesRange(args.immediateChildInstalledVersion, depRange);
|
|
148
|
+
if (!stillAllowsInstalledChild) {
|
|
143
149
|
return {
|
|
144
150
|
package: args.directParentName,
|
|
145
151
|
currentVersion: args.directParentVersion,
|
|
@@ -147,7 +153,7 @@ async function findUpgradeForImmediateIntermediate(args) {
|
|
|
147
153
|
viaPath: args.viaPath,
|
|
148
154
|
vulnerablePackage: args.vulnerableName,
|
|
149
155
|
confidence: "best-effort",
|
|
150
|
-
reason: `${args.directParentName}@${version} no longer allows ${args.
|
|
156
|
+
reason: `${args.directParentName}@${version} no longer allows ${args.immediateChildName}@${args.immediateChildInstalledVersion} in the current path`,
|
|
151
157
|
};
|
|
152
158
|
}
|
|
153
159
|
}
|
package/dist/scanner.js
CHANGED
|
@@ -8,7 +8,8 @@ import { LocalAdvisorySource } from "./advisory/local-advisory-source.js";
|
|
|
8
8
|
import { LocalAdvisoryDatabase } from "./advisory/local-db.js";
|
|
9
9
|
import { ADVISORY_DB_STALE_AFTER_MS, getDefaultAdvisoryDbPath } from "./advisory/osv-sync.js";
|
|
10
10
|
import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js";
|
|
11
|
-
import { resolveLowestKnownNonVulnerableVersion, resolvePublishedFixVersion } from "./remediation/npm-registry.js";
|
|
11
|
+
import { configureNpmRegistryDebug, resolveLowestKnownNonVulnerableVersion, resolvePublishedFixVersion, } from "./remediation/npm-registry.js";
|
|
12
|
+
import { countBySeverity } from "./utils/severity.js";
|
|
12
13
|
import { resolveNpmTransitiveRemediation, resolveTransitiveRemediationViaRegistry } from "./remediation/npm-transitive-resolution.js";
|
|
13
14
|
import { loadNpmLockGraph } from "./parsers/npm-lock-graph.js";
|
|
14
15
|
import { buildPnpmWorkspaceMap } from "./parsers/pnpm-lock.js";
|
|
@@ -30,7 +31,7 @@ export function createAdvisorySource(options) {
|
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
return {
|
|
33
|
-
advisorySource: new OsvAdvisorySource(options?.osvUrl),
|
|
34
|
+
advisorySource: new OsvAdvisorySource(options?.osvUrl, options?.debugLog),
|
|
34
35
|
offline: false,
|
|
35
36
|
sourceLabel: options?.osvUrl
|
|
36
37
|
? `custom OSV endpoint (${options.osvUrl})`
|
|
@@ -43,11 +44,13 @@ export function createAdvisorySource(options) {
|
|
|
43
44
|
function getPackageCacheKey(pkg) {
|
|
44
45
|
return `${pkg.ecosystem}:${pkg.name}@${pkg.version}`;
|
|
45
46
|
}
|
|
46
|
-
export async function scanPackages(packages, batchSize, options, context) {
|
|
47
|
+
export async function scanPackages(packages, batchSize, options, context, debugLog) {
|
|
48
|
+
const log = debugLog ?? (() => { });
|
|
47
49
|
const sourceContext = createAdvisorySource({
|
|
48
50
|
osvUrl: options.osvUrl,
|
|
49
51
|
offline: options.offline,
|
|
50
52
|
offlineDb: options.offlineDb,
|
|
53
|
+
debugLog: log,
|
|
51
54
|
});
|
|
52
55
|
const offline = sourceContext.offline;
|
|
53
56
|
const cacheDirOverride = options.cacheDir;
|
|
@@ -55,28 +58,43 @@ export async function scanPackages(packages, batchSize, options, context) {
|
|
|
55
58
|
? "Scanning dependencies against the local advisory database..."
|
|
56
59
|
: "Scanning dependencies against OSV...", options);
|
|
57
60
|
const advisorySource = sourceContext.advisorySource;
|
|
58
|
-
|
|
61
|
+
if (!offline && options.debug) {
|
|
62
|
+
configureNpmRegistryDebug(log);
|
|
63
|
+
}
|
|
64
|
+
const cache = loadCache(cacheDirOverride, options.debug ? log : undefined);
|
|
59
65
|
try {
|
|
60
66
|
const results = [];
|
|
61
67
|
const uncachedPackages = [];
|
|
62
68
|
if (!offline) {
|
|
63
69
|
const nowMs = Date.now();
|
|
70
|
+
let hits = 0;
|
|
71
|
+
let misses = 0;
|
|
64
72
|
for (const pkg of packages) {
|
|
65
73
|
const cacheKey = getPackageCacheKey(pkg);
|
|
66
74
|
if (!options.noCache) {
|
|
67
75
|
const cached = cache.queryEntries[cacheKey];
|
|
68
76
|
if (cached && !isEntryStale(cached, nowMs)) {
|
|
77
|
+
hits += 1;
|
|
69
78
|
if (cached.vulnIds.length > 0) {
|
|
70
79
|
results.push({ pkg, vulnIds: cached.vulnIds });
|
|
71
80
|
}
|
|
72
81
|
continue;
|
|
73
82
|
}
|
|
74
83
|
}
|
|
84
|
+
misses += 1;
|
|
75
85
|
uncachedPackages.push(pkg);
|
|
76
86
|
}
|
|
77
87
|
const chunks = chunk(uncachedPackages, batchSize);
|
|
88
|
+
const reason = options.noCache ? "no-cache mode" : "stale or missing entry";
|
|
89
|
+
log("Cache check", { hits, misses, reason, uncachedBatches: chunks.length });
|
|
78
90
|
spinner.update(`Scanning OSV in ${chunks.length} parallel ${pluralize(chunks.length, "batch", "batches")}...`);
|
|
79
|
-
const
|
|
91
|
+
const osvScanStartedAt = Date.now();
|
|
92
|
+
let batchCounter = 0;
|
|
93
|
+
const allAdvisoryResults = await runWithConcurrency(chunks, 5, c => {
|
|
94
|
+
batchCounter += 1;
|
|
95
|
+
const batchId = `b-${String(batchCounter).padStart(2, "0")}`;
|
|
96
|
+
return advisorySource.queryBatch(c, { batchId });
|
|
97
|
+
});
|
|
80
98
|
for (let i = 0; i < chunks.length; i++) {
|
|
81
99
|
const chunkItems = chunks[i];
|
|
82
100
|
const rows = allAdvisoryResults[i] ?? [];
|
|
@@ -90,6 +108,13 @@ export async function scanPackages(packages, batchSize, options, context) {
|
|
|
90
108
|
}
|
|
91
109
|
}
|
|
92
110
|
}
|
|
111
|
+
if (chunks.length > 0) {
|
|
112
|
+
log("OSV scan complete", {
|
|
113
|
+
totalBatches: chunks.length,
|
|
114
|
+
totalDurationMs: Date.now() - osvScanStartedAt,
|
|
115
|
+
packagesWithVulns: results.length,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
93
118
|
if (chunks.length === 0) {
|
|
94
119
|
spinner.succeed("Loaded package matches from cache");
|
|
95
120
|
}
|
|
@@ -98,7 +123,7 @@ export async function scanPackages(packages, batchSize, options, context) {
|
|
|
98
123
|
}
|
|
99
124
|
}
|
|
100
125
|
else {
|
|
101
|
-
const advisoryResult = await advisorySource.queryBatch(packages);
|
|
126
|
+
const advisoryResult = await advisorySource.queryBatch(packages, { batchId: "offline" });
|
|
102
127
|
const rows = advisoryResult ?? [];
|
|
103
128
|
for (let i = 0; i < packages.length; i++) {
|
|
104
129
|
const pkg = packages[i];
|
|
@@ -165,7 +190,7 @@ export async function scanPackages(packages, batchSize, options, context) {
|
|
|
165
190
|
}
|
|
166
191
|
}
|
|
167
192
|
if (!offline && idSet.size > 0) {
|
|
168
|
-
saveCache(cache, cacheDirOverride);
|
|
193
|
+
saveCache(cache, cacheDirOverride, options.debug ? log : undefined);
|
|
169
194
|
}
|
|
170
195
|
const findings = results.map(result => {
|
|
171
196
|
const vulnerabilities = result.vulnIds
|
|
@@ -193,35 +218,59 @@ export async function scanPackages(packages, batchSize, options, context) {
|
|
|
193
218
|
};
|
|
194
219
|
});
|
|
195
220
|
const npmTransitiveGraph = context?.scanSource === "package-lock" && context.scanFilePath
|
|
196
|
-
? createNpmTransitiveGraphFromLockfile(context.scanFilePath)
|
|
221
|
+
? createNpmTransitiveGraphFromLockfile(context.scanFilePath, log, packages.length)
|
|
197
222
|
: null;
|
|
198
223
|
const npmWorkspaceMap = (() => {
|
|
199
224
|
try {
|
|
200
225
|
return context?.scanSource === "package-lock" && context.scanFilePath
|
|
201
226
|
? buildNpmWorkspaceMap(context.scanFilePath) : null;
|
|
202
227
|
}
|
|
203
|
-
catch {
|
|
228
|
+
catch (error) {
|
|
229
|
+
log("Workspace map", {
|
|
230
|
+
type: "npm",
|
|
231
|
+
status: "failed",
|
|
232
|
+
error: error instanceof Error ? error.message : String(error),
|
|
233
|
+
});
|
|
204
234
|
return null;
|
|
205
235
|
}
|
|
206
236
|
})();
|
|
237
|
+
if (npmWorkspaceMap) {
|
|
238
|
+
log("Workspace map", { type: "npm", workspaces: npmWorkspaceMap.size });
|
|
239
|
+
}
|
|
207
240
|
const pnpmWorkspaceMap = (() => {
|
|
208
241
|
try {
|
|
209
242
|
return context?.scanSource === "pnpm-lock" && context.scanFilePath
|
|
210
243
|
? buildPnpmWorkspaceMap(context.scanFilePath) : null;
|
|
211
244
|
}
|
|
212
|
-
catch {
|
|
245
|
+
catch (error) {
|
|
246
|
+
log("Workspace map", {
|
|
247
|
+
type: "pnpm",
|
|
248
|
+
status: "failed",
|
|
249
|
+
error: error instanceof Error ? error.message : String(error),
|
|
250
|
+
});
|
|
213
251
|
return null;
|
|
214
252
|
}
|
|
215
253
|
})();
|
|
254
|
+
if (pnpmWorkspaceMap) {
|
|
255
|
+
log("Workspace map", { type: "pnpm", workspaces: pnpmWorkspaceMap.size });
|
|
256
|
+
}
|
|
216
257
|
const bunWorkspaceMap = (() => {
|
|
217
258
|
try {
|
|
218
259
|
return context?.scanSource === "bun-lock" && context.scanFilePath
|
|
219
260
|
? buildBunWorkspaceMap(context.scanFilePath) : null;
|
|
220
261
|
}
|
|
221
|
-
catch {
|
|
262
|
+
catch (error) {
|
|
263
|
+
log("Workspace map", {
|
|
264
|
+
type: "bun",
|
|
265
|
+
status: "failed",
|
|
266
|
+
error: error instanceof Error ? error.message : String(error),
|
|
267
|
+
});
|
|
222
268
|
return null;
|
|
223
269
|
}
|
|
224
270
|
})();
|
|
271
|
+
if (bunWorkspaceMap) {
|
|
272
|
+
log("Workspace map", { type: "bun", workspaces: bunWorkspaceMap.size });
|
|
273
|
+
}
|
|
225
274
|
const lockfileWorkspaceMap = pnpmWorkspaceMap ?? bunWorkspaceMap ?? null;
|
|
226
275
|
const npmRemediationCache = new Map();
|
|
227
276
|
const parentUpgradeCache = new Map();
|
|
@@ -239,7 +288,7 @@ export async function scanPackages(packages, batchSize, options, context) {
|
|
|
239
288
|
if (!offline) {
|
|
240
289
|
await validateDirectFixTargets(findings, (finding) => {
|
|
241
290
|
updateAnalysisProgress("validating fix target for", `${finding.pkg.name}@${finding.pkg.version}`);
|
|
242
|
-
});
|
|
291
|
+
}, log);
|
|
243
292
|
}
|
|
244
293
|
for (const finding of findings) {
|
|
245
294
|
if (finding.relationship !== "transitive")
|
|
@@ -326,8 +375,19 @@ export async function scanPackages(packages, batchSize, options, context) {
|
|
|
326
375
|
}
|
|
327
376
|
}
|
|
328
377
|
else if (!offline) {
|
|
329
|
-
await validateDirectFixTargets(findings);
|
|
378
|
+
await validateDirectFixTargets(findings, undefined, log);
|
|
330
379
|
}
|
|
380
|
+
const severityCounts = countBySeverity(findings);
|
|
381
|
+
log("Findings classified", {
|
|
382
|
+
total: findings.length,
|
|
383
|
+
direct: findings.filter(finding => finding.relationship === "direct").length,
|
|
384
|
+
transitive: findings.filter(finding => finding.relationship === "transitive").length,
|
|
385
|
+
critical: severityCounts.critical,
|
|
386
|
+
high: severityCounts.high,
|
|
387
|
+
medium: severityCounts.medium,
|
|
388
|
+
low: severityCounts.low,
|
|
389
|
+
unknown: severityCounts.unknown,
|
|
390
|
+
});
|
|
331
391
|
return findings;
|
|
332
392
|
}
|
|
333
393
|
catch (error) {
|
|
@@ -338,9 +398,10 @@ export async function scanPackages(packages, batchSize, options, context) {
|
|
|
338
398
|
sourceContext.cleanup();
|
|
339
399
|
}
|
|
340
400
|
}
|
|
341
|
-
function createNpmTransitiveGraphFromLockfile(filePath) {
|
|
401
|
+
function createNpmTransitiveGraphFromLockfile(filePath, log, packageCount) {
|
|
342
402
|
try {
|
|
343
403
|
const lockGraph = loadNpmLockGraph(filePath, { includePaths: false });
|
|
404
|
+
log("npm transitive graph", { status: "built", nodes: packageCount });
|
|
344
405
|
return {
|
|
345
406
|
nodeIdsFor(name, version) {
|
|
346
407
|
return lockGraph.nodeIdsFor(name, version);
|
|
@@ -359,14 +420,26 @@ function createNpmTransitiveGraphFromLockfile(filePath) {
|
|
|
359
420
|
},
|
|
360
421
|
};
|
|
361
422
|
}
|
|
362
|
-
catch {
|
|
423
|
+
catch (error) {
|
|
424
|
+
log("npm transitive graph", {
|
|
425
|
+
status: "failed",
|
|
426
|
+
error: error instanceof Error ? error.message : String(error),
|
|
427
|
+
});
|
|
363
428
|
return null;
|
|
364
429
|
}
|
|
365
430
|
}
|
|
366
|
-
async function validateDirectFixTargets(findings, onFinding) {
|
|
431
|
+
async function validateDirectFixTargets(findings, onFinding, debugLog) {
|
|
367
432
|
const directCandidates = findings.filter(finding => finding.vulnerabilities.length > 0);
|
|
368
433
|
for (const finding of directCandidates) {
|
|
369
434
|
onFinding?.(finding);
|
|
435
|
+
const logFixValidation = () => {
|
|
436
|
+
debugLog?.("Fix validation", {
|
|
437
|
+
package: finding.pkg.name,
|
|
438
|
+
installed: finding.pkg.version,
|
|
439
|
+
resolvedFixVersion: finding.validatedFirstFixedVersion,
|
|
440
|
+
verified: Boolean(finding.validatedFirstFixedVersion),
|
|
441
|
+
});
|
|
442
|
+
};
|
|
370
443
|
const lowestKnownResolution = await resolveLowestKnownNonVulnerableVersion(finding.pkg.name, finding.pkg.version, finding.vulnerabilities);
|
|
371
444
|
const fixedVersionHint = finding.firstFixedVersion;
|
|
372
445
|
if (lowestKnownResolution.resolvedVersion) {
|
|
@@ -375,16 +448,19 @@ async function validateDirectFixTargets(findings, onFinding) {
|
|
|
375
448
|
finding.validatedTargetKnownVulnerableVersions = lowestKnownResolution.candidatesKnownVulnerable;
|
|
376
449
|
if (!fixedVersionHint || fixedVersionHint === lowestKnownResolution.resolvedVersion) {
|
|
377
450
|
finding.fixVersionValidationNote = null;
|
|
451
|
+
logFixValidation();
|
|
378
452
|
continue;
|
|
379
453
|
}
|
|
380
454
|
const hintResolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
|
|
381
455
|
if (hintResolution.resolvedVersion === lowestKnownResolution.resolvedVersion &&
|
|
382
456
|
hintResolution.note) {
|
|
383
457
|
finding.fixVersionValidationNote = hintResolution.note;
|
|
458
|
+
logFixValidation();
|
|
384
459
|
continue;
|
|
385
460
|
}
|
|
386
461
|
finding.fixVersionValidationNote =
|
|
387
462
|
`Advisory fixed-version hint ${fixedVersionHint} is still known vulnerable for ${finding.pkg.name}; scanned ${lowestKnownResolution.candidatesChecked} package ${pluralize(lowestKnownResolution.candidatesChecked, "version")} above current version (${lowestKnownResolution.candidatesKnownVulnerable} still known vulnerable); using lowest known non-vulnerable version ${lowestKnownResolution.resolvedVersion}.`;
|
|
463
|
+
logFixValidation();
|
|
388
464
|
continue;
|
|
389
465
|
}
|
|
390
466
|
if (!fixedVersionHint) {
|
|
@@ -392,6 +468,7 @@ async function validateDirectFixTargets(findings, onFinding) {
|
|
|
392
468
|
finding.fixVersionValidationNote = lowestKnownResolution.note;
|
|
393
469
|
finding.validatedTargetScannedVersions = null;
|
|
394
470
|
finding.validatedTargetKnownVulnerableVersions = null;
|
|
471
|
+
logFixValidation();
|
|
395
472
|
continue;
|
|
396
473
|
}
|
|
397
474
|
const resolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
|
|
@@ -399,6 +476,7 @@ async function validateDirectFixTargets(findings, onFinding) {
|
|
|
399
476
|
finding.fixVersionValidationNote = resolution.note ?? lowestKnownResolution.note;
|
|
400
477
|
finding.validatedTargetScannedVersions = null;
|
|
401
478
|
finding.validatedTargetKnownVulnerableVersions = null;
|
|
479
|
+
logFixValidation();
|
|
402
480
|
}
|
|
403
481
|
}
|
|
404
482
|
function isAdvisoryDbStale(metadata) {
|
package/dist/utils/fix-runner.js
CHANGED
|
@@ -14,7 +14,9 @@ export function buildFixCommandParts(packageManager, targets) {
|
|
|
14
14
|
}
|
|
15
15
|
return ["yarn", "add", ...targets.map(target => `${target.package}@${target.targetVersion}`)];
|
|
16
16
|
}
|
|
17
|
-
export async function runInstallCommand(command, args, cwd) {
|
|
17
|
+
export async function runInstallCommand(command, args, cwd, debugLog) {
|
|
18
|
+
const commandLine = [command, ...args].join(" ");
|
|
19
|
+
debugLog?.("Fix command", { command: commandLine, cwd });
|
|
18
20
|
return await new Promise(resolve => {
|
|
19
21
|
const child = spawn(command, args, {
|
|
20
22
|
cwd,
|
|
@@ -23,9 +25,11 @@ export async function runInstallCommand(command, args, cwd) {
|
|
|
23
25
|
child.stdout.on("data", () => { });
|
|
24
26
|
child.stderr.on("data", () => { });
|
|
25
27
|
child.on("error", error => {
|
|
28
|
+
debugLog?.("Fix command finished", { command: commandLine, exitCode: null, error: error.message });
|
|
26
29
|
resolve({ status: null, error });
|
|
27
30
|
});
|
|
28
31
|
child.on("close", code => {
|
|
32
|
+
debugLog?.("Fix command finished", { command: commandLine, exitCode: code });
|
|
29
33
|
resolve({ status: code, error: null });
|
|
30
34
|
});
|
|
31
35
|
});
|
|
@@ -74,7 +78,7 @@ export async function applyFixesIfRequested(params) {
|
|
|
74
78
|
const target = directTargets[i];
|
|
75
79
|
const commandParts = buildFixCommandParts(params.plan.packageManager, [target]);
|
|
76
80
|
spinner.update(`Applying direct fix ${i + 1}/${total}: ${commandParts.join(" ")}`);
|
|
77
|
-
const run = await runInstallCommand(commandParts[0], commandParts.slice(1), params.projectPath);
|
|
81
|
+
const run = await runInstallCommand(commandParts[0], commandParts.slice(1), params.projectPath, params.debugLog);
|
|
78
82
|
if (run.error) {
|
|
79
83
|
spinner.fail("Failed to apply fixes");
|
|
80
84
|
throw new Error(`Failed to apply fixes: ${run.error.message}${fixHint}`);
|
package/dist/utils/network.js
CHANGED
|
@@ -45,6 +45,13 @@ export function serverAdvisoryRequestHint() {
|
|
|
45
45
|
...OFFLINE_FALLBACK_LINES,
|
|
46
46
|
];
|
|
47
47
|
}
|
|
48
|
+
export function offlineDbSyncHint(offlineDb) {
|
|
49
|
+
const lines = ["To build it, run: cve-lite advisories sync"];
|
|
50
|
+
if (offlineDb) {
|
|
51
|
+
lines.push(`Or to save it to the requested path: cve-lite advisories sync --output ${offlineDb}`);
|
|
52
|
+
}
|
|
53
|
+
return lines;
|
|
54
|
+
}
|
|
48
55
|
const SSL_ERROR_CODES = new Set([
|
|
49
56
|
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
50
57
|
"CERT_UNTRUSTED",
|
package/package.json
CHANGED