cve-lite-cli 1.19.2 → 1.20.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/cli/args.js +18 -0
- package/dist/cli/help.js +2 -0
- package/dist/cli/validate.js +9 -0
- package/dist/constants.js +4 -0
- package/dist/index.js +33 -3
- package/dist/output/formatters.js +8 -1
- package/dist/output/html-reporter.js +6 -3
- package/dist/output/printers.js +41 -14
- package/dist/parsers/bun-lock.js +75 -5
- package/dist/parsers/index.js +4 -4
- package/dist/parsers/package-lock.js +2 -1
- package/dist/parsers/yarn-lock.js +174 -15
- package/dist/remediation/npm-transitive-resolution.js +43 -4
- package/dist/scanner.js +7 -0
- package/dist/utils/advisory.js +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -220,9 +220,10 @@ CVE Lite CLI has been evaluated against real open-source projects to verify that
|
|
|
220
220
|
- [LangChain.js](https://owasp.org/cve-lite-cli/docs/case-studies/langchainjs) — verified baseline scan of a pnpm LLM-framework monorepo (2,174 packages, 13 findings at revision `1503c9b`) with a lean-graph profile, three high-severity findings with validated fix targets, and a malicious-package advisory on OpenSearch integration paths
|
|
221
221
|
- [OpenAI Agents SDK (JavaScript)](https://owasp.org/cve-lite-cli/docs/case-studies/openai-agents-js) — verified baseline scan of a pnpm AI-agent monorepo (1,683 packages, 31 findings at revision `f76fc19`) with 0 direct findings, MCP/Daytona parent clusters, and one generated `verdaccio` parent-upgrade command
|
|
222
222
|
- [n8n](https://owasp.org/cve-lite-cli/docs/case-studies/n8n) — verified baseline scan of a workflow automation pnpm monorepo (3,746 packages, 32 findings at revision `e2e0394`) with one direct `turbo` fix, four command groups, and email/editor transitive clusters
|
|
223
|
+
- [CamoFox Browser](https://owasp.org/cve-lite-cli/docs/case-studies/camofox-browser) — verified baseline scan of an AI agent browser automation npm graph (435 packages, 2 findings at revision `ce3a3b0`) with dual `qs` fix strategies — within-range `npm update qs` and parent `npm install express@4.22.2`
|
|
223
224
|
- [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
|
|
224
225
|
|
|
225
|
-
In-repo lockfile fixtures for Astro, Turborepo, Visual Studio Code, Gatsby, Vercel AI SDK, Mastra, Lit, LangChain.js, OpenAI Agents JS, n8n, and Storybook live under [`examples/`](examples/readme.md) — clone the repo and scan immediately without downloading full upstream checkouts.
|
|
226
|
+
In-repo lockfile fixtures for Astro, Turborepo, Visual Studio Code, Gatsby, Vercel AI SDK, Mastra, Lit, LangChain.js, OpenAI Agents JS, n8n, CamoFox Browser, and Storybook live under [`examples/`](examples/readme.md) — clone the repo and scan immediately without downloading full upstream checkouts.
|
|
226
227
|
|
|
227
228
|
These are not demos. They are documented scans against real codebases with real findings, recorded before and after applying fix commands.
|
|
228
229
|
|
package/dist/cli/args.js
CHANGED
|
@@ -109,6 +109,24 @@ export function parseArgs(argv) {
|
|
|
109
109
|
options.fix = true;
|
|
110
110
|
continue;
|
|
111
111
|
}
|
|
112
|
+
if (arg === "--create-pr") {
|
|
113
|
+
options.createPr = true;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (arg === "--base") {
|
|
117
|
+
const val = argv[++i];
|
|
118
|
+
if (!val)
|
|
119
|
+
throw new Error("--base requires a branch name");
|
|
120
|
+
options.prBase = val;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (arg.startsWith("--base=")) {
|
|
124
|
+
const val = arg.slice("--base=".length);
|
|
125
|
+
if (!val)
|
|
126
|
+
throw new Error("--base requires a branch name");
|
|
127
|
+
options.prBase = val;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
112
130
|
if (arg === "--prod-only") {
|
|
113
131
|
options.prodOnly = true;
|
|
114
132
|
continue;
|
package/dist/cli/help.js
CHANGED
|
@@ -34,6 +34,8 @@ export function printHelp() {
|
|
|
34
34
|
" --cdx Write CycloneDX 1.4 SBOM to a timestamped .cdx.json file",
|
|
35
35
|
" --no-open Don't auto-open the report in the browser",
|
|
36
36
|
" --fix Apply validated direct dependency fixes and rescan",
|
|
37
|
+
" --create-pr After --fix, commit changes and open a GitHub pull request (requires gh)",
|
|
38
|
+
" --base <branch> Base branch for --create-pr (default: main)",
|
|
37
39
|
" --osv-url <url> Use a custom OSV-compatible advisory endpoint",
|
|
38
40
|
" --ca-cert <path> Path to a CA certificate file for corporate SSL proxies",
|
|
39
41
|
" --debug Write verbose runtime/network diagnostics to a timestamped log file",
|
package/dist/cli/validate.js
CHANGED
|
@@ -17,6 +17,15 @@ export function validateOptions(options) {
|
|
|
17
17
|
if (options.fix && options.json) {
|
|
18
18
|
throw new Error("--fix cannot be used with --json");
|
|
19
19
|
}
|
|
20
|
+
if (options.createPr && !options.fix) {
|
|
21
|
+
throw new Error("--create-pr requires --fix");
|
|
22
|
+
}
|
|
23
|
+
if (options.createPr && options.json) {
|
|
24
|
+
throw new Error("--create-pr cannot be used with --json");
|
|
25
|
+
}
|
|
26
|
+
if (options.prBase && !options.createPr) {
|
|
27
|
+
throw new Error("--base can only be used with --create-pr");
|
|
28
|
+
}
|
|
20
29
|
if (options.report && options.json) {
|
|
21
30
|
throw new Error("--report cannot be used with --json");
|
|
22
31
|
}
|
package/dist/constants.js
CHANGED
|
@@ -8,6 +8,10 @@ export const severityOrder = {
|
|
|
8
8
|
};
|
|
9
9
|
export const DEFAULT_BATCH_SIZE = 100;
|
|
10
10
|
export const DEFAULT_SEARCH_DEPTH = 4;
|
|
11
|
+
export const NPM_PUBLIC_REGISTRY = "https://registry.npmjs.org/";
|
|
12
|
+
export const MAL_PRIVATE_REGISTRY_MESSAGE = "This package has a MAL- advisory but resolved from a private registry - unverifiable whether this advisory applies to your artifact. Inspect the source manually.";
|
|
13
|
+
export const MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE = "MAL- advisory could not be confirmed for this artifact.";
|
|
14
|
+
export const MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE = "verify artifact source manually";
|
|
11
15
|
export const EXCLUDED_DIRS = new Set([
|
|
12
16
|
".git",
|
|
13
17
|
"node_modules",
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ import { readDirectDependencyNames } from "./utils/package-json.js";
|
|
|
31
31
|
import { applyFixesIfRequested, printFixModeSummary, } from "./utils/fix-runner.js";
|
|
32
32
|
import { hasRootLockfile, findNestedLockfiles } from "./parsers/multi-package.js";
|
|
33
33
|
import { handleMultiFolderScan } from "./scan/multi-folder-scan.js";
|
|
34
|
+
import { createPullRequestForFixes, } from "./utils/create-pr.js";
|
|
34
35
|
let parsedArgs = null;
|
|
35
36
|
try {
|
|
36
37
|
parsedArgs = parseArgs(process.argv.slice(2));
|
|
@@ -142,7 +143,7 @@ if (parsedArgs) {
|
|
|
142
143
|
await handleMultiFolderScan({ projectRoot: projectPath, batchSize, options });
|
|
143
144
|
return;
|
|
144
145
|
}
|
|
145
|
-
let advisorySourceLine;
|
|
146
|
+
let advisorySourceLine = "";
|
|
146
147
|
let advisoryDbFreshnessLine = null;
|
|
147
148
|
let advisoryDbWarning = null;
|
|
148
149
|
try {
|
|
@@ -180,7 +181,9 @@ if (parsedArgs) {
|
|
|
180
181
|
if (options.offline || options.offlineDb) {
|
|
181
182
|
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
182
183
|
}
|
|
183
|
-
|
|
184
|
+
if (advisorySourceLine) {
|
|
185
|
+
console.log(`${chalk.gray("Advisory source:")} ${formatAdvisorySourceLine(advisorySourceLine)}`);
|
|
186
|
+
}
|
|
184
187
|
if (advisoryDbFreshnessLine) {
|
|
185
188
|
console.log(`${chalk.gray("Advisory DB freshness:")} ${advisoryDbFreshnessLine}`);
|
|
186
189
|
}
|
|
@@ -222,7 +225,8 @@ if (parsedArgs) {
|
|
|
222
225
|
projectPath,
|
|
223
226
|
debugLog,
|
|
224
227
|
});
|
|
225
|
-
const
|
|
228
|
+
const findingsBeforeFixList = scanState.sorted;
|
|
229
|
+
const findingsBeforeFix = findingsBeforeFixList.length;
|
|
226
230
|
let fixResult = null;
|
|
227
231
|
if (options.fix) {
|
|
228
232
|
fixResult = await applyFixesIfRequested({
|
|
@@ -258,6 +262,32 @@ if (parsedArgs) {
|
|
|
258
262
|
findingsAfterFix: scanState.sorted.length,
|
|
259
263
|
remainingBySeverity: countBySeverity(scanState.sorted),
|
|
260
264
|
});
|
|
265
|
+
if (options.createPr && fixResult) {
|
|
266
|
+
if (fixResult.appliedFixCount === 0) {
|
|
267
|
+
logWarn("Skipping pull request creation: no direct fixes were applied.", options);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
console.log("");
|
|
271
|
+
console.log(chalk.bold.cyan("Creating pull request (--create-pr)"));
|
|
272
|
+
const prResult = await createPullRequestForFixes({
|
|
273
|
+
projectPath,
|
|
274
|
+
baseBranch: options.prBase ?? "main",
|
|
275
|
+
fixResult,
|
|
276
|
+
findingsBeforeFix: findingsBeforeFixList,
|
|
277
|
+
findingsAfterFix: scanState.sorted,
|
|
278
|
+
});
|
|
279
|
+
if (prResult.skipped) {
|
|
280
|
+
logWarn(prResult.skipReason ?? "Pull request was not created.", options);
|
|
281
|
+
}
|
|
282
|
+
else if (prResult.prUrl) {
|
|
283
|
+
console.log(`${chalk.gray("Pull request:")} ${chalk.cyan(prResult.prUrl)}`);
|
|
284
|
+
console.log(`${chalk.gray("Branch:")} ${chalk.cyan(prResult.branchName)}`);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
logWarn(`Branch ${prResult.branchName} was pushed, but no pull request URL was returned.`, options);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
261
291
|
}
|
|
262
292
|
else {
|
|
263
293
|
await writeOutputs(options, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { findSuggestedCommandForFinding } from "../remediation/fix-commands.js";
|
|
2
2
|
import { chalk } from "../utils/chalk.js";
|
|
3
|
-
import { severityOrder } from "../constants.js";
|
|
3
|
+
import { severityOrder, MAL_PRIVATE_REGISTRY_MESSAGE } from "../constants.js";
|
|
4
4
|
import { loadCache } from "../osv/cache.js";
|
|
5
5
|
import { inferSeverity } from "../osv/severity.js";
|
|
6
6
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
@@ -40,6 +40,9 @@ function isMaliciousAdvisory(finding) {
|
|
|
40
40
|
}
|
|
41
41
|
export function getRecommendedAction(finding) {
|
|
42
42
|
if (isMaliciousAdvisory(finding)) {
|
|
43
|
+
if (finding.maliciousUnverifiable) {
|
|
44
|
+
return MAL_PRIVATE_REGISTRY_MESSAGE;
|
|
45
|
+
}
|
|
43
46
|
return finding.relationship === "direct"
|
|
44
47
|
? "This package has a malicious code advisory. Remove it from your dependencies."
|
|
45
48
|
: "This package has a malicious code advisory. Upgrade or remove the parent package that pulls it in.";
|
|
@@ -146,6 +149,9 @@ export function summarizeNextAction(finding) {
|
|
|
146
149
|
// line agrees with the fix-command table. See getRecommendedAction.
|
|
147
150
|
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
148
151
|
if (isMaliciousAdvisory(finding)) {
|
|
152
|
+
if (finding.maliciousUnverifiable) {
|
|
153
|
+
return MAL_PRIVATE_REGISTRY_MESSAGE;
|
|
154
|
+
}
|
|
149
155
|
return finding.relationship === "direct"
|
|
150
156
|
? "This package has a malicious code advisory. Remove it from your dependencies."
|
|
151
157
|
: "This package has a malicious code advisory. Upgrade or remove the parent package that pulls it in.";
|
|
@@ -194,6 +200,7 @@ export function serializeFinding(finding, plan) {
|
|
|
194
200
|
cves: finding.cveAliases,
|
|
195
201
|
dependencyPaths: finding.dependencyPaths,
|
|
196
202
|
usage: finding.usage ?? null,
|
|
203
|
+
maliciousUnverifiable: finding.maliciousUnverifiable ?? false,
|
|
197
204
|
vulnerabilities: finding.vulnerabilities.map(v => ({
|
|
198
205
|
id: v.id,
|
|
199
206
|
aliases: v.aliases ?? [],
|
|
@@ -97,6 +97,7 @@ button.header-link:hover{color:#58a6ff;border-color:#58a6ff}
|
|
|
97
97
|
.sev-badge.medium{background:#e3b34122;color:#e3b341;border:1px solid #e3b34166}
|
|
98
98
|
.sev-badge.low{background:#388bfd22;color:#388bfd;border:1px solid #388bfd66}
|
|
99
99
|
.sev-badge.unknown{background:#8b949e22;color:#8b949e;border:1px solid #8b949e66}
|
|
100
|
+
.badge-warning{display:inline-block;font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.4px;padding:2px 8px;border-radius:4px;background:#e3b34122;color:#e3b341;border:1px solid #e3b34166}
|
|
100
101
|
.rel-badge{font-size:11px;padding:2px 7px;border-radius:4px}
|
|
101
102
|
.rel-badge.direct{color:#3fb950;background:#3fb95022}
|
|
102
103
|
.rel-badge.transitive{color:#e3b341;background:#e3b34122}
|
|
@@ -404,9 +405,11 @@ export function renderFindingRow(finding, idx, skippedKeys) {
|
|
|
404
405
|
? `<span class="fix-hint hint-only" title="Advisory hint only — no automated fix command was generated. See the Skipped findings section below for details.">${escapeHtml(fixVersion)} ⊘</span>`
|
|
405
406
|
: fixVersion
|
|
406
407
|
? `<span class="fix-hint">${escapeHtml(fixVersion)}</span>`
|
|
407
|
-
: isMalicious
|
|
408
|
-
? `<span class="
|
|
409
|
-
:
|
|
408
|
+
: isMalicious && finding.maliciousUnverifiable
|
|
409
|
+
? `<span class="badge badge-warning" title="MAL- advisory found but package resolved from a private registry - may not apply to your artifact">Unverifiable (private source)</span>`
|
|
410
|
+
: isMalicious
|
|
411
|
+
? `<span class="fix-hint none" title="Malicious code advisory — remove this package">⚠ Malicious</span>`
|
|
412
|
+
: `<span class="fix-hint none" title="No known fix — consider replacing this package">⚠ No fix</span>`;
|
|
410
413
|
const depPathHtml = finding.dependencyPaths.length > 0
|
|
411
414
|
? finding.dependencyPaths[0].map((node, i, arr) => {
|
|
412
415
|
const isLast = i === arr.length - 1;
|
package/dist/output/printers.js
CHANGED
|
@@ -5,6 +5,7 @@ import { getPrimaryParent } from "../utils/finding.js";
|
|
|
5
5
|
import { countUniqueAdvisories, formatSeverityLabel, formatRelationshipLabel } from "./formatters.js";
|
|
6
6
|
import { pluralize } from "../utils/string.js";
|
|
7
7
|
import { selectFindingsForCompact } from "./finding-display.js";
|
|
8
|
+
import { MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE, MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE } from "../constants.js";
|
|
8
9
|
export function printSummary(findings, packageCount, scanInput) {
|
|
9
10
|
if (findings.length === 0) {
|
|
10
11
|
if (scanInput.mode === "manifest-fallback") {
|
|
@@ -157,11 +158,22 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
157
158
|
}
|
|
158
159
|
const isSkipped = skippedKeys?.has(`${f.pkg.name}@${f.pkg.version}`);
|
|
159
160
|
const fixVersion = f.validatedFirstFixedVersion ?? f.firstFixedVersion;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
let fixedDisplay;
|
|
162
|
+
if (isSkipped && fixVersion) {
|
|
163
|
+
fixedDisplay = chalk.gray(`${fixVersion} ⊘`);
|
|
164
|
+
}
|
|
165
|
+
else if (fixVersion) {
|
|
166
|
+
fixedDisplay = fixVersion;
|
|
167
|
+
}
|
|
168
|
+
else if (f.maliciousUnverifiable) {
|
|
169
|
+
fixedDisplay = chalk.yellow("⚠ Unverifiable (private source)");
|
|
170
|
+
}
|
|
171
|
+
else if (f.vulnerabilities.some(v => v.id.startsWith("MAL-"))) {
|
|
172
|
+
fixedDisplay = chalk.yellow("⚠ Malicious");
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
fixedDisplay = chalk.yellow("⚠ no fix");
|
|
176
|
+
}
|
|
165
177
|
return [
|
|
166
178
|
f.pkg.name,
|
|
167
179
|
f.pkg.version,
|
|
@@ -209,7 +221,12 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
209
221
|
const action = f.relationship === "direct"
|
|
210
222
|
? "Remove it from your dependencies immediately."
|
|
211
223
|
: "Upgrade or remove the parent package that pulls it in.";
|
|
212
|
-
|
|
224
|
+
if (f.maliciousUnverifiable) {
|
|
225
|
+
console.log(chalk.yellow(` · ${f.pkg.name}@${f.pkg.version} - Unverifiable (private source) - ${action}`));
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
console.log(chalk.red(` · ${f.pkg.name}@${f.pkg.version} - ${action}`));
|
|
229
|
+
}
|
|
213
230
|
}
|
|
214
231
|
}
|
|
215
232
|
if (skippedKeys && skippedKeys.size > 0 && findings.some(f => skippedKeys.has(`${f.pkg.name}@${f.pkg.version}`))) {
|
|
@@ -316,10 +333,15 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
316
333
|
console.log(` ${typeLabel}${usageContext}`);
|
|
317
334
|
const isMalicious = finding.vulnerabilities.some(v => v.id.startsWith("MAL-"));
|
|
318
335
|
if (isMalicious) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
336
|
+
if (finding.maliciousUnverifiable) {
|
|
337
|
+
console.log(` ${chalk.yellow(`⚠ Unverifiable (private source) - ${MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE}`)}`);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
const action = finding.relationship === "direct"
|
|
341
|
+
? "Remove this package from your dependencies immediately."
|
|
342
|
+
: "Upgrade or remove the parent package that pulls it in.";
|
|
343
|
+
console.log(` ${chalk.red(`⚠ Malicious: ${action}`)}`);
|
|
344
|
+
}
|
|
323
345
|
}
|
|
324
346
|
else if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
325
347
|
console.log(` ${chalk.gray(`Fix: lockfile refresh — ${finding.recommendedNpmTransitiveRemediation.package} already permits a safe version`)}`);
|
|
@@ -422,10 +444,15 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
422
444
|
console.log("");
|
|
423
445
|
console.log(chalk.bold.red("⚠ Malicious package advisory:"));
|
|
424
446
|
for (const f of maliciousCompact) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
447
|
+
if (f.maliciousUnverifiable) {
|
|
448
|
+
console.log(chalk.yellow(` · ${f.pkg.name}@${f.pkg.version} - Unverifiable (private source) - ${MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE}`));
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
const action = f.relationship === "direct"
|
|
452
|
+
? "Remove it from your dependencies immediately."
|
|
453
|
+
: "Upgrade or remove the parent package that pulls it in.";
|
|
454
|
+
console.log(chalk.red(` · ${f.pkg.name}@${f.pkg.version} - ${action}`));
|
|
455
|
+
}
|
|
429
456
|
}
|
|
430
457
|
}
|
|
431
458
|
if (options?.all) {
|
package/dist/parsers/bun-lock.js
CHANGED
|
@@ -1,9 +1,58 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import { uniquePathArrays } from "../utils/array.js";
|
|
2
3
|
import { upsertPackage } from "./utils.js";
|
|
4
|
+
const MAX_PATHS_PER_PACKAGE = 5;
|
|
5
|
+
const MAX_PATH_DEPTH = 10;
|
|
3
6
|
function parseJsonc(text) {
|
|
4
7
|
// bun.lock uses JSONC (trailing commas). Strip them before parsing.
|
|
5
8
|
return JSON.parse(text.replace(/,(\s*[}\]])/g, "$1"));
|
|
6
9
|
}
|
|
10
|
+
function extractChildDependencyNames(depMeta) {
|
|
11
|
+
if (!depMeta || typeof depMeta !== "object")
|
|
12
|
+
return [];
|
|
13
|
+
const names = new Set();
|
|
14
|
+
const meta = depMeta;
|
|
15
|
+
for (const section of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
16
|
+
const sectionObj = meta[section];
|
|
17
|
+
if (!sectionObj || typeof sectionObj !== "object")
|
|
18
|
+
continue;
|
|
19
|
+
for (const name of Object.keys(sectionObj)) {
|
|
20
|
+
names.add(name);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
24
|
+
if (key === "dependencies" || key === "optionalDependencies" || key === "devDependencies")
|
|
25
|
+
continue;
|
|
26
|
+
if (typeof value === "string") {
|
|
27
|
+
names.add(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return [...names];
|
|
31
|
+
}
|
|
32
|
+
function collectBunPaths(rootDepNames, childDepsByPackageName, map, packageNameToVersion) {
|
|
33
|
+
const queue = rootDepNames.map(name => ({ name, path: ["project"] }));
|
|
34
|
+
const visitedStates = new Set();
|
|
35
|
+
while (queue.length > 0) {
|
|
36
|
+
const current = queue.shift();
|
|
37
|
+
const nextPath = [...current.path, current.name];
|
|
38
|
+
const version = packageNameToVersion.get(current.name);
|
|
39
|
+
const stateKey = `${current.name}@${version ?? ""}>${nextPath.join(">")}`;
|
|
40
|
+
if (visitedStates.has(stateKey))
|
|
41
|
+
continue;
|
|
42
|
+
visitedStates.add(stateKey);
|
|
43
|
+
if (version) {
|
|
44
|
+
const pkg = map.get(`${current.name}@${version}`);
|
|
45
|
+
if (pkg) {
|
|
46
|
+
pkg.paths = uniquePathArrays([...(pkg.paths ?? []), nextPath]).slice(0, MAX_PATHS_PER_PACKAGE);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (nextPath.length >= MAX_PATH_DEPTH)
|
|
50
|
+
continue;
|
|
51
|
+
for (const child of childDepsByPackageName.get(current.name) ?? []) {
|
|
52
|
+
queue.push({ name: child, path: nextPath });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
7
56
|
export function buildBunWorkspaceMap(filePath) {
|
|
8
57
|
const raw = parseJsonc(fs.readFileSync(filePath, "utf8"));
|
|
9
58
|
const workspaces = raw?.workspaces ?? {};
|
|
@@ -28,9 +77,11 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
28
77
|
const packages = raw?.packages ?? {};
|
|
29
78
|
const workspaces = raw?.workspaces ?? {};
|
|
30
79
|
const map = new Map();
|
|
31
|
-
|
|
80
|
+
const childDepsByPackageName = new Map();
|
|
81
|
+
const packageNameToVersion = new Map();
|
|
32
82
|
const prodNames = new Set();
|
|
33
83
|
const devNames = new Set();
|
|
84
|
+
const rootDepNames = [];
|
|
34
85
|
for (const workspace of Object.values(workspaces)) {
|
|
35
86
|
for (const name of Object.keys(workspace?.dependencies ?? {})) {
|
|
36
87
|
prodNames.add(name);
|
|
@@ -39,11 +90,24 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
39
90
|
devNames.add(name);
|
|
40
91
|
}
|
|
41
92
|
}
|
|
93
|
+
for (const [workspacePath, workspace] of Object.entries(workspaces)) {
|
|
94
|
+
if (workspacePath !== "")
|
|
95
|
+
continue;
|
|
96
|
+
for (const depSectionName of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
97
|
+
if (prodOnly && depSectionName === "devDependencies")
|
|
98
|
+
continue;
|
|
99
|
+
const depSection = workspace?.[depSectionName];
|
|
100
|
+
if (!depSection || typeof depSection !== "object")
|
|
101
|
+
continue;
|
|
102
|
+
for (const depName of Object.keys(depSection)) {
|
|
103
|
+
rootDepNames.push(depName);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
42
107
|
for (const [pkgName, entry] of Object.entries(packages)) {
|
|
43
108
|
if (!Array.isArray(entry) || entry.length < 1)
|
|
44
109
|
continue;
|
|
45
110
|
const nameAtVersion = String(entry[0] ?? "");
|
|
46
|
-
// Split on last @ to handle scoped packages (e.g. @babel/core@7.0.0)
|
|
47
111
|
const atIndex = nameAtVersion.lastIndexOf("@");
|
|
48
112
|
if (atIndex <= 0)
|
|
49
113
|
continue;
|
|
@@ -51,8 +115,8 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
51
115
|
const version = nameAtVersion.slice(atIndex + 1);
|
|
52
116
|
if (!name || !version)
|
|
53
117
|
continue;
|
|
54
|
-
|
|
55
|
-
|
|
118
|
+
packageNameToVersion.set(pkgName, version);
|
|
119
|
+
childDepsByPackageName.set(pkgName, extractChildDependencyNames(entry[2]));
|
|
56
120
|
const dev = devNames.has(pkgName) && !prodNames.has(pkgName);
|
|
57
121
|
if (prodOnly && dev)
|
|
58
122
|
continue;
|
|
@@ -61,8 +125,14 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
61
125
|
version,
|
|
62
126
|
ecosystem: "npm",
|
|
63
127
|
dev,
|
|
64
|
-
paths: [
|
|
128
|
+
paths: [],
|
|
65
129
|
});
|
|
66
130
|
}
|
|
131
|
+
collectBunPaths(rootDepNames, childDepsByPackageName, map, packageNameToVersion);
|
|
132
|
+
for (const [pkgKey, pkg] of map.entries()) {
|
|
133
|
+
if ((pkg.paths?.length ?? 0) === 0) {
|
|
134
|
+
pkg.paths = [["project", pkg.name]];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
67
137
|
return [...map.values()];
|
|
68
138
|
}
|
package/dist/parsers/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
20
20
|
packages: loadFromBunLock(rootBunLock, prodOnly),
|
|
21
21
|
notes: [
|
|
22
22
|
"Scanned resolved dependency versions from bun.lock.",
|
|
23
|
-
"Dependency paths are
|
|
23
|
+
"Dependency paths are derived from bun.lock package relationships."
|
|
24
24
|
],
|
|
25
25
|
warnings: [],
|
|
26
26
|
skippedDependencies: []
|
|
@@ -76,7 +76,7 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
76
76
|
packages: loadFromYarnLock(rootYarnLock),
|
|
77
77
|
notes: [
|
|
78
78
|
"Scanned resolved dependency versions from yarn.lock.",
|
|
79
|
-
"Dependency
|
|
79
|
+
"Dependency paths are derived from yarn.lock package relationships."
|
|
80
80
|
],
|
|
81
81
|
warnings: [],
|
|
82
82
|
skippedDependencies: []
|
|
@@ -94,7 +94,7 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
94
94
|
packages: loadFromBunLock(selected, prodOnly),
|
|
95
95
|
notes: [
|
|
96
96
|
`Scanned resolved dependency versions from ${relativeOrName(projectRoot, selected)}.`,
|
|
97
|
-
"Dependency paths are
|
|
97
|
+
"Dependency paths are derived from bun.lock package relationships.",
|
|
98
98
|
"No supported lockfile was found at the repo root — a nested lockfile was used instead."
|
|
99
99
|
],
|
|
100
100
|
warnings: [],
|
|
@@ -153,7 +153,7 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
153
153
|
packages: loadFromYarnLock(selected),
|
|
154
154
|
notes: [
|
|
155
155
|
`Scanned resolved dependency versions from ${relativeOrName(projectRoot, selected)}.`,
|
|
156
|
-
"Dependency
|
|
156
|
+
"Dependency paths are derived from yarn.lock package relationships.",
|
|
157
157
|
"No supported lockfile was found at the repo root — a nested lockfile was used instead."
|
|
158
158
|
],
|
|
159
159
|
warnings: [],
|
|
@@ -44,7 +44,8 @@ export function loadFromPackageLock(filePath, prodOnly) {
|
|
|
44
44
|
const nodeIds = graph.nodeIdsFor(name, version);
|
|
45
45
|
const graphPaths = nodeIds.flatMap(id => graph.pathsFor(id));
|
|
46
46
|
const paths = graphPaths.length > 0 ? graphPaths : [normalizeNodeModulesPath(pkgPath)];
|
|
47
|
-
|
|
47
|
+
const resolvedUrl = meta?.resolved;
|
|
48
|
+
upsertPackage(map, { name, version, ecosystem: "npm", dev, paths, resolvedUrl });
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
if (map.size === 0 && raw.dependencies && typeof raw.dependencies === "object") {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { parse as parseYarnLock } from "yarn-lockfile";
|
|
4
|
+
import { uniquePathArrays } from "../utils/array.js";
|
|
5
|
+
import { normalizeRawVersion } from "../utils/version.js";
|
|
4
6
|
import { upsertPackage } from "./utils.js";
|
|
7
|
+
const MAX_PATHS_PER_PACKAGE = 5;
|
|
8
|
+
const MAX_PATH_DEPTH = 10;
|
|
5
9
|
export function buildYarnWorkspaceMap(filePath) {
|
|
6
10
|
const dir = path.dirname(filePath);
|
|
7
11
|
const map = new Map();
|
|
@@ -64,13 +68,113 @@ export function buildYarnWorkspaceMap(filePath) {
|
|
|
64
68
|
function isYarnBerry(content) {
|
|
65
69
|
return content.startsWith('__metadata:') || content.includes('\n__metadata:');
|
|
66
70
|
}
|
|
67
|
-
function
|
|
71
|
+
function pathsEqual(left, right) {
|
|
72
|
+
if (left.length !== right.length)
|
|
73
|
+
return false;
|
|
74
|
+
return left.every((value, index) => value === right[index]);
|
|
75
|
+
}
|
|
76
|
+
function parseYarnPackageKey(key) {
|
|
77
|
+
const idx = key.lastIndexOf("@");
|
|
78
|
+
if (idx <= 0)
|
|
79
|
+
return null;
|
|
80
|
+
const name = key.slice(0, idx);
|
|
81
|
+
const version = key.slice(idx + 1);
|
|
82
|
+
if (!name || !version)
|
|
83
|
+
return null;
|
|
84
|
+
return { key, name, version };
|
|
85
|
+
}
|
|
86
|
+
function collectYarnPaths(rootDepKeys, graph, map) {
|
|
87
|
+
const queue = rootDepKeys.map(key => ({ key, path: ["project"] }));
|
|
88
|
+
const visitedStates = new Set();
|
|
89
|
+
while (queue.length > 0) {
|
|
90
|
+
const current = queue.shift();
|
|
91
|
+
const ref = parseYarnPackageKey(current.key);
|
|
92
|
+
if (!ref)
|
|
93
|
+
continue;
|
|
94
|
+
const nextPath = [...current.path, ref.name];
|
|
95
|
+
const stateKey = `${ref.key}>${nextPath.join(">")}`;
|
|
96
|
+
if (visitedStates.has(stateKey))
|
|
97
|
+
continue;
|
|
98
|
+
visitedStates.add(stateKey);
|
|
99
|
+
const pkg = map.get(ref.key);
|
|
100
|
+
if (pkg) {
|
|
101
|
+
pkg.paths = uniquePathArrays([...(pkg.paths ?? []), nextPath]).slice(0, MAX_PATHS_PER_PACKAGE);
|
|
102
|
+
}
|
|
103
|
+
if (nextPath.length >= MAX_PATH_DEPTH)
|
|
104
|
+
continue;
|
|
105
|
+
if ((pkg?.paths?.length ?? 0) >= MAX_PATHS_PER_PACKAGE && !(pkg?.paths ?? []).some(path => pathsEqual(path, nextPath))) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
for (const child of graph.get(ref.key) ?? []) {
|
|
109
|
+
queue.push({ key: child, path: nextPath });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function loadRootDepKeys(filePath, selectorToKey, map) {
|
|
114
|
+
const dir = path.dirname(filePath);
|
|
115
|
+
let rootPkg;
|
|
116
|
+
try {
|
|
117
|
+
rootPkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
const rootDepKeys = [];
|
|
123
|
+
for (const depSection of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
124
|
+
const deps = rootPkg[depSection];
|
|
125
|
+
if (!deps || typeof deps !== "object")
|
|
126
|
+
continue;
|
|
127
|
+
for (const [depName, depRange] of Object.entries(deps)) {
|
|
128
|
+
const resolved = selectorToKey.get(`${depName}@${depRange}`) ??
|
|
129
|
+
selectorToKey.get(`${depName}@npm:${depRange}`);
|
|
130
|
+
if (resolved) {
|
|
131
|
+
rootDepKeys.push(resolved);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const fallbackVersion = normalizeRawVersion(depRange);
|
|
135
|
+
if (fallbackVersion) {
|
|
136
|
+
upsertPackage(map, {
|
|
137
|
+
name: String(depName),
|
|
138
|
+
version: fallbackVersion,
|
|
139
|
+
ecosystem: "npm",
|
|
140
|
+
paths: [["project", String(depName)]],
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return rootDepKeys;
|
|
146
|
+
}
|
|
147
|
+
function parseBerryDependencies(block) {
|
|
148
|
+
const dependencies = {};
|
|
149
|
+
const lines = block.split("\n");
|
|
150
|
+
let inDependencies = false;
|
|
151
|
+
for (const line of lines) {
|
|
152
|
+
if (/^\s*dependencies:\s*$/.test(line)) {
|
|
153
|
+
inDependencies = true;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (!inDependencies)
|
|
157
|
+
continue;
|
|
158
|
+
const depMatch = line.match(/^\s{2,}([^:]+):\s*(.+)$/);
|
|
159
|
+
if (!depMatch) {
|
|
160
|
+
if (!/^\s/.test(line))
|
|
161
|
+
inDependencies = false;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
dependencies[depMatch[1].trim().replace(/^"|"$/g, "")] = depMatch[2].trim().replace(/^"|"$/g, "");
|
|
165
|
+
}
|
|
166
|
+
return dependencies;
|
|
167
|
+
}
|
|
168
|
+
function loadFromYarnBerryLock(content, filePath) {
|
|
68
169
|
const map = new Map();
|
|
170
|
+
const graph = new Map();
|
|
171
|
+
const selectorToKey = new Map();
|
|
69
172
|
const blocks = content.split(/\n\n+/);
|
|
70
173
|
for (const block of blocks) {
|
|
71
174
|
const lines = block.trim().split('\n');
|
|
72
175
|
if (!lines[0] || lines[0].startsWith('__metadata'))
|
|
73
176
|
continue;
|
|
177
|
+
const selectorLine = lines[0].trim().replace(/:$/, "").replace(/^"|"$/g, "");
|
|
74
178
|
const resolutionLine = lines.find((l) => l.trim().startsWith('resolution:'));
|
|
75
179
|
if (!resolutionLine)
|
|
76
180
|
continue;
|
|
@@ -85,32 +189,87 @@ function loadFromYarnBerryLock(content) {
|
|
|
85
189
|
const version = resolution.slice(npmIdx + 5);
|
|
86
190
|
if (!name || !version)
|
|
87
191
|
continue;
|
|
88
|
-
|
|
192
|
+
const canonicalKey = `${name}@${version}`;
|
|
193
|
+
for (const selector of selectorLine.split(",").map(part => part.trim()).filter(Boolean)) {
|
|
194
|
+
selectorToKey.set(selector, canonicalKey);
|
|
195
|
+
}
|
|
196
|
+
upsertPackage(map, { name, version, ecosystem: 'npm', paths: [] });
|
|
197
|
+
}
|
|
198
|
+
for (const block of blocks) {
|
|
199
|
+
const lines = block.trim().split('\n');
|
|
200
|
+
if (!lines[0] || lines[0].startsWith('__metadata'))
|
|
201
|
+
continue;
|
|
202
|
+
const selectorLine = lines[0].trim().replace(/:$/, "").replace(/^"|"$/g, "");
|
|
203
|
+
const canonicalKey = selectorToKey.get(selectorLine.split(",").map(part => part.trim()).find(part => selectorToKey.has(part)) ?? selectorLine) ?? selectorToKey.get(selectorLine);
|
|
204
|
+
if (!canonicalKey)
|
|
205
|
+
continue;
|
|
206
|
+
const depKeys = new Set();
|
|
207
|
+
for (const [depName, depRef] of Object.entries(parseBerryDependencies(block))) {
|
|
208
|
+
const childSelector = depRef.startsWith("npm:") ? `${depName}@${depRef}` : `${depName}@${depRef}`;
|
|
209
|
+
const childKey = selectorToKey.get(childSelector);
|
|
210
|
+
if (childKey)
|
|
211
|
+
depKeys.add(childKey);
|
|
212
|
+
}
|
|
213
|
+
graph.set(canonicalKey, [...depKeys]);
|
|
89
214
|
}
|
|
215
|
+
const rootDepKeys = loadRootDepKeys(filePath, selectorToKey, map);
|
|
216
|
+
collectYarnPaths(rootDepKeys, graph, map);
|
|
90
217
|
return [...map.values()];
|
|
91
218
|
}
|
|
92
|
-
|
|
93
|
-
const content = fs.readFileSync(filePath, "utf8");
|
|
94
|
-
if (isYarnBerry(content)) {
|
|
95
|
-
return loadFromYarnBerryLock(content);
|
|
96
|
-
}
|
|
97
|
-
const parsed = parseYarnLock(content);
|
|
98
|
-
if (parsed.type !== "success" || !parsed.object) {
|
|
99
|
-
throw new Error("Could not parse yarn.lock");
|
|
100
|
-
}
|
|
219
|
+
function loadFromYarnClassicLock(parsed, filePath) {
|
|
101
220
|
const map = new Map();
|
|
102
|
-
|
|
221
|
+
const graph = new Map();
|
|
222
|
+
const selectorToKey = new Map();
|
|
223
|
+
for (const [selectorKey, meta] of Object.entries(parsed.object)) {
|
|
103
224
|
const version = meta?.version;
|
|
104
225
|
if (!version)
|
|
105
226
|
continue;
|
|
106
|
-
const
|
|
227
|
+
const selectors = String(selectorKey).split(",").map(selector => selector.trim()).filter(Boolean);
|
|
228
|
+
const firstSelector = selectors[0];
|
|
107
229
|
const atIndex = firstSelector.lastIndexOf("@");
|
|
108
230
|
if (atIndex <= 0)
|
|
109
231
|
continue;
|
|
110
232
|
const name = firstSelector.slice(0, atIndex);
|
|
111
|
-
|
|
233
|
+
const canonicalKey = `${name}@${version}`;
|
|
234
|
+
for (const selector of selectors) {
|
|
235
|
+
selectorToKey.set(selector, canonicalKey);
|
|
236
|
+
}
|
|
237
|
+
upsertPackage(map, { name, version, ecosystem: "npm", paths: [] });
|
|
238
|
+
}
|
|
239
|
+
for (const [selectorKey, meta] of Object.entries(parsed.object)) {
|
|
240
|
+
const version = meta?.version;
|
|
241
|
+
if (!version)
|
|
242
|
+
continue;
|
|
243
|
+
const selectors = String(selectorKey).split(",").map(selector => selector.trim()).filter(Boolean);
|
|
244
|
+
const firstSelector = selectors[0];
|
|
245
|
+
const atIndex = firstSelector.lastIndexOf("@");
|
|
246
|
+
if (atIndex <= 0)
|
|
112
247
|
continue;
|
|
113
|
-
|
|
248
|
+
const name = firstSelector.slice(0, atIndex);
|
|
249
|
+
const canonicalKey = `${name}@${version}`;
|
|
250
|
+
const depKeys = new Set();
|
|
251
|
+
const deps = meta?.dependencies;
|
|
252
|
+
if (deps && typeof deps === "object") {
|
|
253
|
+
for (const [depName, depRange] of Object.entries(deps)) {
|
|
254
|
+
const childKey = selectorToKey.get(`${depName}@${depRange}`);
|
|
255
|
+
if (childKey)
|
|
256
|
+
depKeys.add(childKey);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
graph.set(canonicalKey, [...depKeys]);
|
|
114
260
|
}
|
|
261
|
+
const rootDepKeys = loadRootDepKeys(filePath, selectorToKey, map);
|
|
262
|
+
collectYarnPaths(rootDepKeys, graph, map);
|
|
115
263
|
return [...map.values()];
|
|
116
264
|
}
|
|
265
|
+
export function loadFromYarnLock(filePath) {
|
|
266
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
267
|
+
if (isYarnBerry(content)) {
|
|
268
|
+
return loadFromYarnBerryLock(content, filePath);
|
|
269
|
+
}
|
|
270
|
+
const parsed = parseYarnLock(content);
|
|
271
|
+
if (parsed.type !== "success" || !parsed.object) {
|
|
272
|
+
throw new Error("Could not parse yarn.lock");
|
|
273
|
+
}
|
|
274
|
+
return loadFromYarnClassicLock(parsed, filePath);
|
|
275
|
+
}
|
|
@@ -11,12 +11,21 @@ export async function resolveTransitiveRemediationViaRegistry(args) {
|
|
|
11
11
|
if (!directParentContext)
|
|
12
12
|
return null;
|
|
13
13
|
const { directParentName, immediateParentName, directParent } = directParentContext;
|
|
14
|
-
if (directParentName !== immediateParentName)
|
|
15
|
-
return null;
|
|
16
|
-
if (!looksLikeVersion(directParent.version))
|
|
17
|
-
return null;
|
|
18
14
|
const vulnerableName = args.finding.pkg.name;
|
|
19
15
|
const fixHint = args.finding.validatedFirstFixedVersion ?? args.finding.firstFixedVersion;
|
|
16
|
+
if (directParentName !== immediateParentName) {
|
|
17
|
+
return resolveWithinRangeForDeepChainViaRegistry({
|
|
18
|
+
immediateParentName,
|
|
19
|
+
vulnerableName,
|
|
20
|
+
installedVersion: args.finding.pkg.version,
|
|
21
|
+
fixHint,
|
|
22
|
+
viaPath,
|
|
23
|
+
packages: args.packages,
|
|
24
|
+
workspaceMap: args.workspaceMap,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (!looksLikeVersion(directParent.version))
|
|
28
|
+
return null;
|
|
20
29
|
const safeCandidates = await findSafeChildCandidates(vulnerableName, args.finding.pkg.version, fixHint);
|
|
21
30
|
if (safeCandidates.length === 0)
|
|
22
31
|
return null;
|
|
@@ -291,6 +300,36 @@ function parseCoreVersion(version) {
|
|
|
291
300
|
const [major = "0", minor = "0", patch = "0"] = version.split(/[+-]/)[0].split(".");
|
|
292
301
|
return [Number(major), Number(minor), Number(patch)];
|
|
293
302
|
}
|
|
303
|
+
async function resolveWithinRangeForDeepChainViaRegistry(args) {
|
|
304
|
+
const immediateParent = args.packages.find(pkg => pkg.name === args.immediateParentName);
|
|
305
|
+
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
|
306
|
+
return null;
|
|
307
|
+
const safeCandidates = await findSafeChildCandidates(args.vulnerableName, args.installedVersion, args.fixHint);
|
|
308
|
+
if (safeCandidates.length === 0)
|
|
309
|
+
return null;
|
|
310
|
+
const packument = await fetchPackument(args.immediateParentName);
|
|
311
|
+
const parentManifest = packument?.versions?.[immediateParent.version];
|
|
312
|
+
const depRange = parentManifest?.dependencies?.[args.vulnerableName] ??
|
|
313
|
+
parentManifest?.optionalDependencies?.[args.vulnerableName];
|
|
314
|
+
if (!depRange)
|
|
315
|
+
return null;
|
|
316
|
+
const inRangeTarget = [...safeCandidates]
|
|
317
|
+
.sort(compareVersions)
|
|
318
|
+
.filter(version => versionSatisfiesRange(version, depRange))
|
|
319
|
+
.at(-1);
|
|
320
|
+
if (!inRangeTarget)
|
|
321
|
+
return null;
|
|
322
|
+
const workspaces = collectWorkspacesFromAllPaths([args.viaPath], args.workspaceMap);
|
|
323
|
+
return {
|
|
324
|
+
kind: "update-parent-within-range",
|
|
325
|
+
package: args.vulnerableName,
|
|
326
|
+
currentVersion: args.installedVersion,
|
|
327
|
+
targetChildVersion: inRangeTarget,
|
|
328
|
+
viaPath: args.viaPath,
|
|
329
|
+
reason: `${args.immediateParentName}@${immediateParent.version} already allows ${args.vulnerableName}@${inRangeTarget} within the current dependency range`,
|
|
330
|
+
workspaces,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
294
333
|
async function resolveWithinRangeForDeepChain(args) {
|
|
295
334
|
const immediateParent = args.packages.find(p => p.name === args.immediateParentName);
|
|
296
335
|
if (!immediateParent || !looksLikeVersion(immediateParent.version))
|
package/dist/scanner.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { chunk, unique, runWithConcurrency } from "./utils/array.js";
|
|
2
|
+
import { isPrivateRegistrySource } from "./utils/advisory.js";
|
|
2
3
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "./utils/version.js";
|
|
3
4
|
import { loadCache, saveCache, isEntryStale } from "./osv/cache.js";
|
|
4
5
|
import { maxSeverity } from "./osv/severity.js";
|
|
@@ -217,6 +218,12 @@ export async function scanPackages(packages, batchSize, options, context, debugL
|
|
|
217
218
|
recommendedNpmTransitiveRemediation: undefined,
|
|
218
219
|
};
|
|
219
220
|
});
|
|
221
|
+
for (const finding of findings) {
|
|
222
|
+
if (finding.vulnerabilities.some(v => v.id.startsWith("MAL-")) &&
|
|
223
|
+
isPrivateRegistrySource(finding.pkg)) {
|
|
224
|
+
finding.maliciousUnverifiable = true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
220
227
|
const npmTransitiveGraph = context?.scanSource === "package-lock" && context.scanFilePath
|
|
221
228
|
? createNpmTransitiveGraphFromLockfile(context.scanFilePath, log, packages.length)
|
|
222
229
|
: null;
|