cve-lite-cli 1.18.2 → 1.19.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/advisory/local-advisory-source.js +1 -1
- package/dist/advisory/osv-advisory-source.js +13 -83
- package/dist/cli/args.js +0 -4
- package/dist/cli/help.js +0 -1
- package/dist/index.js +14 -66
- package/dist/osv/cache.js +7 -46
- package/dist/output/html-reporter.js +33 -32
- package/dist/output/sarif.js +9 -3
- package/dist/output/spinner.js +1 -1
- package/dist/parsers/pnpm-lock.js +0 -4
- package/dist/remediation/fix-commands.js +12 -36
- package/dist/remediation/npm-registry.js +1 -44
- package/dist/remediation/parent-upgrade.js +8 -14
- package/dist/scanner.js +16 -94
- package/dist/utils/fix-runner.js +2 -6
- package/dist/utils/network.js +0 -7
- package/dist/utils/update-check.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -213,9 +213,8 @@ 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
|
|
217
216
|
|
|
218
|
-
In-repo lockfile fixtures for Astro, Turborepo, Visual Studio Code
|
|
217
|
+
In-repo lockfile fixtures for Astro, Turborepo, and Visual Studio Code live under [`examples/`](examples/readme.md) — clone the repo and scan immediately without downloading full upstream checkouts.
|
|
219
218
|
|
|
220
219
|
These are not demos. They are documented scans against real codebases with real findings, recorded before and after applying fix commands.
|
|
221
220
|
|
|
@@ -1,57 +1,26 @@
|
|
|
1
1
|
import { extractErrorMessage } from "../utils/network.js";
|
|
2
2
|
export class OsvAdvisorySource {
|
|
3
3
|
baseUrl;
|
|
4
|
-
|
|
5
|
-
constructor(baseUrl = "https://api.osv.dev", debugLog) {
|
|
4
|
+
constructor(baseUrl = "https://api.osv.dev") {
|
|
6
5
|
this.baseUrl = baseUrl;
|
|
7
|
-
this.debugLog = debugLog;
|
|
8
6
|
}
|
|
9
|
-
async queryBatch(packages
|
|
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;
|
|
7
|
+
async queryBatch(packages) {
|
|
21
8
|
try {
|
|
22
|
-
|
|
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, {
|
|
9
|
+
const response = await fetch(`${this.baseUrl}/v1/querybatch`, {
|
|
39
10
|
method: "POST",
|
|
40
11
|
headers: {
|
|
41
12
|
"Content-Type": "application/json",
|
|
42
13
|
},
|
|
43
|
-
body: JSON.stringify(
|
|
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
|
+
}),
|
|
44
23
|
});
|
|
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
|
-
}
|
|
55
24
|
if (!response.ok) {
|
|
56
25
|
throw new Error(`OSV batch query failed: ${response.status} ${response.statusText}`);
|
|
57
26
|
}
|
|
@@ -63,58 +32,19 @@ export class OsvAdvisorySource {
|
|
|
63
32
|
}));
|
|
64
33
|
}
|
|
65
34
|
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
|
-
}
|
|
77
35
|
const message = extractErrorMessage(error);
|
|
78
36
|
throw new Error(`OSV batch query failed for ${this.baseUrl}: ${message}`);
|
|
79
37
|
}
|
|
80
38
|
}
|
|
81
39
|
async getVuln(id) {
|
|
82
|
-
const requestUrl = `${this.baseUrl}/v1/vulns/${encodeURIComponent(id)}`;
|
|
83
|
-
const startedAt = this.debugLog ? Date.now() : 0;
|
|
84
40
|
try {
|
|
85
|
-
|
|
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
|
-
}
|
|
41
|
+
const response = await fetch(`${this.baseUrl}/v1/vulns/${encodeURIComponent(id)}`);
|
|
102
42
|
if (!response.ok) {
|
|
103
43
|
throw new Error(`OSV vuln fetch failed for ${id}: ${response.status} ${response.statusText}`);
|
|
104
44
|
}
|
|
105
45
|
return response.json();
|
|
106
46
|
}
|
|
107
47
|
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
|
-
}
|
|
118
48
|
const message = extractErrorMessage(error);
|
|
119
49
|
throw new Error(`OSV vuln fetch failed for ${id} via ${this.baseUrl}: ${message}`);
|
|
120
50
|
}
|
package/dist/cli/args.js
CHANGED
package/dist/cli/help.js
CHANGED
|
@@ -42,7 +42,6 @@ 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",
|
|
46
45
|
" --verbose Show detailed output with fix plan, paths, and full table",
|
|
47
46
|
" --prod-only Exclude dev dependencies where available",
|
|
48
47
|
" --fail-on <severity> Exit non-zero at or above severity (default: critical)",
|
package/dist/index.js
CHANGED
|
@@ -11,11 +11,10 @@ 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";
|
|
15
14
|
import { buildSuggestedFixCommandPlan } from "./remediation/fix-commands.js";
|
|
16
15
|
import { scanProjectForPackageUsage } from "./usage/scanner.js";
|
|
17
16
|
import { getCliVersion } from "./utils/version-info.js";
|
|
18
|
-
import { blockedAdvisoryRequestHint, fetchErrorCaCertHint, isLikelyBlockedAdvisoryRequestError, isRateLimitError, isServerError, isSslCertificateError,
|
|
17
|
+
import { blockedAdvisoryRequestHint, fetchErrorCaCertHint, isLikelyBlockedAdvisoryRequestError, isRateLimitError, isServerError, isSslCertificateError, rateLimitAdvisoryRequestHint, serverAdvisoryRequestHint, sslCertificateErrorHint, } from "./utils/network.js";
|
|
19
18
|
import { formatAdvisoryDbFreshness } from "./utils/time.js";
|
|
20
19
|
import { pluralize } from "./utils/string.js";
|
|
21
20
|
import { formatAdvisorySourceLine, logInfo, logWarn, printCacheSummary, sortFindingsForOutput } from "./output/formatters.js";
|
|
@@ -29,6 +28,8 @@ import { readConfig, validateCaCertFile } from "./cli/config.js";
|
|
|
29
28
|
import { runConfigCommand } from "./cli/config-command.js";
|
|
30
29
|
import { readDirectDependencyNames } from "./utils/package-json.js";
|
|
31
30
|
import { applyFixesIfRequested, printFixModeSummary, } from "./utils/fix-runner.js";
|
|
31
|
+
import { hasRootLockfile, findNestedLockfiles } from "./parsers/multi-package.js";
|
|
32
|
+
import { handleMultiFolderScan } from "./scan/multi-folder-scan.js";
|
|
32
33
|
let parsedArgs = null;
|
|
33
34
|
try {
|
|
34
35
|
parsedArgs = parseArgs(process.argv.slice(2));
|
|
@@ -54,16 +55,8 @@ if (parsedArgs) {
|
|
|
54
55
|
const projectPath = path.resolve(projectArg || ".");
|
|
55
56
|
const batchSize = Number(options.batchSize || DEFAULT_BATCH_SIZE);
|
|
56
57
|
const searchDepth = Math.max(0, Number(options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
57
|
-
const debugSession = createDebugLogger(!!options.debug);
|
|
58
|
-
const debugLog = debugSession.log;
|
|
59
|
-
const scanStartedAt = Date.now();
|
|
60
58
|
async function main() {
|
|
61
59
|
printBanner(options);
|
|
62
|
-
debugSession.announcePath();
|
|
63
|
-
debugLog("CLI started", {
|
|
64
|
-
version: cliVersion,
|
|
65
|
-
args: process.argv.slice(2),
|
|
66
|
-
});
|
|
67
60
|
if (command === "config") {
|
|
68
61
|
const { configSubcommand } = parsedArgs;
|
|
69
62
|
if (!configSubcommand) {
|
|
@@ -97,10 +90,6 @@ if (parsedArgs) {
|
|
|
97
90
|
}
|
|
98
91
|
process.env.NODE_EXTRA_CA_CERTS = resolvedCaCert;
|
|
99
92
|
}
|
|
100
|
-
debugLog("Config loaded", {
|
|
101
|
-
caCert: resolvedCaCert ?? null,
|
|
102
|
-
nodeExtraCaCerts: process.env.NODE_EXTRA_CA_CERTS ?? null,
|
|
103
|
-
});
|
|
104
93
|
if (command === "advisories-sync") {
|
|
105
94
|
const spinner = createSpinner("Preparing advisory sync...", options);
|
|
106
95
|
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
@@ -133,6 +122,13 @@ if (parsedArgs) {
|
|
|
133
122
|
return;
|
|
134
123
|
}
|
|
135
124
|
validateOptions(options);
|
|
125
|
+
// Multi-folder mode: if no root lockfile and 2+ nested lockfiles exist,
|
|
126
|
+
// route to dedicated multi-folder handler instead of single-lockfile scan
|
|
127
|
+
const nestedLockfiles = findNestedLockfiles(projectPath, searchDepth);
|
|
128
|
+
if (!hasRootLockfile(projectPath) && nestedLockfiles.length >= 2) {
|
|
129
|
+
await handleMultiFolderScan({ projectRoot: projectPath, batchSize, options });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
136
132
|
let advisorySourceLine;
|
|
137
133
|
let advisoryDbFreshnessLine = null;
|
|
138
134
|
let advisoryDbWarning = null;
|
|
@@ -141,14 +137,8 @@ if (parsedArgs) {
|
|
|
141
137
|
osvUrl: options.osvUrl,
|
|
142
138
|
offline: options.offline,
|
|
143
139
|
offlineDb: options.offlineDb,
|
|
144
|
-
debugLog,
|
|
145
140
|
});
|
|
146
141
|
advisorySourceLine = advisorySource.sourceLabel;
|
|
147
|
-
debugLog("Advisory source", {
|
|
148
|
-
mode: advisorySource.offline ? "offline" : "online",
|
|
149
|
-
url: options.osvUrl ?? (advisorySource.offline ? null : "https://api.osv.dev"),
|
|
150
|
-
label: advisorySourceLine,
|
|
151
|
-
});
|
|
152
142
|
if (advisorySource.offline) {
|
|
153
143
|
const metadata = advisorySource.advisoryDbMetadata;
|
|
154
144
|
advisoryDbFreshnessLine = formatAdvisoryDbFreshness(metadata?.lastSyncAt ?? null);
|
|
@@ -162,8 +152,7 @@ if (parsedArgs) {
|
|
|
162
152
|
}
|
|
163
153
|
catch (error) {
|
|
164
154
|
if (options.offline || options.offlineDb) {
|
|
165
|
-
|
|
166
|
-
throw new Error(`Offline advisory database is not available: ${reason}\n${offlineDbSyncHint(options.offlineDb).join("\n")}`);
|
|
155
|
+
throw new Error(`Offline advisory database is not available: ${error instanceof Error ? error.message : String(error)}`);
|
|
167
156
|
}
|
|
168
157
|
throw error;
|
|
169
158
|
}
|
|
@@ -181,16 +170,6 @@ if (parsedArgs) {
|
|
|
181
170
|
}
|
|
182
171
|
let scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
183
172
|
let packages = scanInput.packages;
|
|
184
|
-
if (scanInput.filePath) {
|
|
185
|
-
debugLog("Lockfile selected", {
|
|
186
|
-
source: scanInput.source,
|
|
187
|
-
path: scanInput.filePath,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
debugLog("Packages parsed", {
|
|
191
|
-
count: packages.length,
|
|
192
|
-
source: scanInput.source,
|
|
193
|
-
});
|
|
194
173
|
logInfo(`Parsed ${packages.length} ${pluralize(packages.length, "package")} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
195
174
|
printCacheSummary(options.cacheDir, options);
|
|
196
175
|
if (scanInput.warnings.length > 0) {
|
|
@@ -199,17 +178,17 @@ if (parsedArgs) {
|
|
|
199
178
|
}
|
|
200
179
|
}
|
|
201
180
|
if (packages.length === 0) {
|
|
202
|
-
debugLog("Scan skipped", { reason: "no packages found", projectPath });
|
|
203
181
|
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
204
182
|
process.exit(0);
|
|
205
183
|
return;
|
|
206
184
|
}
|
|
185
|
+
if (!options.json)
|
|
186
|
+
console.log();
|
|
207
187
|
let scanState = await scanProject({
|
|
208
188
|
scanInput,
|
|
209
189
|
batchSize,
|
|
210
190
|
options,
|
|
211
191
|
projectPath,
|
|
212
|
-
debugLog,
|
|
213
192
|
});
|
|
214
193
|
const findingsBeforeFix = scanState.sorted.length;
|
|
215
194
|
let fixResult = null;
|
|
@@ -219,14 +198,12 @@ if (parsedArgs) {
|
|
|
219
198
|
projectPath,
|
|
220
199
|
totalFindings: scanState.sorted.length,
|
|
221
200
|
options,
|
|
222
|
-
debugLog,
|
|
223
201
|
});
|
|
224
202
|
if (fixResult.appliedFixCount > 0) {
|
|
225
203
|
console.log(`${chalk.cyan("⠋")} ${chalk.gray("Rescanning project...")}`);
|
|
226
204
|
scanInput = loadPackages(projectPath, !!options.prodOnly, searchDepth);
|
|
227
205
|
packages = scanInput.packages;
|
|
228
206
|
if (packages.length === 0) {
|
|
229
|
-
debugLog("Scan skipped", { reason: "no packages found after fix rescan", projectPath });
|
|
230
207
|
logWarn(buildNoPackagesMessage(projectPath), options);
|
|
231
208
|
process.exit(0);
|
|
232
209
|
return;
|
|
@@ -236,7 +213,6 @@ if (parsedArgs) {
|
|
|
236
213
|
batchSize,
|
|
237
214
|
options,
|
|
238
215
|
projectPath,
|
|
239
|
-
debugLog,
|
|
240
216
|
});
|
|
241
217
|
}
|
|
242
218
|
}
|
|
@@ -303,11 +279,6 @@ if (parsedArgs) {
|
|
|
303
279
|
});
|
|
304
280
|
console.log(`${chalk.gray("Report:")} ${chalk.cyan(reportPath)}`);
|
|
305
281
|
}
|
|
306
|
-
debugLog("Scan finished", {
|
|
307
|
-
totalDurationMs: Date.now() - scanStartedAt,
|
|
308
|
-
findings: scanState.sorted.length,
|
|
309
|
-
packages: packages.length,
|
|
310
|
-
});
|
|
311
282
|
const failLevel = normalizeSeverity(options.failOn);
|
|
312
283
|
const shouldFail = scanState.sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
313
284
|
process.exit(shouldFail ? 1 : 0);
|
|
@@ -316,9 +287,6 @@ if (parsedArgs) {
|
|
|
316
287
|
main().catch((error) => {
|
|
317
288
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
318
289
|
console.error(chalk.red(`Error: ${errorMessage}`));
|
|
319
|
-
if (options.debug && error instanceof Error && error.stack) {
|
|
320
|
-
debugLog("Unhandled error", { message: error.message, stack: error.stack });
|
|
321
|
-
}
|
|
322
290
|
if (isSslCertificateError(error)) {
|
|
323
291
|
const [hint, ...rest] = sslCertificateErrorHint();
|
|
324
292
|
console.error(chalk.yellow(hint));
|
|
@@ -354,44 +322,24 @@ async function scanProject(params) {
|
|
|
354
322
|
directDependencyNames,
|
|
355
323
|
scanSource: params.scanInput.source,
|
|
356
324
|
scanFilePath: params.scanInput.filePath,
|
|
357
|
-
}
|
|
325
|
+
});
|
|
358
326
|
if (params.options.usage) {
|
|
359
327
|
logInfo(`Scanning project source for usage hints...`, params.options);
|
|
360
|
-
const usageStartedAt = Date.now();
|
|
361
328
|
const pkgNames = new Set(findings.map(f => f.pkg.name));
|
|
362
329
|
const usageData = scanProjectForPackageUsage(params.projectPath, pkgNames);
|
|
363
|
-
let matchedPackages = 0;
|
|
364
330
|
for (const finding of findings) {
|
|
365
331
|
const files = usageData[finding.pkg.name];
|
|
366
332
|
if (files) {
|
|
367
|
-
if (files.length > 0) {
|
|
368
|
-
matchedPackages += 1;
|
|
369
|
-
}
|
|
370
333
|
finding.usage = {
|
|
371
334
|
imported: files.length > 0,
|
|
372
335
|
files,
|
|
373
336
|
};
|
|
374
337
|
}
|
|
375
338
|
}
|
|
376
|
-
if (params.options.debug) {
|
|
377
|
-
params.debugLog("Usage scan", {
|
|
378
|
-
durationMs: Date.now() - usageStartedAt,
|
|
379
|
-
packagesChecked: pkgNames.size,
|
|
380
|
-
matchedPackages,
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
339
|
}
|
|
384
340
|
let finalFindings = findings;
|
|
385
341
|
if (params.options.onlyUsed) {
|
|
386
|
-
const beforeCount = finalFindings.length;
|
|
387
342
|
finalFindings = finalFindings.filter(f => f.usage?.imported);
|
|
388
|
-
if (params.options.debug) {
|
|
389
|
-
params.debugLog("Findings filtered", {
|
|
390
|
-
reason: "only-used",
|
|
391
|
-
before: beforeCount,
|
|
392
|
-
after: finalFindings.length,
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
343
|
}
|
|
396
344
|
const offline = !!params.options.offline || !!params.options.offlineDb;
|
|
397
345
|
const sorted = sortFindingsForOutput(finalFindings);
|
package/dist/osv/cache.js
CHANGED
|
@@ -14,23 +14,15 @@ 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) {
|
|
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
|
-
});
|
|
26
20
|
return createEmptyCache();
|
|
27
21
|
}
|
|
28
22
|
try {
|
|
29
23
|
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
30
|
-
if (typeof parsed !== "object" || parsed === null)
|
|
31
|
-
debugLog?.("Cache load failed", { path: filePath, reason: "invalid root object" });
|
|
24
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
32
25
|
return createEmptyCache();
|
|
33
|
-
}
|
|
34
26
|
const entries = (parsed.entries && typeof parsed.entries === "object")
|
|
35
27
|
? parsed.entries
|
|
36
28
|
: {};
|
|
@@ -41,25 +33,11 @@ export function loadCache(cacheDirOverride, debugLog) {
|
|
|
41
33
|
for (const [key, vulnIds] of Object.entries(rawQuery ?? {})) {
|
|
42
34
|
queryEntries[key] = { vulnIds: Array.isArray(vulnIds) ? vulnIds : [], cachedAt: new Date(0).toISOString() };
|
|
43
35
|
}
|
|
44
|
-
|
|
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;
|
|
36
|
+
return { version: 3, createdAt: String(parsed.createdAt ?? new Date().toISOString()), entries, queryEntries };
|
|
52
37
|
}
|
|
53
38
|
// v1 or unknown: no queryEntries
|
|
54
39
|
if (parsed.version !== 3) {
|
|
55
|
-
|
|
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;
|
|
40
|
+
return { version: 3, createdAt: new Date().toISOString(), entries, queryEntries: {} };
|
|
63
41
|
}
|
|
64
42
|
const rawQuery = parsed.queryEntries;
|
|
65
43
|
const queryEntries = {};
|
|
@@ -68,36 +46,19 @@ export function loadCache(cacheDirOverride, debugLog) {
|
|
|
68
46
|
queryEntries[key] = value;
|
|
69
47
|
}
|
|
70
48
|
}
|
|
71
|
-
|
|
49
|
+
return {
|
|
72
50
|
version: 3,
|
|
73
51
|
createdAt: String(parsed.createdAt ?? new Date().toISOString()),
|
|
74
52
|
entries,
|
|
75
53
|
queryEntries,
|
|
76
54
|
};
|
|
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;
|
|
83
55
|
}
|
|
84
|
-
catch
|
|
85
|
-
debugLog?.("Cache load failed", {
|
|
86
|
-
path: filePath,
|
|
87
|
-
reason: error instanceof Error ? error.message : String(error),
|
|
88
|
-
});
|
|
56
|
+
catch {
|
|
89
57
|
return createEmptyCache();
|
|
90
58
|
}
|
|
91
59
|
}
|
|
92
|
-
export function saveCache(cache, cacheDirOverride
|
|
60
|
+
export function saveCache(cache, cacheDirOverride) {
|
|
93
61
|
const filePath = getCacheFilePath(cacheDirOverride);
|
|
94
62
|
cache.createdAt = new Date().toISOString();
|
|
95
63
|
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
|
-
}
|
|
103
64
|
}
|
|
@@ -20,33 +20,7 @@ export function buildReportData(params) {
|
|
|
20
20
|
warnings: params.warnings,
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
export
|
|
24
|
-
const projectName = path.basename(data.projectPath);
|
|
25
|
-
const scanDate = new Date(data.scannedAt).toLocaleString();
|
|
26
|
-
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
|
|
27
|
-
for (const f of data.findings) {
|
|
28
|
-
const sev = f.severity;
|
|
29
|
-
if (sev in counts)
|
|
30
|
-
counts[sev]++;
|
|
31
|
-
}
|
|
32
|
-
const totalCVEs = new Set(data.findings.flatMap(f => f.vulnerabilities.map(v => v.id))).size;
|
|
33
|
-
const noticesHtml = renderNotices(data.notes, data.warnings);
|
|
34
|
-
const fixPlanHtml = renderFixPlan(data.suggestedFixCommands);
|
|
35
|
-
const findingRowsHtml = data.findings.map(renderFindingRow).join("\n");
|
|
36
|
-
const dataJson = JSON.stringify(data)
|
|
37
|
-
.replace(/</g, "\\u003c")
|
|
38
|
-
.replace(/>/g, "\\u003e")
|
|
39
|
-
.replace(/&/g, "\\u0026")
|
|
40
|
-
.replace(/\u2028/g, "\\u2028")
|
|
41
|
-
.replace(/\u2029/g, "\\u2029");
|
|
42
|
-
return `<!DOCTYPE html>
|
|
43
|
-
<html lang="en">
|
|
44
|
-
<head>
|
|
45
|
-
<meta charset="UTF-8">
|
|
46
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
47
|
-
<title>CVE Lite — ${escapeHtml(projectName)}</title>
|
|
48
|
-
<style>
|
|
49
|
-
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
23
|
+
export const REPORT_STYLES = `*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
50
24
|
body{background:#0d1117;color:#e6edf3;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;font-size:14px;line-height:1.5}
|
|
51
25
|
.report-header{background:#161b22;border-bottom:1px solid #30363d;padding:14px 32px;display:flex;align-items:center;justify-content:space-between;gap:24px}
|
|
52
26
|
.header-left{display:flex;align-items:center;gap:20px}
|
|
@@ -169,7 +143,34 @@ button.header-link:hover{color:#58a6ff;border-color:#58a6ff}
|
|
|
169
143
|
.break-badge{font-size:10px;font-weight:700;background:#fb850022;color:#fb8500;border:1px solid #fb850066;border-radius:4px;padding:1px 5px}
|
|
170
144
|
.tier-ok{display:inline-flex;align-items:center;gap:4px;font-size:10px;padding:2px 8px;border-radius:4px;background:#3fb95022;color:#3fb950;border:1px solid #3fb95033;margin-bottom:6px}
|
|
171
145
|
.tier-warn{display:inline-flex;align-items:center;gap:4px;font-size:10px;padding:2px 8px;border-radius:4px;background:#e3b34122;color:#e3b341;border:1px solid #e3b34133;margin-bottom:6px}
|
|
172
|
-
.tier-err{display:inline-flex;align-items:center;gap:4px;font-size:10px;padding:2px 8px;border-radius:4px;background:#ff000011;color:#ff7b72;border:1px solid #ff7b7222;margin-bottom:6px}
|
|
146
|
+
.tier-err{display:inline-flex;align-items:center;gap:4px;font-size:10px;padding:2px 8px;border-radius:4px;background:#ff000011;color:#ff7b72;border:1px solid #ff7b7222;margin-bottom:6px}`;
|
|
147
|
+
export function renderHtmlReport(data) {
|
|
148
|
+
const projectName = path.basename(data.projectPath);
|
|
149
|
+
const scanDate = new Date(data.scannedAt).toLocaleString();
|
|
150
|
+
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
|
|
151
|
+
for (const f of data.findings) {
|
|
152
|
+
const sev = f.severity;
|
|
153
|
+
if (sev in counts)
|
|
154
|
+
counts[sev]++;
|
|
155
|
+
}
|
|
156
|
+
const totalCVEs = new Set(data.findings.flatMap(f => f.vulnerabilities.map(v => v.id))).size;
|
|
157
|
+
const noticesHtml = renderNotices(data.notes, data.warnings);
|
|
158
|
+
const fixPlanHtml = renderFixPlan(data.suggestedFixCommands);
|
|
159
|
+
const findingRowsHtml = data.findings.map(renderFindingRow).join("\n");
|
|
160
|
+
const dataJson = JSON.stringify(data)
|
|
161
|
+
.replace(/</g, "\\u003c")
|
|
162
|
+
.replace(/>/g, "\\u003e")
|
|
163
|
+
.replace(/&/g, "\\u0026")
|
|
164
|
+
.replace(/\u2028/g, "\\u2028")
|
|
165
|
+
.replace(/\u2029/g, "\\u2029");
|
|
166
|
+
return `<!DOCTYPE html>
|
|
167
|
+
<html lang="en">
|
|
168
|
+
<head>
|
|
169
|
+
<meta charset="UTF-8">
|
|
170
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
171
|
+
<title>CVE Lite — ${escapeHtml(projectName)}</title>
|
|
172
|
+
<style>
|
|
173
|
+
${REPORT_STYLES}
|
|
173
174
|
</style>
|
|
174
175
|
</head>
|
|
175
176
|
<body>
|
|
@@ -374,7 +375,7 @@ document.addEventListener('click', function(e) {
|
|
|
374
375
|
</body>
|
|
375
376
|
</html>`;
|
|
376
377
|
}
|
|
377
|
-
function escapeHtml(str) {
|
|
378
|
+
export function escapeHtml(str) {
|
|
378
379
|
return str
|
|
379
380
|
.replace(/&/g, "&")
|
|
380
381
|
.replace(/</g, "<")
|
|
@@ -387,7 +388,7 @@ function advisoryLink(id) {
|
|
|
387
388
|
}
|
|
388
389
|
return `<a class="cve-link" href="https://osv.dev/vulnerability/${escapeHtml(id)}" target="_blank">${escapeHtml(id)}</a>`;
|
|
389
390
|
}
|
|
390
|
-
function renderFindingRow(finding, idx) {
|
|
391
|
+
export function renderFindingRow(finding, idx) {
|
|
391
392
|
const cveLinks = finding.cves.length > 0
|
|
392
393
|
? finding.cves.map(advisoryLink).join(", ")
|
|
393
394
|
: finding.vulnerabilities.map(v => advisoryLink(v.id)).join(", ");
|
|
@@ -484,7 +485,7 @@ function renderNotices(notes, warnings) {
|
|
|
484
485
|
<div class="scan-notes-body"><ul>${items}</ul></div>
|
|
485
486
|
</div>`;
|
|
486
487
|
}
|
|
487
|
-
function renderFixPlan(plan) {
|
|
488
|
+
export function renderFixPlan(plan) {
|
|
488
489
|
if (!plan || plan.sections.length === 0)
|
|
489
490
|
return "";
|
|
490
491
|
const directCount = plan.targets.filter(t => t.kind === "direct").length;
|
|
@@ -556,7 +557,7 @@ export async function writeHtmlReport(params) {
|
|
|
556
557
|
}
|
|
557
558
|
return { reportPath: indexPath };
|
|
558
559
|
}
|
|
559
|
-
function openInBrowser(filePath) {
|
|
560
|
+
export function openInBrowser(filePath) {
|
|
560
561
|
if (!path.isAbsolute(filePath))
|
|
561
562
|
return;
|
|
562
563
|
const cmd = process.platform === "darwin"
|
package/dist/output/sarif.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
3
4
|
import { getRecommendedAction } from "./formatters.js";
|
|
4
5
|
import { getCliVersion } from "../utils/version-info.js";
|
|
5
6
|
import { severityToSarifLevel } from "../utils/severity.js";
|
|
@@ -18,12 +19,13 @@ export function deriveLockfileUri(scanInput) {
|
|
|
18
19
|
return path.basename(scanInput.filePath);
|
|
19
20
|
return LOCKFILE_NAMES[scanInput.source] ?? "lockfile";
|
|
20
21
|
}
|
|
21
|
-
export function buildSarifOutput(findings, lockfileUri, version,
|
|
22
|
+
export function buildSarifOutput(findings, lockfileUri, version, plan) {
|
|
22
23
|
const ruleMap = new Map();
|
|
23
24
|
const results = [];
|
|
24
25
|
for (const finding of findings) {
|
|
25
26
|
const level = severityToSarifLevel(finding.severity);
|
|
26
27
|
const action = getRecommendedAction(finding);
|
|
28
|
+
const runnableFixCommand = plan ? findSuggestedCommandForFinding(plan, finding) : null;
|
|
27
29
|
const location = {
|
|
28
30
|
physicalLocation: {
|
|
29
31
|
artifactLocation: { uri: lockfileUri, uriBaseId: "%SRCROOT%" },
|
|
@@ -45,14 +47,18 @@ export function buildSarifOutput(findings, lockfileUri, version, _plan) {
|
|
|
45
47
|
properties: { tags: ["security", "dependency"] },
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
const result = {
|
|
49
51
|
ruleId,
|
|
50
52
|
level,
|
|
51
53
|
message: {
|
|
52
54
|
text: `${finding.pkg.name}@${finding.pkg.version} is vulnerable (${finding.severity}). ${action}`,
|
|
53
55
|
},
|
|
54
56
|
locations: [location],
|
|
55
|
-
}
|
|
57
|
+
};
|
|
58
|
+
if (runnableFixCommand) {
|
|
59
|
+
result.fixes = [{ description: { text: runnableFixCommand }, artifactChanges: [] }];
|
|
60
|
+
}
|
|
61
|
+
results.push(result);
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
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);
|
|
5
5
|
if (!enabled) {
|
|
6
6
|
return {
|
|
7
7
|
update: () => { },
|
|
@@ -219,10 +219,6 @@ 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;
|
|
226
222
|
}
|
|
227
223
|
if (depRef && typeof depRef === "object") {
|
|
228
224
|
const version = depRef.version ?? depRef.specifier;
|
|
@@ -71,26 +71,13 @@ 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" || finding.relationship === "unknown") {
|
|
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
|
-
}
|
|
94
81
|
if (directTarget &&
|
|
95
82
|
isUpgradeTarget(finding.pkg.version, directTarget) &&
|
|
96
83
|
validatedFieldOk) {
|
|
@@ -145,15 +132,6 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
145
132
|
}
|
|
146
133
|
continue;
|
|
147
134
|
}
|
|
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
|
-
}
|
|
157
135
|
if (packageManager === "npm" &&
|
|
158
136
|
finding.relationship === "transitive" &&
|
|
159
137
|
finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
@@ -309,6 +287,14 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
309
287
|
totalFindingCount: findings.length,
|
|
310
288
|
};
|
|
311
289
|
plan.coveredFindingCount = findings.filter(f => findSuggestedCommandForFinding(plan, f) !== null).length;
|
|
290
|
+
if (options?.subfolder) {
|
|
291
|
+
const prefix = `cd ${options.subfolder} && `;
|
|
292
|
+
if (plan.command)
|
|
293
|
+
plan.command = prefix + plan.command;
|
|
294
|
+
for (const section of plan.sections) {
|
|
295
|
+
section.command = prefix + section.command;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
312
298
|
return plan;
|
|
313
299
|
}
|
|
314
300
|
function inferPackageManager(scanInput) {
|
|
@@ -359,14 +345,8 @@ export function findSuggestedCommandForFinding(plan, finding) {
|
|
|
359
345
|
(item.package === finding.recommendedNpmTransitiveRemediation.package || item.package === finding.pkg.name));
|
|
360
346
|
}
|
|
361
347
|
if (finding.recommendedParentUpgrade) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (item.targetVersion === finding.recommendedParentUpgrade.targetVersion)
|
|
365
|
-
return true;
|
|
366
|
-
// A command targeting a higher version also satisfies a lower-version recommendation
|
|
367
|
-
return (looksLikeVersion(item.targetVersion) &&
|
|
368
|
-
looksLikeVersion(finding.recommendedParentUpgrade.targetVersion) &&
|
|
369
|
-
compareVersions(item.targetVersion, finding.recommendedParentUpgrade.targetVersion) >= 0);
|
|
348
|
+
return (item.package === finding.recommendedParentUpgrade.package &&
|
|
349
|
+
item.targetVersion === finding.recommendedParentUpgrade.targetVersion);
|
|
370
350
|
}
|
|
371
351
|
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
372
352
|
return item.package === finding.pkg.name && item.targetVersion === directTarget;
|
|
@@ -427,11 +407,7 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
427
407
|
if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
|
|
428
408
|
merged.targetVersion = next.targetVersion;
|
|
429
409
|
merged.currentVersion = next.currentVersion ?? merged.currentVersion;
|
|
430
|
-
|
|
431
|
-
// in the context column. Only update the reason if next has strictly higher severity.
|
|
432
|
-
if (severityOrder[next.severity] > severityOrder[existing.severity]) {
|
|
433
|
-
merged.reason = next.reason;
|
|
434
|
-
}
|
|
410
|
+
merged.reason = next.reason;
|
|
435
411
|
merged.scannedVersions = next.scannedVersions ?? merged.scannedVersions ?? null;
|
|
436
412
|
merged.knownVulnerableVersions = next.knownVulnerableVersions ?? merged.knownVulnerableVersions ?? null;
|
|
437
413
|
}
|
|
@@ -1,16 +1,6 @@
|
|
|
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
|
-
}
|
|
14
4
|
export function clearPackumentCache() {
|
|
15
5
|
packumentCache.clear();
|
|
16
6
|
}
|
|
@@ -21,50 +11,17 @@ export async function fetchPackument(packageName) {
|
|
|
21
11
|
const url = `${DEFAULT_NPM_REGISTRY_URL}/${encodeURIComponent(packageName)
|
|
22
12
|
.replace(/%40/g, "@")
|
|
23
13
|
.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
|
-
}
|
|
29
14
|
try {
|
|
30
15
|
const response = await fetch(url);
|
|
31
16
|
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
|
-
}
|
|
41
17
|
packumentCache.set(packageName, null);
|
|
42
18
|
return null;
|
|
43
19
|
}
|
|
44
20
|
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
|
-
}
|
|
54
21
|
packumentCache.set(packageName, json);
|
|
55
22
|
return json;
|
|
56
23
|
}
|
|
57
|
-
catch
|
|
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
|
-
}
|
|
24
|
+
catch {
|
|
68
25
|
packumentCache.set(packageName, null);
|
|
69
26
|
return null;
|
|
70
27
|
}
|
|
@@ -28,17 +28,11 @@ 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;
|
|
37
31
|
return findUpgradeForImmediateIntermediate({
|
|
38
32
|
directParentName,
|
|
39
33
|
directParentVersion: directParent.version,
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
immediateParentName,
|
|
35
|
+
immediateParentInstalledVersion: findPackageVersion(packages, immediateParentName, viaPath.slice(0, -1)) ?? "",
|
|
42
36
|
vulnerableName,
|
|
43
37
|
viaPath,
|
|
44
38
|
});
|
|
@@ -129,7 +123,7 @@ async function findUpgradeForExactDirectChild(args) {
|
|
|
129
123
|
return null;
|
|
130
124
|
}
|
|
131
125
|
async function findUpgradeForImmediateIntermediate(args) {
|
|
132
|
-
if (!args.
|
|
126
|
+
if (!args.immediateParentInstalledVersion || !looksLikeVersion(args.immediateParentInstalledVersion)) {
|
|
133
127
|
return null;
|
|
134
128
|
}
|
|
135
129
|
const packument = await fetchPackument(args.directParentName);
|
|
@@ -140,12 +134,12 @@ async function findUpgradeForImmediateIntermediate(args) {
|
|
|
140
134
|
.sort(compareVersions);
|
|
141
135
|
for (const version of versions) {
|
|
142
136
|
const manifest = packument?.versions?.[version];
|
|
143
|
-
const depRange = manifest?.dependencies?.[args.
|
|
144
|
-
manifest?.optionalDependencies?.[args.
|
|
137
|
+
const depRange = manifest?.dependencies?.[args.immediateParentName] ??
|
|
138
|
+
manifest?.optionalDependencies?.[args.immediateParentName];
|
|
145
139
|
if (!depRange)
|
|
146
140
|
continue;
|
|
147
|
-
const
|
|
148
|
-
if (!
|
|
141
|
+
const stillAllowsImmediateParentInstalled = versionSatisfiesRange(args.immediateParentInstalledVersion, depRange);
|
|
142
|
+
if (!stillAllowsImmediateParentInstalled) {
|
|
149
143
|
return {
|
|
150
144
|
package: args.directParentName,
|
|
151
145
|
currentVersion: args.directParentVersion,
|
|
@@ -153,7 +147,7 @@ async function findUpgradeForImmediateIntermediate(args) {
|
|
|
153
147
|
viaPath: args.viaPath,
|
|
154
148
|
vulnerablePackage: args.vulnerableName,
|
|
155
149
|
confidence: "best-effort",
|
|
156
|
-
reason: `${args.directParentName}@${version} no longer allows ${args.
|
|
150
|
+
reason: `${args.directParentName}@${version} no longer allows ${args.immediateParentName}@${args.immediateParentInstalledVersion} in the current path`,
|
|
157
151
|
};
|
|
158
152
|
}
|
|
159
153
|
}
|
package/dist/scanner.js
CHANGED
|
@@ -8,8 +8,7 @@ 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 {
|
|
12
|
-
import { countBySeverity } from "./utils/severity.js";
|
|
11
|
+
import { resolveLowestKnownNonVulnerableVersion, resolvePublishedFixVersion } from "./remediation/npm-registry.js";
|
|
13
12
|
import { resolveNpmTransitiveRemediation, resolveTransitiveRemediationViaRegistry } from "./remediation/npm-transitive-resolution.js";
|
|
14
13
|
import { loadNpmLockGraph } from "./parsers/npm-lock-graph.js";
|
|
15
14
|
import { buildPnpmWorkspaceMap } from "./parsers/pnpm-lock.js";
|
|
@@ -31,7 +30,7 @@ export function createAdvisorySource(options) {
|
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
32
|
return {
|
|
34
|
-
advisorySource: new OsvAdvisorySource(options?.osvUrl
|
|
33
|
+
advisorySource: new OsvAdvisorySource(options?.osvUrl),
|
|
35
34
|
offline: false,
|
|
36
35
|
sourceLabel: options?.osvUrl
|
|
37
36
|
? `custom OSV endpoint (${options.osvUrl})`
|
|
@@ -44,13 +43,11 @@ export function createAdvisorySource(options) {
|
|
|
44
43
|
function getPackageCacheKey(pkg) {
|
|
45
44
|
return `${pkg.ecosystem}:${pkg.name}@${pkg.version}`;
|
|
46
45
|
}
|
|
47
|
-
export async function scanPackages(packages, batchSize, options, context
|
|
48
|
-
const log = debugLog ?? (() => { });
|
|
46
|
+
export async function scanPackages(packages, batchSize, options, context) {
|
|
49
47
|
const sourceContext = createAdvisorySource({
|
|
50
48
|
osvUrl: options.osvUrl,
|
|
51
49
|
offline: options.offline,
|
|
52
50
|
offlineDb: options.offlineDb,
|
|
53
|
-
debugLog: log,
|
|
54
51
|
});
|
|
55
52
|
const offline = sourceContext.offline;
|
|
56
53
|
const cacheDirOverride = options.cacheDir;
|
|
@@ -58,43 +55,28 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
58
55
|
? "Scanning dependencies against the local advisory database..."
|
|
59
56
|
: "Scanning dependencies against OSV...", options);
|
|
60
57
|
const advisorySource = sourceContext.advisorySource;
|
|
61
|
-
|
|
62
|
-
configureNpmRegistryDebug(log);
|
|
63
|
-
}
|
|
64
|
-
const cache = loadCache(cacheDirOverride, options.debug ? log : undefined);
|
|
58
|
+
const cache = loadCache(cacheDirOverride);
|
|
65
59
|
try {
|
|
66
60
|
const results = [];
|
|
67
61
|
const uncachedPackages = [];
|
|
68
62
|
if (!offline) {
|
|
69
63
|
const nowMs = Date.now();
|
|
70
|
-
let hits = 0;
|
|
71
|
-
let misses = 0;
|
|
72
64
|
for (const pkg of packages) {
|
|
73
65
|
const cacheKey = getPackageCacheKey(pkg);
|
|
74
66
|
if (!options.noCache) {
|
|
75
67
|
const cached = cache.queryEntries[cacheKey];
|
|
76
68
|
if (cached && !isEntryStale(cached, nowMs)) {
|
|
77
|
-
hits += 1;
|
|
78
69
|
if (cached.vulnIds.length > 0) {
|
|
79
70
|
results.push({ pkg, vulnIds: cached.vulnIds });
|
|
80
71
|
}
|
|
81
72
|
continue;
|
|
82
73
|
}
|
|
83
74
|
}
|
|
84
|
-
misses += 1;
|
|
85
75
|
uncachedPackages.push(pkg);
|
|
86
76
|
}
|
|
87
77
|
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 });
|
|
90
78
|
spinner.update(`Scanning OSV in ${chunks.length} parallel ${pluralize(chunks.length, "batch", "batches")}...`);
|
|
91
|
-
const
|
|
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
|
-
});
|
|
79
|
+
const allAdvisoryResults = await runWithConcurrency(chunks, 5, c => advisorySource.queryBatch(c));
|
|
98
80
|
for (let i = 0; i < chunks.length; i++) {
|
|
99
81
|
const chunkItems = chunks[i];
|
|
100
82
|
const rows = allAdvisoryResults[i] ?? [];
|
|
@@ -108,13 +90,6 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
108
90
|
}
|
|
109
91
|
}
|
|
110
92
|
}
|
|
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
|
-
}
|
|
118
93
|
if (chunks.length === 0) {
|
|
119
94
|
spinner.succeed("Loaded package matches from cache");
|
|
120
95
|
}
|
|
@@ -123,7 +98,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
123
98
|
}
|
|
124
99
|
}
|
|
125
100
|
else {
|
|
126
|
-
const advisoryResult = await advisorySource.queryBatch(packages
|
|
101
|
+
const advisoryResult = await advisorySource.queryBatch(packages);
|
|
127
102
|
const rows = advisoryResult ?? [];
|
|
128
103
|
for (let i = 0; i < packages.length; i++) {
|
|
129
104
|
const pkg = packages[i];
|
|
@@ -190,7 +165,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
190
165
|
}
|
|
191
166
|
}
|
|
192
167
|
if (!offline && idSet.size > 0) {
|
|
193
|
-
saveCache(cache, cacheDirOverride
|
|
168
|
+
saveCache(cache, cacheDirOverride);
|
|
194
169
|
}
|
|
195
170
|
const findings = results.map(result => {
|
|
196
171
|
const vulnerabilities = result.vulnIds
|
|
@@ -218,59 +193,35 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
218
193
|
};
|
|
219
194
|
});
|
|
220
195
|
const npmTransitiveGraph = context?.scanSource === "package-lock" && context.scanFilePath
|
|
221
|
-
? createNpmTransitiveGraphFromLockfile(context.scanFilePath
|
|
196
|
+
? createNpmTransitiveGraphFromLockfile(context.scanFilePath)
|
|
222
197
|
: null;
|
|
223
198
|
const npmWorkspaceMap = (() => {
|
|
224
199
|
try {
|
|
225
200
|
return context?.scanSource === "package-lock" && context.scanFilePath
|
|
226
201
|
? buildNpmWorkspaceMap(context.scanFilePath) : null;
|
|
227
202
|
}
|
|
228
|
-
catch
|
|
229
|
-
log("Workspace map", {
|
|
230
|
-
type: "npm",
|
|
231
|
-
status: "failed",
|
|
232
|
-
error: error instanceof Error ? error.message : String(error),
|
|
233
|
-
});
|
|
203
|
+
catch {
|
|
234
204
|
return null;
|
|
235
205
|
}
|
|
236
206
|
})();
|
|
237
|
-
if (npmWorkspaceMap) {
|
|
238
|
-
log("Workspace map", { type: "npm", workspaces: npmWorkspaceMap.size });
|
|
239
|
-
}
|
|
240
207
|
const pnpmWorkspaceMap = (() => {
|
|
241
208
|
try {
|
|
242
209
|
return context?.scanSource === "pnpm-lock" && context.scanFilePath
|
|
243
210
|
? buildPnpmWorkspaceMap(context.scanFilePath) : null;
|
|
244
211
|
}
|
|
245
|
-
catch
|
|
246
|
-
log("Workspace map", {
|
|
247
|
-
type: "pnpm",
|
|
248
|
-
status: "failed",
|
|
249
|
-
error: error instanceof Error ? error.message : String(error),
|
|
250
|
-
});
|
|
212
|
+
catch {
|
|
251
213
|
return null;
|
|
252
214
|
}
|
|
253
215
|
})();
|
|
254
|
-
if (pnpmWorkspaceMap) {
|
|
255
|
-
log("Workspace map", { type: "pnpm", workspaces: pnpmWorkspaceMap.size });
|
|
256
|
-
}
|
|
257
216
|
const bunWorkspaceMap = (() => {
|
|
258
217
|
try {
|
|
259
218
|
return context?.scanSource === "bun-lock" && context.scanFilePath
|
|
260
219
|
? buildBunWorkspaceMap(context.scanFilePath) : null;
|
|
261
220
|
}
|
|
262
|
-
catch
|
|
263
|
-
log("Workspace map", {
|
|
264
|
-
type: "bun",
|
|
265
|
-
status: "failed",
|
|
266
|
-
error: error instanceof Error ? error.message : String(error),
|
|
267
|
-
});
|
|
221
|
+
catch {
|
|
268
222
|
return null;
|
|
269
223
|
}
|
|
270
224
|
})();
|
|
271
|
-
if (bunWorkspaceMap) {
|
|
272
|
-
log("Workspace map", { type: "bun", workspaces: bunWorkspaceMap.size });
|
|
273
|
-
}
|
|
274
225
|
const lockfileWorkspaceMap = pnpmWorkspaceMap ?? bunWorkspaceMap ?? null;
|
|
275
226
|
const npmRemediationCache = new Map();
|
|
276
227
|
const parentUpgradeCache = new Map();
|
|
@@ -288,7 +239,7 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
288
239
|
if (!offline) {
|
|
289
240
|
await validateDirectFixTargets(findings, (finding) => {
|
|
290
241
|
updateAnalysisProgress("validating fix target for", `${finding.pkg.name}@${finding.pkg.version}`);
|
|
291
|
-
}
|
|
242
|
+
});
|
|
292
243
|
}
|
|
293
244
|
for (const finding of findings) {
|
|
294
245
|
if (finding.relationship !== "transitive")
|
|
@@ -375,19 +326,8 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
375
326
|
}
|
|
376
327
|
}
|
|
377
328
|
else if (!offline) {
|
|
378
|
-
await validateDirectFixTargets(findings
|
|
329
|
+
await validateDirectFixTargets(findings);
|
|
379
330
|
}
|
|
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
|
-
});
|
|
391
331
|
return findings;
|
|
392
332
|
}
|
|
393
333
|
catch (error) {
|
|
@@ -398,10 +338,9 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
398
338
|
sourceContext.cleanup();
|
|
399
339
|
}
|
|
400
340
|
}
|
|
401
|
-
function createNpmTransitiveGraphFromLockfile(filePath
|
|
341
|
+
function createNpmTransitiveGraphFromLockfile(filePath) {
|
|
402
342
|
try {
|
|
403
343
|
const lockGraph = loadNpmLockGraph(filePath, { includePaths: false });
|
|
404
|
-
log("npm transitive graph", { status: "built", nodes: packageCount });
|
|
405
344
|
return {
|
|
406
345
|
nodeIdsFor(name, version) {
|
|
407
346
|
return lockGraph.nodeIdsFor(name, version);
|
|
@@ -420,26 +359,14 @@ function createNpmTransitiveGraphFromLockfile(filePath, log, packageCount) {
|
|
|
420
359
|
},
|
|
421
360
|
};
|
|
422
361
|
}
|
|
423
|
-
catch
|
|
424
|
-
log("npm transitive graph", {
|
|
425
|
-
status: "failed",
|
|
426
|
-
error: error instanceof Error ? error.message : String(error),
|
|
427
|
-
});
|
|
362
|
+
catch {
|
|
428
363
|
return null;
|
|
429
364
|
}
|
|
430
365
|
}
|
|
431
|
-
async function validateDirectFixTargets(findings, onFinding
|
|
366
|
+
async function validateDirectFixTargets(findings, onFinding) {
|
|
432
367
|
const directCandidates = findings.filter(finding => finding.vulnerabilities.length > 0);
|
|
433
368
|
for (const finding of directCandidates) {
|
|
434
369
|
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
|
-
};
|
|
443
370
|
const lowestKnownResolution = await resolveLowestKnownNonVulnerableVersion(finding.pkg.name, finding.pkg.version, finding.vulnerabilities);
|
|
444
371
|
const fixedVersionHint = finding.firstFixedVersion;
|
|
445
372
|
if (lowestKnownResolution.resolvedVersion) {
|
|
@@ -448,19 +375,16 @@ async function validateDirectFixTargets(findings, onFinding, debugLog) {
|
|
|
448
375
|
finding.validatedTargetKnownVulnerableVersions = lowestKnownResolution.candidatesKnownVulnerable;
|
|
449
376
|
if (!fixedVersionHint || fixedVersionHint === lowestKnownResolution.resolvedVersion) {
|
|
450
377
|
finding.fixVersionValidationNote = null;
|
|
451
|
-
logFixValidation();
|
|
452
378
|
continue;
|
|
453
379
|
}
|
|
454
380
|
const hintResolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
|
|
455
381
|
if (hintResolution.resolvedVersion === lowestKnownResolution.resolvedVersion &&
|
|
456
382
|
hintResolution.note) {
|
|
457
383
|
finding.fixVersionValidationNote = hintResolution.note;
|
|
458
|
-
logFixValidation();
|
|
459
384
|
continue;
|
|
460
385
|
}
|
|
461
386
|
finding.fixVersionValidationNote =
|
|
462
387
|
`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();
|
|
464
388
|
continue;
|
|
465
389
|
}
|
|
466
390
|
if (!fixedVersionHint) {
|
|
@@ -468,7 +392,6 @@ async function validateDirectFixTargets(findings, onFinding, debugLog) {
|
|
|
468
392
|
finding.fixVersionValidationNote = lowestKnownResolution.note;
|
|
469
393
|
finding.validatedTargetScannedVersions = null;
|
|
470
394
|
finding.validatedTargetKnownVulnerableVersions = null;
|
|
471
|
-
logFixValidation();
|
|
472
395
|
continue;
|
|
473
396
|
}
|
|
474
397
|
const resolution = await resolvePublishedFixVersion(finding.pkg.name, fixedVersionHint);
|
|
@@ -476,7 +399,6 @@ async function validateDirectFixTargets(findings, onFinding, debugLog) {
|
|
|
476
399
|
finding.fixVersionValidationNote = resolution.note ?? lowestKnownResolution.note;
|
|
477
400
|
finding.validatedTargetScannedVersions = null;
|
|
478
401
|
finding.validatedTargetKnownVulnerableVersions = null;
|
|
479
|
-
logFixValidation();
|
|
480
402
|
}
|
|
481
403
|
}
|
|
482
404
|
function isAdvisoryDbStale(metadata) {
|
package/dist/utils/fix-runner.js
CHANGED
|
@@ -14,9 +14,7 @@ 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
|
|
18
|
-
const commandLine = [command, ...args].join(" ");
|
|
19
|
-
debugLog?.("Fix command", { command: commandLine, cwd });
|
|
17
|
+
export async function runInstallCommand(command, args, cwd) {
|
|
20
18
|
return await new Promise(resolve => {
|
|
21
19
|
const child = spawn(command, args, {
|
|
22
20
|
cwd,
|
|
@@ -25,11 +23,9 @@ export async function runInstallCommand(command, args, cwd, debugLog) {
|
|
|
25
23
|
child.stdout.on("data", () => { });
|
|
26
24
|
child.stderr.on("data", () => { });
|
|
27
25
|
child.on("error", error => {
|
|
28
|
-
debugLog?.("Fix command finished", { command: commandLine, exitCode: null, error: error.message });
|
|
29
26
|
resolve({ status: null, error });
|
|
30
27
|
});
|
|
31
28
|
child.on("close", code => {
|
|
32
|
-
debugLog?.("Fix command finished", { command: commandLine, exitCode: code });
|
|
33
29
|
resolve({ status: code, error: null });
|
|
34
30
|
});
|
|
35
31
|
});
|
|
@@ -78,7 +74,7 @@ export async function applyFixesIfRequested(params) {
|
|
|
78
74
|
const target = directTargets[i];
|
|
79
75
|
const commandParts = buildFixCommandParts(params.plan.packageManager, [target]);
|
|
80
76
|
spinner.update(`Applying direct fix ${i + 1}/${total}: ${commandParts.join(" ")}`);
|
|
81
|
-
const run = await runInstallCommand(commandParts[0], commandParts.slice(1), params.projectPath
|
|
77
|
+
const run = await runInstallCommand(commandParts[0], commandParts.slice(1), params.projectPath);
|
|
82
78
|
if (run.error) {
|
|
83
79
|
spinner.fail("Failed to apply fixes");
|
|
84
80
|
throw new Error(`Failed to apply fixes: ${run.error.message}${fixHint}`);
|
package/dist/utils/network.js
CHANGED
|
@@ -45,13 +45,6 @@ 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
|
-
}
|
|
55
48
|
const SSL_ERROR_CODES = new Set([
|
|
56
49
|
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
57
50
|
"CERT_UNTRUSTED",
|
|
@@ -8,7 +8,8 @@ const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
|
8
8
|
const BOX_INNER_WIDTH = 50;
|
|
9
9
|
export function isNewer(latest, current) {
|
|
10
10
|
const parse = (v) => {
|
|
11
|
-
const
|
|
11
|
+
const core = v.replace(/^v/, "").split("-")[0];
|
|
12
|
+
const parts = core.split(".").map(Number);
|
|
12
13
|
return parts.length === 3 && parts.every(n => !isNaN(n)) ? parts : [];
|
|
13
14
|
};
|
|
14
15
|
const l = parse(latest);
|
package/package.json
CHANGED