cve-lite-cli 1.0.5 → 1.0.6
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 +25 -7
- package/dist/output/formatters.js +41 -13
- package/dist/output/printers.js +18 -3
- package/dist/remediation/parent-upgrade.js +224 -0
- package/dist/scanner.js +16 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<a href="#quick-start">Quick Start</a> •
|
|
11
11
|
<a href="#features">Features</a> •
|
|
12
12
|
<a href="#usage">Usage</a> •
|
|
13
|
-
<a href="CONTRIBUTING.md">Contributing</a>
|
|
13
|
+
<a href="https://github.com/sonukapoor/cve-lite-cli/blob/main/src/docs/CONTRIBUTING.md">Contributing</a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
16
|
</div>
|
|
@@ -74,7 +74,7 @@ cve-lite /path/to/project --osv-url https://security.company.internal/osv
|
|
|
74
74
|
|
|
75
75
|
CVE Lite CLI produces a clean, summary-first console view by default, designed for fast triage before release.
|
|
76
76
|
|
|
77
|
-
For deeper investigation, running with `--verbose` provides full details, including dependency paths, a complete fix plan, and a detailed table view.
|
|
77
|
+
For deeper investigation, running with `--verbose` provides full details, including dependency paths, parent upgrade guidance for transitive issues when available, a complete fix plan, and a detailed table view.
|
|
78
78
|
|
|
79
79
|
That is the core idea: install it, point it at your project, and immediately get a practical fix plan instead of a wall of raw advisories.
|
|
80
80
|
|
|
@@ -164,7 +164,7 @@ CVE Lite CLI is a local-first scanner. It parses dependency information locally,
|
|
|
164
164
|
|
|
165
165
|
It does not require a hosted account, cloud dashboard, or source code upload.
|
|
166
166
|
|
|
167
|
-
For the full explanation, see [Network Behavior and Privacy](
|
|
167
|
+
For the full explanation, see [Network Behavior and Privacy](https://github.com/sonukapoor/cve-lite-cli/blob/main/src/docs/network-and-privacy.md).
|
|
168
168
|
|
|
169
169
|
### Planned support for stricter environments
|
|
170
170
|
|
|
@@ -174,6 +174,21 @@ Support for stricter network-controlled environments is planned on the roadmap,
|
|
|
174
174
|
- custom advisory endpoint support for internal mirrors or proxies
|
|
175
175
|
- local advisory database input for controlled or air-gapped workflows
|
|
176
176
|
|
|
177
|
+
## Detecting malicious package incidents
|
|
178
|
+
|
|
179
|
+
CVE Lite CLI can help detect malicious package incidents and supply-chain compromises **once the affected versions are represented in OSV or equivalent advisory data available through the configured advisory endpoint**.
|
|
180
|
+
|
|
181
|
+
In practice, that means the tool can catch incidents such as a compromised npm package **when the exact malicious version appears in your lockfile** and the advisory data has already been published and indexed. This makes the tool useful for real-world release checks after a malicious package disclosure becomes known.
|
|
182
|
+
|
|
183
|
+
It is important to be precise about the current scope:
|
|
184
|
+
|
|
185
|
+
- CVE Lite CLI is **advisory-driven**, not a behavioral malware detector
|
|
186
|
+
- it does **not** perform static malware analysis on package contents
|
|
187
|
+
- it does **not** detect a package compromise before advisory intelligence exists for it
|
|
188
|
+
- it works best with lockfiles because they capture the exact resolved version that was actually installed
|
|
189
|
+
|
|
190
|
+
So the practical model is: **local lockfile scan + advisory matching**. When malicious versions are published to OSV or mirrored through a compatible internal endpoint, CVE Lite CLI can flag those exact versions during a scan.
|
|
191
|
+
|
|
177
192
|
## How it works
|
|
178
193
|
|
|
179
194
|
### Architectural Philosophy
|
|
@@ -229,6 +244,7 @@ Instead of only showing advisory IDs, the CLI reports:
|
|
|
229
244
|
- fixed-version hint when available
|
|
230
245
|
- advisory IDs
|
|
231
246
|
- dependency path hints
|
|
247
|
+
- recommended parent upgrade for transitive issues when available
|
|
232
248
|
|
|
233
249
|
By default, the CLI now presents a cleaner summary-first view, with `--verbose` available for the full detailed output.
|
|
234
250
|
|
|
@@ -247,7 +263,7 @@ CVE Lite CLI organizes likely remediation work into a practical sequence, such a
|
|
|
247
263
|
|
|
248
264
|
### 5. Parent package hints for transitive issues
|
|
249
265
|
|
|
250
|
-
For transitive vulnerabilities, the
|
|
266
|
+
For transitive vulnerabilities, CVE Lite CLI can show the dependency path and, when it can determine one reliably, recommend the parent package upgrade to make. That makes the output more actionable than simply saying a nested package is vulnerable.
|
|
251
267
|
|
|
252
268
|
### 6. JSON output
|
|
253
269
|
|
|
@@ -313,7 +329,7 @@ Run it before a release, during dependency cleanup, or after a major package upg
|
|
|
313
329
|
|
|
314
330
|
### CI/CD
|
|
315
331
|
|
|
316
|
-
This repository also uses CVE Lite CLI in its own GitHub Actions workflow to scan itself as part of CI. See [`self-scan.yml`](
|
|
332
|
+
This repository also uses CVE Lite CLI in its own GitHub Actions workflow to scan itself as part of CI. See [`self-scan.yml`](https://github.com/sonukapoor/cve-lite-cli/blob/main/.github/workflows/self-scan.yml).
|
|
317
333
|
|
|
318
334
|
For CI, we recommend using `--verbose` so build logs include the full fix plan, dependency paths, and detailed table output when a scan fails.
|
|
319
335
|
|
|
@@ -422,6 +438,8 @@ If your goal is a practical developer-first CVE scan right before release, CVE L
|
|
|
422
438
|
|
|
423
439
|
To keep the project honest, here is what it does **not** do in the current version:
|
|
424
440
|
|
|
441
|
+
- it does not detect malicious packages before they are represented in advisory data
|
|
442
|
+
- it does not perform behavioral malware detection or package content analysis
|
|
425
443
|
- it does not prove exploitability
|
|
426
444
|
- it does not verify runtime reachability
|
|
427
445
|
- it does not scan container images, binaries, secrets, or IaC
|
|
@@ -456,7 +474,7 @@ CVE Lite CLI is evolving from a vulnerability scanner into a comprehensive remed
|
|
|
456
474
|
|
|
457
475
|
This project is being shaped around real-world developer usability. Feedback on output clarity, remediation guidance, ecosystem coverage, and CI usage is especially valuable.
|
|
458
476
|
|
|
459
|
-
To get started, see [CONTRIBUTING.md](
|
|
477
|
+
To get started, see [CONTRIBUTING.md](https://github.com/sonukapoor/cve-lite-cli/blob/main/src/docs/CONTRIBUTING.md).
|
|
460
478
|
|
|
461
479
|
## Community and support
|
|
462
480
|
|
|
@@ -475,7 +493,7 @@ Helpful feedback includes:
|
|
|
475
493
|
|
|
476
494
|
As the project grows, contribution and security guidance will be expanded further in dedicated project docs.
|
|
477
495
|
|
|
478
|
-
For bug reports and feature requests, please use [GitHub Issues](https://github.com/sonukapoor/cve-lite-cli/issues). For contribution guidance, see [CONTRIBUTING.md](
|
|
496
|
+
For bug reports and feature requests, please use [GitHub Issues](https://github.com/sonukapoor/cve-lite-cli/issues). For contribution guidance, see [CONTRIBUTING.md](https://github.com/sonukapoor/cve-lite-cli/blob/main/src/docs/CONTRIBUTING.md). For security-related reporting, see [SECURITY.md](https://github.com/sonukapoor/cve-lite-cli/blob/main/src/docs/SECURITY.md).
|
|
479
497
|
|
|
480
498
|
## License
|
|
481
499
|
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { chalk } from "../utils/chalk.js";
|
|
2
|
+
import { severityOrder } from "../constants.js";
|
|
2
3
|
import { loadCache } from "../osv/cache.js";
|
|
3
4
|
import { inferSeverity } from "../osv/severity.js";
|
|
4
5
|
export function formatSeverityLabel(severity) {
|
|
5
|
-
|
|
6
|
+
const lower = severity.toLowerCase();
|
|
7
|
+
if (lower === "critical")
|
|
6
8
|
return chalk.redBright(severity);
|
|
7
|
-
if (
|
|
9
|
+
if (lower === "high")
|
|
8
10
|
return chalk.red(severity);
|
|
9
|
-
if (
|
|
11
|
+
if (lower === "medium")
|
|
10
12
|
return chalk.yellow(severity);
|
|
11
|
-
if (
|
|
13
|
+
if (lower === "low")
|
|
12
14
|
return chalk.blueBright(severity);
|
|
13
|
-
if (
|
|
15
|
+
if (lower === "unknown")
|
|
14
16
|
return chalk.magenta(severity);
|
|
15
17
|
return severity;
|
|
16
18
|
}
|
|
@@ -34,6 +36,9 @@ export function getRecommendedAction(finding) {
|
|
|
34
36
|
if (finding.relationship === "direct") {
|
|
35
37
|
return `Review and upgrade ${finding.pkg.name} directly in this project.`;
|
|
36
38
|
}
|
|
39
|
+
if (finding.recommendedParentUpgrade) {
|
|
40
|
+
return `Upgrade ${finding.recommendedParentUpgrade.package} from ${finding.recommendedParentUpgrade.currentVersion} to ${finding.recommendedParentUpgrade.targetVersion} to stop pulling in vulnerable ${finding.pkg.name}.`;
|
|
41
|
+
}
|
|
37
42
|
const parent = getPrimaryParent(finding);
|
|
38
43
|
if (parent && finding.firstFixedVersion) {
|
|
39
44
|
return `Review ${parent}; aim for a version that resolves ${finding.pkg.name} to ${finding.firstFixedVersion}+`;
|
|
@@ -53,6 +58,9 @@ export function summarizeRisk(finding) {
|
|
|
53
58
|
if (finding.severity === "high" && finding.relationship === "direct") {
|
|
54
59
|
return "High-severity direct dependency. A direct upgrade is likely the fastest path.";
|
|
55
60
|
}
|
|
61
|
+
if (finding.relationship === "transitive" && finding.recommendedParentUpgrade) {
|
|
62
|
+
return `Transitive issue. A specific parent upgrade target was found for ${finding.recommendedParentUpgrade.package}.`;
|
|
63
|
+
}
|
|
56
64
|
if (finding.relationship === "transitive" && finding.firstFixedVersion) {
|
|
57
65
|
return `Transitive issue. Look for a parent dependency upgrade that pulls in ${finding.firstFixedVersion}+`;
|
|
58
66
|
}
|
|
@@ -71,6 +79,9 @@ export function summarizeNextAction(finding) {
|
|
|
71
79
|
if (finding.relationship === "direct") {
|
|
72
80
|
return `Review and upgrade ${finding.pkg.name} directly in this project.`;
|
|
73
81
|
}
|
|
82
|
+
if (finding.recommendedParentUpgrade) {
|
|
83
|
+
return `Upgrade ${finding.recommendedParentUpgrade.package} ${finding.recommendedParentUpgrade.currentVersion} -> ${finding.recommendedParentUpgrade.targetVersion}.`;
|
|
84
|
+
}
|
|
74
85
|
if (finding.firstFixedVersion) {
|
|
75
86
|
return `Upgrade the parent dependency chain so it resolves ${finding.pkg.name} to ${finding.firstFixedVersion}+`;
|
|
76
87
|
}
|
|
@@ -85,14 +96,15 @@ export function serializeFinding(finding) {
|
|
|
85
96
|
firstFixedVersion: finding.firstFixedVersion,
|
|
86
97
|
recommendedAction: getRecommendedAction(finding),
|
|
87
98
|
primaryParent: getPrimaryParent(finding),
|
|
99
|
+
recommendedParentUpgrade: finding.recommendedParentUpgrade,
|
|
88
100
|
cves: finding.cveAliases,
|
|
89
101
|
dependencyPaths: finding.dependencyPaths,
|
|
90
102
|
vulnerabilities: finding.vulnerabilities.map(v => ({
|
|
91
103
|
id: v.id,
|
|
92
104
|
aliases: v.aliases ?? [],
|
|
93
105
|
summary: v.summary ?? "",
|
|
94
|
-
severity: inferSeverity(v)
|
|
95
|
-
}))
|
|
106
|
+
severity: inferSeverity(v),
|
|
107
|
+
})),
|
|
96
108
|
};
|
|
97
109
|
}
|
|
98
110
|
export function printCacheSummary(cacheDirOverride, options) {
|
|
@@ -100,14 +112,30 @@ export function printCacheSummary(cacheDirOverride, options) {
|
|
|
100
112
|
return;
|
|
101
113
|
const cache = loadCache(cacheDirOverride);
|
|
102
114
|
const advisoryCount = Object.entries(cache.entries).filter(([, value]) => Boolean(value)).length;
|
|
103
|
-
const
|
|
104
|
-
|
|
115
|
+
const emptyCount = Object.entries(cache.entries).filter(([, value]) => value === null).length;
|
|
116
|
+
const totalCount = advisoryCount + emptyCount;
|
|
117
|
+
if (totalCount === 0)
|
|
118
|
+
return;
|
|
119
|
+
console.log(chalk.gray(`Cache: ${advisoryCount} advisory detail record${advisoryCount === 1 ? "" : "s"}`) +
|
|
120
|
+
(emptyCount > 0
|
|
121
|
+
? chalk.gray(`, ${emptyCount} empty lookup${emptyCount === 1 ? "" : "s"}`)
|
|
122
|
+
: ""));
|
|
105
123
|
}
|
|
106
124
|
export function logInfo(message, options) {
|
|
107
|
-
if (
|
|
108
|
-
|
|
125
|
+
if (options?.json)
|
|
126
|
+
return;
|
|
127
|
+
console.log(chalk.gray(message));
|
|
109
128
|
}
|
|
110
129
|
export function logWarn(message, options) {
|
|
111
|
-
if (
|
|
112
|
-
|
|
130
|
+
if (options?.json)
|
|
131
|
+
return;
|
|
132
|
+
console.log(chalk.yellow(message));
|
|
133
|
+
}
|
|
134
|
+
export function sortFindingsForOutput(findings) {
|
|
135
|
+
return [...findings].sort((a, b) => {
|
|
136
|
+
const sevDelta = severityOrder[b.severity] - severityOrder[a.severity];
|
|
137
|
+
if (sevDelta !== 0)
|
|
138
|
+
return sevDelta;
|
|
139
|
+
return a.pkg.name.localeCompare(b.pkg.name);
|
|
140
|
+
});
|
|
113
141
|
}
|
package/dist/output/printers.js
CHANGED
|
@@ -64,6 +64,9 @@ export function printPriorityFixes(findings) {
|
|
|
64
64
|
const parent = getPrimaryParent(finding);
|
|
65
65
|
if (parent)
|
|
66
66
|
console.log(` Parent: ${parent}`);
|
|
67
|
+
if (finding.recommendedParentUpgrade) {
|
|
68
|
+
console.log(` Target: ${finding.recommendedParentUpgrade.package} ${finding.recommendedParentUpgrade.currentVersion} -> ${finding.recommendedParentUpgrade.targetVersion}`);
|
|
69
|
+
}
|
|
67
70
|
console.log(` Next: ${summarizeNextAction(finding)}`);
|
|
68
71
|
}
|
|
69
72
|
}
|
|
@@ -187,6 +190,9 @@ export function printPathHints(findings) {
|
|
|
187
190
|
for (const example of examples) {
|
|
188
191
|
console.log(` ${chalk.gray(example)}`);
|
|
189
192
|
}
|
|
193
|
+
if (finding.recommendedParentUpgrade) {
|
|
194
|
+
console.log(` Recommended parent upgrade: ${chalk.bold.cyan(finding.recommendedParentUpgrade.package)} ${finding.recommendedParentUpgrade.currentVersion} -> ${finding.recommendedParentUpgrade.targetVersion}`);
|
|
195
|
+
}
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
export function printFinalStatus(findings) {
|
|
@@ -235,11 +241,17 @@ export function printCompactOutput(findings) {
|
|
|
235
241
|
.slice(0, 3);
|
|
236
242
|
for (const finding of urgentFindings) {
|
|
237
243
|
const sevLabel = finding.severity.toUpperCase().padEnd(8);
|
|
238
|
-
const typeLabel = finding.relationship === "direct"
|
|
239
|
-
|
|
244
|
+
const typeLabel = finding.relationship === "direct"
|
|
245
|
+
? "Direct dependency"
|
|
246
|
+
: finding.relationship === "transitive"
|
|
247
|
+
? "Transitive dependency"
|
|
248
|
+
: "Unknown dependency";
|
|
240
249
|
console.log(`${formatSeverityLabel(sevLabel)} ${chalk.whiteBright(finding.pkg.name)}@${finding.pkg.version}`);
|
|
241
250
|
console.log(` ${typeLabel}`);
|
|
242
|
-
if (finding.
|
|
251
|
+
if (finding.recommendedParentUpgrade) {
|
|
252
|
+
console.log(` ${chalk.gray(`Fix: upgrade ${finding.recommendedParentUpgrade.package} to ${finding.recommendedParentUpgrade.targetVersion}`)}`);
|
|
253
|
+
}
|
|
254
|
+
else if (finding.firstFixedVersion) {
|
|
243
255
|
const action = finding.relationship === "direct"
|
|
244
256
|
? `upgrade to ${finding.firstFixedVersion}`
|
|
245
257
|
: `upgrade parent chain to resolve ${finding.firstFixedVersion}+`;
|
|
@@ -265,6 +277,9 @@ export function printCompactOutput(findings) {
|
|
|
265
277
|
else if (topFinding.relationship === "direct") {
|
|
266
278
|
console.log(`Upgrade ${chalk.whiteBright(topFinding.pkg.name)} to latest safe version`);
|
|
267
279
|
}
|
|
280
|
+
else if (topFinding.recommendedParentUpgrade) {
|
|
281
|
+
console.log(`Upgrade ${chalk.whiteBright(topFinding.recommendedParentUpgrade.package)} ${topFinding.recommendedParentUpgrade.currentVersion} → ${topFinding.recommendedParentUpgrade.targetVersion}`);
|
|
282
|
+
}
|
|
268
283
|
else {
|
|
269
284
|
const parent = getPrimaryParent(topFinding);
|
|
270
285
|
if (parent) {
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
2
|
+
const packumentCache = new Map();
|
|
3
|
+
const DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
4
|
+
export async function resolveRecommendedParentUpgrade(finding, packages) {
|
|
5
|
+
if (finding.relationship !== "transitive")
|
|
6
|
+
return null;
|
|
7
|
+
const viaPath = getBestPath(finding);
|
|
8
|
+
if (!viaPath || viaPath.length < 3)
|
|
9
|
+
return null;
|
|
10
|
+
const directParentName = viaPath[1];
|
|
11
|
+
const immediateParentName = viaPath[viaPath.length - 2];
|
|
12
|
+
const vulnerableName = finding.pkg.name;
|
|
13
|
+
const directParent = findDirectDependency(packages, directParentName);
|
|
14
|
+
if (!directParent)
|
|
15
|
+
return null;
|
|
16
|
+
// Common reliable case:
|
|
17
|
+
// project -> sanitize-html -> lodash
|
|
18
|
+
if (viaPath.length === 3) {
|
|
19
|
+
return findUpgradeForExactDirectChild({
|
|
20
|
+
directParentName,
|
|
21
|
+
directParentVersion: directParent.version,
|
|
22
|
+
vulnerableName,
|
|
23
|
+
vulnerableInstalledVersion: finding.pkg.version,
|
|
24
|
+
vulnerableFixedVersion: finding.firstFixedVersion,
|
|
25
|
+
viaPath,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// Best-effort fallback for deeper chains.
|
|
29
|
+
return findUpgradeForImmediateIntermediate({
|
|
30
|
+
directParentName,
|
|
31
|
+
directParentVersion: directParent.version,
|
|
32
|
+
immediateParentName,
|
|
33
|
+
immediateParentInstalledVersion: findPackageVersion(packages, immediateParentName, viaPath.slice(0, -1)) ?? "",
|
|
34
|
+
vulnerableName,
|
|
35
|
+
viaPath,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function getBestPath(finding) {
|
|
39
|
+
const paths = finding.dependencyPaths ?? [];
|
|
40
|
+
if (paths.length === 0)
|
|
41
|
+
return null;
|
|
42
|
+
return [...paths].sort((a, b) => a.length - b.length)[0] ?? null;
|
|
43
|
+
}
|
|
44
|
+
function findDirectDependency(packages, name) {
|
|
45
|
+
for (const pkg of packages) {
|
|
46
|
+
if (pkg.name !== name)
|
|
47
|
+
continue;
|
|
48
|
+
const paths = pkg.paths ?? [];
|
|
49
|
+
if (paths.some(path => path.length === 2 && path[1] === name)) {
|
|
50
|
+
return pkg;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
function findPackageVersion(packages, name, pathPrefix) {
|
|
56
|
+
for (const pkg of packages) {
|
|
57
|
+
if (pkg.name !== name)
|
|
58
|
+
continue;
|
|
59
|
+
const paths = pkg.paths ?? [];
|
|
60
|
+
if (paths.some(path => startsWithPath(path, pathPrefix))) {
|
|
61
|
+
return pkg.version;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
function startsWithPath(path, prefix) {
|
|
67
|
+
if (prefix.length > path.length)
|
|
68
|
+
return false;
|
|
69
|
+
for (let i = 0; i < prefix.length; i++) {
|
|
70
|
+
if (path[i] !== prefix[i])
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
async function findUpgradeForExactDirectChild(args) {
|
|
76
|
+
const packument = await fetchPackument(args.directParentName);
|
|
77
|
+
const versions = Object.keys(packument?.versions ?? {})
|
|
78
|
+
.filter(looksLikeVersion)
|
|
79
|
+
.filter(version => compareVersions(version, args.directParentVersion) > 0)
|
|
80
|
+
.sort(compareVersions);
|
|
81
|
+
for (const version of versions) {
|
|
82
|
+
const manifest = packument?.versions?.[version];
|
|
83
|
+
const depRange = manifest?.dependencies?.[args.vulnerableName] ??
|
|
84
|
+
manifest?.optionalDependencies?.[args.vulnerableName];
|
|
85
|
+
if (!depRange)
|
|
86
|
+
continue;
|
|
87
|
+
const stillAllowsInstalled = versionSatisfiesRange(args.vulnerableInstalledVersion, depRange);
|
|
88
|
+
const allowsFixed = args.vulnerableFixedVersion
|
|
89
|
+
? versionSatisfiesRange(args.vulnerableFixedVersion, depRange)
|
|
90
|
+
: true;
|
|
91
|
+
if (!stillAllowsInstalled && allowsFixed) {
|
|
92
|
+
return {
|
|
93
|
+
package: args.directParentName,
|
|
94
|
+
currentVersion: args.directParentVersion,
|
|
95
|
+
targetVersion: version,
|
|
96
|
+
viaPath: args.viaPath,
|
|
97
|
+
vulnerablePackage: args.vulnerableName,
|
|
98
|
+
confidence: "exact-direct-child",
|
|
99
|
+
reason: `${args.directParentName}@${version} no longer allows ${args.vulnerableName}@${args.vulnerableInstalledVersion}${args.vulnerableFixedVersion ? ` and allows ${args.vulnerableFixedVersion}+` : ""}`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
async function findUpgradeForImmediateIntermediate(args) {
|
|
106
|
+
if (!args.immediateParentInstalledVersion || !looksLikeVersion(args.immediateParentInstalledVersion)) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const packument = await fetchPackument(args.directParentName);
|
|
110
|
+
const versions = Object.keys(packument?.versions ?? {})
|
|
111
|
+
.filter(looksLikeVersion)
|
|
112
|
+
.filter(version => compareVersions(version, args.directParentVersion) > 0)
|
|
113
|
+
.sort(compareVersions);
|
|
114
|
+
for (const version of versions) {
|
|
115
|
+
const manifest = packument?.versions?.[version];
|
|
116
|
+
const depRange = manifest?.dependencies?.[args.immediateParentName] ??
|
|
117
|
+
manifest?.optionalDependencies?.[args.immediateParentName];
|
|
118
|
+
if (!depRange)
|
|
119
|
+
continue;
|
|
120
|
+
const stillAllowsImmediateParentInstalled = versionSatisfiesRange(args.immediateParentInstalledVersion, depRange);
|
|
121
|
+
if (!stillAllowsImmediateParentInstalled) {
|
|
122
|
+
return {
|
|
123
|
+
package: args.directParentName,
|
|
124
|
+
currentVersion: args.directParentVersion,
|
|
125
|
+
targetVersion: version,
|
|
126
|
+
viaPath: args.viaPath,
|
|
127
|
+
vulnerablePackage: args.vulnerableName,
|
|
128
|
+
confidence: "best-effort",
|
|
129
|
+
reason: `${args.directParentName}@${version} no longer allows ${args.immediateParentName}@${args.immediateParentInstalledVersion} in the current path`,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
async function fetchPackument(packageName) {
|
|
136
|
+
if (packumentCache.has(packageName)) {
|
|
137
|
+
return packumentCache.get(packageName) ?? null;
|
|
138
|
+
}
|
|
139
|
+
const url = `${DEFAULT_NPM_REGISTRY_URL}/${encodeURIComponent(packageName)
|
|
140
|
+
.replace(/%40/g, "@")
|
|
141
|
+
.replace(/%2F/g, "/")}`;
|
|
142
|
+
const response = await fetch(url);
|
|
143
|
+
if (!response.ok) {
|
|
144
|
+
packumentCache.set(packageName, null);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const json = (await response.json());
|
|
148
|
+
packumentCache.set(packageName, json);
|
|
149
|
+
return json;
|
|
150
|
+
}
|
|
151
|
+
function versionSatisfiesRange(version, rawRange) {
|
|
152
|
+
const range = rawRange.trim();
|
|
153
|
+
if (!range)
|
|
154
|
+
return false;
|
|
155
|
+
if (range === "*" || range === "latest")
|
|
156
|
+
return true;
|
|
157
|
+
const orParts = range.split("||").map(part => part.trim()).filter(Boolean);
|
|
158
|
+
return orParts.some(part => satisfiesAndRange(version, part));
|
|
159
|
+
}
|
|
160
|
+
function satisfiesAndRange(version, range) {
|
|
161
|
+
const normalized = normalizeRange(range);
|
|
162
|
+
if (!normalized)
|
|
163
|
+
return false;
|
|
164
|
+
const tokens = normalized.split(/\s+/).filter(Boolean);
|
|
165
|
+
return tokens.every(token => satisfiesComparator(version, token));
|
|
166
|
+
}
|
|
167
|
+
function normalizeRange(range) {
|
|
168
|
+
const trimmed = range.trim();
|
|
169
|
+
if (!trimmed)
|
|
170
|
+
return null;
|
|
171
|
+
if (looksLikeVersion(trimmed)) {
|
|
172
|
+
return `=${trimmed}`;
|
|
173
|
+
}
|
|
174
|
+
if (trimmed.startsWith("^")) {
|
|
175
|
+
const base = trimmed.slice(1);
|
|
176
|
+
if (!looksLikeVersion(base))
|
|
177
|
+
return null;
|
|
178
|
+
const [major, minor, patch] = parseCoreVersion(base);
|
|
179
|
+
if (major > 0)
|
|
180
|
+
return `>=${base} <${major + 1}.0.0`;
|
|
181
|
+
if (minor > 0)
|
|
182
|
+
return `>=${base} <0.${minor + 1}.0`;
|
|
183
|
+
return `>=${base} <0.0.${patch + 1}`;
|
|
184
|
+
}
|
|
185
|
+
if (trimmed.startsWith("~")) {
|
|
186
|
+
const base = trimmed.slice(1);
|
|
187
|
+
if (!looksLikeVersion(base))
|
|
188
|
+
return null;
|
|
189
|
+
const [major, minor] = parseCoreVersion(base);
|
|
190
|
+
return `>=${base} <${major}.${minor + 1}.0`;
|
|
191
|
+
}
|
|
192
|
+
return trimmed;
|
|
193
|
+
}
|
|
194
|
+
function satisfiesComparator(version, comparator) {
|
|
195
|
+
const token = comparator.trim();
|
|
196
|
+
if (!token)
|
|
197
|
+
return true;
|
|
198
|
+
const match = token.match(/^(<=|>=|<|>|=)?\s*([0-9]+\.[0-9]+\.[0-9]+(?:[-+][^\s]+)?)$/);
|
|
199
|
+
if (!match)
|
|
200
|
+
return false;
|
|
201
|
+
const operator = match[1] ?? "=";
|
|
202
|
+
const target = match[2];
|
|
203
|
+
const cmp = compareVersions(version, target);
|
|
204
|
+
switch (operator) {
|
|
205
|
+
case "<":
|
|
206
|
+
return cmp < 0;
|
|
207
|
+
case "<=":
|
|
208
|
+
return cmp <= 0;
|
|
209
|
+
case ">":
|
|
210
|
+
return cmp > 0;
|
|
211
|
+
case ">=":
|
|
212
|
+
return cmp >= 0;
|
|
213
|
+
case "=":
|
|
214
|
+
return cmp === 0;
|
|
215
|
+
default:
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function parseCoreVersion(version) {
|
|
220
|
+
const [major, minor, patch] = version
|
|
221
|
+
.split(".")
|
|
222
|
+
.map(part => Number(part.replace(/[^0-9].*$/, "")));
|
|
223
|
+
return [major || 0, minor || 0, patch || 0];
|
|
224
|
+
}
|
package/dist/scanner.js
CHANGED
|
@@ -4,6 +4,7 @@ import { loadCache, saveCache } from "./osv/cache.js";
|
|
|
4
4
|
import { maxSeverity } from "./osv/severity.js";
|
|
5
5
|
import { createSpinner } from "./output/spinner.js";
|
|
6
6
|
import { OsvAdvisorySource } from "./advisory/osv-advisory-source.js";
|
|
7
|
+
import { resolveRecommendedParentUpgrade } from "./remediation/parent-upgrade.js";
|
|
7
8
|
export function createAdvisorySource(options) {
|
|
8
9
|
return new OsvAdvisorySource(options?.osvUrl);
|
|
9
10
|
}
|
|
@@ -69,7 +70,7 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
69
70
|
if (!offline && idSet.size > 0) {
|
|
70
71
|
saveCache(cache, cacheDirOverride);
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
+
const findings = results.map(result => {
|
|
73
74
|
const vulnerabilities = result.vulnIds
|
|
74
75
|
.map(id => vulnMap.get(id))
|
|
75
76
|
.filter((v) => Boolean(v));
|
|
@@ -85,9 +86,21 @@ export async function scanPackages(packages, batchSize, options) {
|
|
|
85
86
|
cveAliases,
|
|
86
87
|
dependencyPaths,
|
|
87
88
|
relationship,
|
|
88
|
-
firstFixedVersion
|
|
89
|
+
firstFixedVersion,
|
|
90
|
+
recommendedParentUpgrade: undefined,
|
|
89
91
|
};
|
|
90
92
|
});
|
|
93
|
+
for (const finding of findings) {
|
|
94
|
+
if (finding.relationship !== "transitive" || offline)
|
|
95
|
+
continue;
|
|
96
|
+
try {
|
|
97
|
+
finding.recommendedParentUpgrade = await resolveRecommendedParentUpgrade(finding, packages);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
finding.recommendedParentUpgrade = undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return findings;
|
|
91
104
|
}
|
|
92
105
|
catch (error) {
|
|
93
106
|
spinner.fail("Scan failed");
|
|
@@ -125,7 +138,7 @@ export function buildCoverageNotes(scanInput, offline) {
|
|
|
125
138
|
"This MVP checks package versions against OSV advisories. It does not prove exploitability or runtime reachability.",
|
|
126
139
|
"Installed node_modules contents are not verified in this scan.",
|
|
127
140
|
"Container images, binaries, secrets, and IaC files are not scanned.",
|
|
128
|
-
"Monorepo workspace boundaries are only partially modeled in this version."
|
|
141
|
+
"Monorepo workspace boundaries are only partially modeled in this version.",
|
|
129
142
|
];
|
|
130
143
|
if (scanInput.mode === "manifest-fallback") {
|
|
131
144
|
notes.push("Manifest fallback is limited to direct dependencies pinned to exact versions. It does not resolve transitive dependencies from package.json alone.");
|