cve-lite-cli 1.9.0 โ 1.11.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 +132 -84
- package/dist/index.js +97 -13
- package/dist/output/formatters.js +29 -9
- package/dist/output/html-reporter.js +110 -17
- package/dist/output/printers.js +75 -24
- package/dist/parsers/npm-lock-graph.js +231 -0
- package/dist/parsers/utils.js +5 -1
- package/dist/remediation/fix-commands.js +104 -5
- package/dist/remediation/npm-transitive-graph.js +123 -0
- package/dist/remediation/npm-transitive-resolution.js +221 -0
- package/dist/remediation/parent-upgrade.js +25 -9
- package/dist/scanner.js +115 -10
- package/dist/utils/finding.js +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
**๐ Officially recognized as an [OWASP Incubator Project](https://owasp.org/cve-lite-cli)**
|
|
18
18
|
|
|
19
|
-
<p>
|
|
19
|
+
<p>Vulnerability scanning that belongs in your terminal โ not your CI pipeline.<br/>Scan your lockfile, get copy-and-run fix commands, and ship clean code.</p>
|
|
20
20
|
|
|
21
21
|
<strong>Scan. Understand. Fix.</strong>
|
|
22
22
|
|
|
@@ -45,6 +45,24 @@
|
|
|
45
45
|
|
|
46
46
|
---
|
|
47
47
|
|
|
48
|
+
## The problem with how security scanning works today
|
|
49
|
+
|
|
50
|
+
Most security tooling is designed around pipelines, not people.
|
|
51
|
+
|
|
52
|
+
Dependabot files PRs you'll get to eventually. CI scanners block merges hours after the fact. Security dashboards surface a list of CVE IDs with no clear path to resolving them. By the time a developer is looking at a scan result, the code has already been reviewed and is waiting to ship.
|
|
53
|
+
|
|
54
|
+
The feedback loop is too slow to be useful, and too noisy to be trusted. Developers learn to ignore it.
|
|
55
|
+
|
|
56
|
+
There is also a more fundamental problem: these tools tell you what is vulnerable. Very few tell you what to actually do about it. The result is a gap between detection and remediation that security teams paper over with manual triage, and developers experience as alert fatigue.
|
|
57
|
+
|
|
58
|
+
## A different model
|
|
59
|
+
|
|
60
|
+
CVE Lite CLI is built around a different idea: **vulnerability scanning belongs at the developer's terminal, not at the end of a pipeline.**
|
|
61
|
+
|
|
62
|
+
It reads your lockfile locally, queries [OSV](https://osv.dev) for advisory data, and produces a concrete remediation plan โ not a list of identifiers. You get copy-and-run `npm install`, `pnpm add`, `yarn add`, or `bun add` commands scoped to your package manager. You see exactly which packages are directly installed versus pulled in transitively. You can scan with no internet connection in restricted-network environments.
|
|
63
|
+
|
|
64
|
+
The tool is designed for the moment right before you push: fast, honest, and actionable.
|
|
65
|
+
|
|
48
66
|
## Quick start
|
|
49
67
|
|
|
50
68
|
```bash
|
|
@@ -58,39 +76,18 @@ Or one-off with `npx`:
|
|
|
58
76
|
npx cve-lite-cli /path/to/project
|
|
59
77
|
```
|
|
60
78
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
CVE Lite CLI scans JavaScript and TypeScript projects for known dependency vulnerabilities and tells you what to fix first. It reads your lockfile locally, queries [OSV](https://osv.dev) for advisory data, and produces a practical remediation plan โ not just a list of advisory IDs.
|
|
79
|
+
No account. No configuration. No source code leaves your machine.
|
|
64
80
|
|
|
65
|
-
|
|
81
|
+
## What it does
|
|
66
82
|
|
|
67
|
-
**
|
|
68
|
-
|
|
69
|
-
- **
|
|
70
|
-
- **
|
|
71
|
-
- **
|
|
72
|
-
- **
|
|
73
|
-
- **
|
|
74
|
-
- **
|
|
75
|
-
|
|
76
|
-
## How it compares
|
|
77
|
-
|
|
78
|
-
| Capability | CVE Lite CLI | npm audit | OSV-Scanner | Snyk CLI | Socket CLI |
|
|
79
|
-
|---|:---:|:---:|:---:|:---:|:---:|
|
|
80
|
-
| JS/TS lockfile scanning | โ
| โ
| โ
| โ
| โ
|
|
|
81
|
-
| npm + pnpm + Yarn + Bun support | โ
| โ | โ
| โ
| โ
|
|
|
82
|
-
| No account required | โ
| โ
| โ
| โ | โ |
|
|
83
|
-
| Free to use | โ
| โ
| โ
| โ | โ |
|
|
84
|
-
| Usage-aware reachability scanning | โ
| โ | โ | โ
| โ ๏ธ |
|
|
85
|
-
| Direct vs transitive visibility | โ
| โ ๏ธ | โ
| โ
| โ
|
|
|
86
|
-
| Copy-and-run fix commands | โ
| โ | โ | โ
| โ ๏ธ |
|
|
87
|
-
| Suggested remediation plan | โ
| โ | โ ๏ธ | โ
| โ ๏ธ |
|
|
88
|
-
| JSON output | โ
| โ
| โ
| โ
| โ
|
|
|
89
|
-
| Offline/local advisory DB | โ
| โ | โ ๏ธ | โ | โ |
|
|
90
|
-
|
|
91
|
-
<sub>โ
= built-in strength ยท โ ๏ธ = partial or workflow-dependent ยท โ = not a core strength</sub>
|
|
92
|
-
|
|
93
|
-
For detailed per-tool analysis, see [Comparison with other tools](docs/comparison.md).
|
|
83
|
+
- **Produces copy-and-run fix commands** โ every finding comes with a package-manager-aware install command you can run immediately
|
|
84
|
+
- **Distinguishes direct from transitive risk** โ shows whether the vulnerability is in something you installed or buried three levels deep in a dependency chain
|
|
85
|
+
- **Usage-aware reachability** โ optionally uses static analysis to detect whether vulnerable packages are actually imported in your code, cutting noise with `--usage` and `--only-used`
|
|
86
|
+
- **Offline advisory DB** โ sync advisory data ahead of time and scan with zero runtime API calls, designed for enterprise and air-gapped environments
|
|
87
|
+
- **Interactive HTML report** โ generate a self-contained dashboard with severity cards, a searchable findings table, and copy-ready fix commands (`--report`)
|
|
88
|
+
- **Auto-fix mode** โ apply validated direct dependency fixes and rescan automatically (`--fix`)
|
|
89
|
+
- **CI-ready** โ `--fail-on high` exits non-zero on findings at or above a severity threshold; a first-party [GitHub Action](https://github.com/marketplace/actions/cve-lite-cli) is available on the Marketplace
|
|
90
|
+
- **Minimal footprint** โ four runtime dependencies, intentionally kept small for a security tool
|
|
94
91
|
|
|
95
92
|
## What it looks like
|
|
96
93
|
|
|
@@ -126,16 +123,97 @@ For detailed per-tool analysis, see [Comparison with other tools](docs/compariso
|
|
|
126
123
|
</p>
|
|
127
124
|
</details>
|
|
128
125
|
|
|
129
|
-
##
|
|
126
|
+
## Workflow integration
|
|
130
127
|
|
|
131
|
-
|
|
128
|
+
CVE Lite CLI fits at every stage of the development workflow, not just CI.
|
|
132
129
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
**Local development** โ run a scan before opening a PR. The default output is fast and minimal. `--verbose` adds the full fix plan with dependency paths and prioritized remediation commands. `--report` opens an interactive HTML dashboard.
|
|
131
|
+
|
|
132
|
+
**CI pipelines** โ use `--fail-on high` to gate builds on severity. JSON output (`--json`) integrates with SIEM, dashboards, and custom automation. SARIF output is on the roadmap for direct integration with GitHub Security.
|
|
133
|
+
|
|
134
|
+
**Restricted and enterprise environments** โ sync the advisory database ahead of time with `cve-lite advisories sync`, then scan offline with `--offline`. No runtime outbound calls during the scan. Syncing ~217,065 advisory records completes in under 9 seconds.
|
|
135
|
+
|
|
136
|
+
**GitHub Actions** โ a first-party action is available on the Marketplace:
|
|
137
|
+
|
|
138
|
+
```yaml
|
|
139
|
+
- uses: OWASP/cve-lite-cli@v1
|
|
140
|
+
with:
|
|
141
|
+
verbose: "true"
|
|
142
|
+
fail-on: high
|
|
136
143
|
```
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
CVE Lite CLI scans its own dependencies in CI. See [`self-scan.yml`](https://github.com/OWASP/cve-lite-cli/blob/main/.github/workflows/self-scan.yml).
|
|
146
|
+
|
|
147
|
+
For full CI patterns including offline workflows, git hooks, and scripted automation, see the [CI and Workflow Integration guide](docs/ci-integration.md).
|
|
148
|
+
|
|
149
|
+
## How it compares
|
|
150
|
+
|
|
151
|
+
| Capability | CVE Lite CLI | npm audit | OSV-Scanner | Snyk CLI | Socket CLI |
|
|
152
|
+
|---|:---:|:---:|:---:|:---:|:---:|
|
|
153
|
+
| JS/TS lockfile scanning | โ
| โ
| โ
| โ
| โ
|
|
|
154
|
+
| npm + pnpm + Yarn + Bun support | โ
| โ | โ
| โ
| โ
|
|
|
155
|
+
| No account required | โ
| โ
| โ
| โ | โ |
|
|
156
|
+
| Free to use | โ
| โ
| โ
| โ | โ |
|
|
157
|
+
| Usage-aware reachability scanning | โ
| โ | โ | โ
| โ ๏ธ |
|
|
158
|
+
| Direct vs transitive visibility | โ
| โ ๏ธ | โ
| โ
| โ
|
|
|
159
|
+
| Copy-and-run fix commands | โ
| โ | โ | โ
| โ ๏ธ |
|
|
160
|
+
| Suggested remediation plan | โ
| โ | โ ๏ธ | โ
| โ ๏ธ |
|
|
161
|
+
| JSON output | โ
| โ
| โ
| โ
| โ
|
|
|
162
|
+
| Offline/local advisory DB | โ
| โ | โ ๏ธ | โ | โ |
|
|
163
|
+
|
|
164
|
+
<sub>โ
= built-in strength ยท โ ๏ธ = partial or workflow-dependent ยท โ = not a core strength</sub>
|
|
165
|
+
|
|
166
|
+
For detailed per-tool analysis, see [Comparison with other tools](docs/comparison.md).
|
|
167
|
+
|
|
168
|
+
## Real-world validation
|
|
169
|
+
|
|
170
|
+
CVE Lite CLI has been evaluated against real open-source projects to verify that it surfaces meaningful issues โ including non-obvious transitive vulnerabilities and complex upgrade paths โ not just low-signal advisory matches.
|
|
171
|
+
|
|
172
|
+
- [OWASP Juice Shop](docs/case-studies/owasp-juice-shop.md) โ scanning a deliberately vulnerable application with known dependency issues
|
|
173
|
+
- [NestJS](docs/case-studies/nestjs.md) โ working through a real transitive dependency remediation sequence across a widely-used Node.js framework
|
|
174
|
+
- [Analog](docs/case-studies/analog.md) โ scanning a modern pnpm v9 Angular monorepo (3,367 packages) with unexpected toolchain vulnerabilities
|
|
175
|
+
|
|
176
|
+
These are not demos. They are documented scans against real codebases with real findings, recorded before and after applying fix commands.
|
|
177
|
+
|
|
178
|
+
If you maintain an open-source JavaScript or TypeScript project and want CVE Lite CLI evaluated on it, open an issue and share the repository. Strong candidates may be turned into future public case studies.
|
|
179
|
+
|
|
180
|
+
## Recognized by OWASP
|
|
181
|
+
|
|
182
|
+
CVE Lite CLI is an [OWASP Incubator Project](https://owasp.org/cve-lite-cli), peer-reviewed and maintained under the Open Web Application Security Project Foundation. Being part of OWASP means:
|
|
183
|
+
|
|
184
|
+
- **Peer-reviewed** by security professionals
|
|
185
|
+
- **Community-driven** development and governance
|
|
186
|
+
- **Vendor-neutral** with no commercial platform required
|
|
187
|
+
- **Open source** with transparent security practices and a minimal dependency footprint
|
|
188
|
+
|
|
189
|
+
**Where it fits in the OWASP ecosystem:**
|
|
190
|
+
|
|
191
|
+
CVE Lite CLI fills a specific gap โ fast, local-first JS/TS dependency scanning close to release time โ that broader OWASP tools are not optimized for:
|
|
192
|
+
|
|
193
|
+
| Tool | Focus |
|
|
194
|
+
|---|---|
|
|
195
|
+
| CVE Lite CLI | Lockfile-first, local developer CLI, remediation-focused, JS/TS |
|
|
196
|
+
| OWASP Dependency-Check | Multi-language, SAST-style, broader ecosystem |
|
|
197
|
+
| OWASP dep-scan | Multi-language and environment, SBOM and cloud-native |
|
|
198
|
+
| OWASP Dependency-Track | Platform and SBOM management, not a local CLI |
|
|
199
|
+
|
|
200
|
+
CVE Lite CLI complements these tools. It is not a replacement for continuous monitoring or full SBOM management โ it is the fast local check you run before pushing.
|
|
201
|
+
|
|
202
|
+
## Philosophy
|
|
203
|
+
|
|
204
|
+
Security tooling has optimized heavily for breadth of detection and compliance reporting. That is useful at the platform level. It is the wrong model for the individual developer trying to ship clean code before end of day.
|
|
205
|
+
|
|
206
|
+
Detection without remediation creates work without resolution. A vulnerability report that ends with a list of CVE IDs shifts the burden entirely onto the developer: look up each advisory, figure out which version is safe, work out whether it is a direct or transitive dependency, and construct the right install command by hand. That friction is why security findings go unresolved.
|
|
207
|
+
|
|
208
|
+
CVE Lite CLI is built on the premise that **the closer a security tool is to the developer's natural workflow, the more likely it is to be used** โ and that a tool that surfaces a problem alongside the fix is more valuable than one that only surfaces the problem.
|
|
209
|
+
|
|
210
|
+
## What's next
|
|
211
|
+
|
|
212
|
+
The CLI is the foundation. The model โ local-first, actionable, developer-native โ extends naturally beyond the terminal.
|
|
213
|
+
|
|
214
|
+
JSON and SARIF outputs make findings consumable by editors, dashboards, and automated workflows today. The next phase of the project is oriented around tighter developer integration: surfacing vulnerabilities at the point of dependency installation, not just at scan time; deeper IDE integration; and team-level visibility without requiring a cloud platform.
|
|
215
|
+
|
|
216
|
+
See [roadmap.md](docs/roadmap.md) for the current plan.
|
|
139
217
|
|
|
140
218
|
## Usage
|
|
141
219
|
|
|
@@ -192,7 +270,7 @@ cve-lite --version
|
|
|
192
270
|
|
|
193
271
|
### Why is `--usage` an opt-in flag?
|
|
194
272
|
|
|
195
|
-
CVE Lite CLI is designed to be
|
|
273
|
+
CVE Lite CLI is designed to be fast. Scanning a lockfile is nearly instantaneous, whereas running static reachability analysis across thousands of source files takes significantly more time. Static analysis can also produce false negatives when packages are used in build scripts or dynamically imported at runtime. Making `--usage` opt-in ensures the default lockfile scan remains instant and strictly reflects your dependency graph, while giving you the option to aggressively filter out unreachable noise when triaging findings.
|
|
196
274
|
|
|
197
275
|
## Auto-fix mode (`--fix`)
|
|
198
276
|
|
|
@@ -210,6 +288,17 @@ npx cve-lite-cli /path/to/project --fix
|
|
|
210
288
|
|
|
211
289
|
See the [Fix mode guide](docs/fix-mode.md) for output details and interpretation.
|
|
212
290
|
|
|
291
|
+
## HTML vulnerability report (`--report`)
|
|
292
|
+
|
|
293
|
+
Generate a self-contained HTML dashboard from any scan โ severity cards, an interactive findings table with search, copy-ready fix commands, and breaking-change indicators on upgrades โ all written to a local directory and opened automatically in your browser.
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
cve-lite /path/to/project --report
|
|
297
|
+
cve-lite /path/to/project --report ./my-report --no-open
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
See the [HTML Report guide](docs/html-report.md) for the full option reference and output details.
|
|
301
|
+
|
|
213
302
|
## Offline support
|
|
214
303
|
|
|
215
304
|
For teams in enterprise, restricted-network, or air-gapped environments:
|
|
@@ -226,51 +315,6 @@ Syncing ~217,065 advisory records runs in under 9 seconds after bulk SQLite inge
|
|
|
226
315
|
|
|
227
316
|
See the [Offline Advisory DB guide](docs/offline-advisory-db.md) for the full workflow including CI, scheduled refresh, and controlled-network patterns.
|
|
228
317
|
|
|
229
|
-
## CI integration
|
|
230
|
-
|
|
231
|
-
The project ships a first-party [GitHub Action on the Marketplace](https://github.com/marketplace/actions/cve-lite-cli):
|
|
232
|
-
|
|
233
|
-
```yaml
|
|
234
|
-
- uses: OWASP/cve-lite-cli@v1
|
|
235
|
-
with:
|
|
236
|
-
verbose: "true"
|
|
237
|
-
fail-on: high
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
CVE Lite CLI also uses itself in CI to scan its own dependencies. See [`self-scan.yml`](https://github.com/OWASP/cve-lite-cli/blob/main/.github/workflows/self-scan.yml).
|
|
241
|
-
|
|
242
|
-
For full CI patterns including offline workflows, git hooks, and scripted automation, see the [CI and Workflow Integration guide](docs/ci-integration.md).
|
|
243
|
-
|
|
244
|
-
## Recognized by OWASP
|
|
245
|
-
|
|
246
|
-
CVE Lite CLI is an [OWASP Incubator Project](https://owasp.org/cve-lite-cli), peer-reviewed and maintained under the Open Web Application Security Project Foundation. Being part of OWASP means:
|
|
247
|
-
|
|
248
|
-
- **Peer-reviewed** by security professionals
|
|
249
|
-
- **Community-driven** development and governance
|
|
250
|
-
- **Vendor-neutral** with no commercial platform required
|
|
251
|
-
- **Open source** with transparent security practices and a minimal dependency footprint
|
|
252
|
-
|
|
253
|
-
**Where it fits in the OWASP ecosystem:**
|
|
254
|
-
|
|
255
|
-
CVE Lite CLI fills a specific gap โ fast, local-first JS/TS dependency scanning close to release time โ that broader OWASP tools are not optimized for:
|
|
256
|
-
|
|
257
|
-
| Tool | Focus |
|
|
258
|
-
|---|---|
|
|
259
|
-
| CVE Lite CLI | Lockfile-first, local developer CLI, remediation-focused, JS/TS |
|
|
260
|
-
| OWASP Dependency-Check | Multi-language, SAST-style, broader ecosystem |
|
|
261
|
-
| OWASP dep-scan | Multi-language and environment, SBOM and cloud-native |
|
|
262
|
-
| OWASP Dependency-Track | Platform and SBOM management, not a local CLI |
|
|
263
|
-
|
|
264
|
-
CVE Lite CLI complements these tools. It is not a replacement for continuous monitoring or full SBOM management โ it is the fast local check you run before pushing.
|
|
265
|
-
|
|
266
|
-
## Real-world case studies
|
|
267
|
-
|
|
268
|
-
- [OWASP Juice Shop](docs/case-studies/owasp-juice-shop.md) โ scanning a deliberately vulnerable application with known dependency issues
|
|
269
|
-
- [NestJS](docs/case-studies/nestjs.md) โ working through a real transitive dependency remediation sequence
|
|
270
|
-
- [Analog](docs/case-studies/analog.md) โ scanning a modern pnpm v9 Angular monorepo (3,367 packages) with unexpected toolchain vulnerabilities
|
|
271
|
-
|
|
272
|
-
If you maintain an open-source JavaScript or TypeScript project and want CVE Lite CLI evaluated on it, open an issue and share the repository. Strong candidates may be turned into future public case studies.
|
|
273
|
-
|
|
274
318
|
## Who uses it
|
|
275
319
|
|
|
276
320
|
CVE Lite CLI is a good fit for:
|
|
@@ -339,6 +383,10 @@ For security-related reporting: [SECURITY.md](https://github.com/OWASP/cve-lite-
|
|
|
339
383
|
|
|
340
384
|
If CVE Lite CLI helps your release workflow, a [GitHub star](https://github.com/OWASP/cve-lite-cli) helps more developers find it.
|
|
341
385
|
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
*Most tools tell you what's wrong. CVE Lite CLI tells you what to run.*
|
|
389
|
+
|
|
342
390
|
## License
|
|
343
391
|
|
|
344
392
|
MIT
|
package/dist/index.js
CHANGED
|
@@ -270,7 +270,11 @@ function formatAdvisorySourceLine(sourceLabel) {
|
|
|
270
270
|
}
|
|
271
271
|
async function scanProject(params) {
|
|
272
272
|
const directDependencyNames = readDirectDependencyNames(params.projectPath, !!params.options.prodOnly);
|
|
273
|
-
const findings = await scanPackages(params.scanInput.packages, params.batchSize, params.options, {
|
|
273
|
+
const findings = await scanPackages(params.scanInput.packages, params.batchSize, params.options, {
|
|
274
|
+
directDependencyNames,
|
|
275
|
+
scanSource: params.scanInput.source,
|
|
276
|
+
scanFilePath: params.scanInput.filePath,
|
|
277
|
+
});
|
|
274
278
|
if (params.options.usage) {
|
|
275
279
|
console.log(chalk.gray(`Scanning project source for usage hints...`));
|
|
276
280
|
const pkgNames = new Set(findings.map(f => f.pkg.name));
|
|
@@ -446,21 +450,18 @@ function readDirectDependencyNames(projectPath, prodOnly) {
|
|
|
446
450
|
return null;
|
|
447
451
|
}
|
|
448
452
|
try {
|
|
449
|
-
const raw = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
450
453
|
const directNames = new Set();
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
];
|
|
455
|
-
if (!prodOnly) {
|
|
456
|
-
sections.push(raw?.devDependencies);
|
|
454
|
+
const rootManifest = readPackageJsonObject(packageJsonPath);
|
|
455
|
+
if (!rootManifest) {
|
|
456
|
+
return null;
|
|
457
457
|
}
|
|
458
|
-
|
|
459
|
-
|
|
458
|
+
addDependencyNamesFromManifest(directNames, rootManifest, prodOnly);
|
|
459
|
+
const workspacePatterns = readWorkspacePatterns(rootManifest);
|
|
460
|
+
for (const workspacePackageJsonPath of resolveWorkspacePackageJsonPaths(projectPath, workspacePatterns)) {
|
|
461
|
+
const workspaceManifest = readPackageJsonObject(workspacePackageJsonPath);
|
|
462
|
+
if (!workspaceManifest)
|
|
460
463
|
continue;
|
|
461
|
-
|
|
462
|
-
directNames.add(name);
|
|
463
|
-
}
|
|
464
|
+
addDependencyNamesFromManifest(directNames, workspaceManifest, prodOnly);
|
|
464
465
|
}
|
|
465
466
|
return directNames;
|
|
466
467
|
}
|
|
@@ -468,6 +469,89 @@ function readDirectDependencyNames(projectPath, prodOnly) {
|
|
|
468
469
|
return null;
|
|
469
470
|
}
|
|
470
471
|
}
|
|
472
|
+
function readPackageJsonObject(filePath) {
|
|
473
|
+
try {
|
|
474
|
+
const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
475
|
+
return raw && typeof raw === "object" ? raw : null;
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function addDependencyNamesFromManifest(target, manifest, prodOnly) {
|
|
482
|
+
const sections = [
|
|
483
|
+
isRecord(manifest.dependencies) ? manifest.dependencies : undefined,
|
|
484
|
+
isRecord(manifest.optionalDependencies) ? manifest.optionalDependencies : undefined,
|
|
485
|
+
];
|
|
486
|
+
if (!prodOnly) {
|
|
487
|
+
sections.push(isRecord(manifest.devDependencies) ? manifest.devDependencies : undefined);
|
|
488
|
+
}
|
|
489
|
+
for (const section of sections) {
|
|
490
|
+
if (!section)
|
|
491
|
+
continue;
|
|
492
|
+
for (const name of Object.keys(section)) {
|
|
493
|
+
target.add(name);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function readWorkspacePatterns(manifest) {
|
|
498
|
+
const workspaces = manifest.workspaces;
|
|
499
|
+
if (Array.isArray(workspaces)) {
|
|
500
|
+
return workspaces.filter((value) => typeof value === "string");
|
|
501
|
+
}
|
|
502
|
+
if (isRecord(workspaces) && Array.isArray(workspaces.packages)) {
|
|
503
|
+
return workspaces.packages.filter((value) => typeof value === "string");
|
|
504
|
+
}
|
|
505
|
+
return [];
|
|
506
|
+
}
|
|
507
|
+
function resolveWorkspacePackageJsonPaths(projectPath, patterns) {
|
|
508
|
+
const matches = new Set();
|
|
509
|
+
for (const pattern of patterns) {
|
|
510
|
+
const normalized = pattern.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
511
|
+
if (!normalized)
|
|
512
|
+
continue;
|
|
513
|
+
for (const relativeDir of expandWorkspacePattern(projectPath, normalized.split("/").filter(Boolean), "")) {
|
|
514
|
+
const packageJsonPath = path.join(projectPath, relativeDir, "package.json");
|
|
515
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
516
|
+
matches.add(packageJsonPath);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return [...matches];
|
|
521
|
+
}
|
|
522
|
+
function expandWorkspacePattern(projectPath, segments, currentRelativePath) {
|
|
523
|
+
if (segments.length === 0) {
|
|
524
|
+
return currentRelativePath ? [currentRelativePath] : [];
|
|
525
|
+
}
|
|
526
|
+
const [segment, ...rest] = segments;
|
|
527
|
+
if (segment === "*") {
|
|
528
|
+
const baseDir = currentRelativePath ? path.join(projectPath, currentRelativePath) : projectPath;
|
|
529
|
+
let entries = [];
|
|
530
|
+
try {
|
|
531
|
+
entries = fs.readdirSync(baseDir, { withFileTypes: true });
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
return [];
|
|
535
|
+
}
|
|
536
|
+
return entries
|
|
537
|
+
.filter(entry => entry.isDirectory())
|
|
538
|
+
.flatMap(entry => {
|
|
539
|
+
const nextRelativePath = currentRelativePath
|
|
540
|
+
? path.join(currentRelativePath, entry.name)
|
|
541
|
+
: entry.name;
|
|
542
|
+
return expandWorkspacePattern(projectPath, rest, nextRelativePath);
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
const nextRelativePath = currentRelativePath ? path.join(currentRelativePath, segment) : segment;
|
|
546
|
+
const nextAbsolutePath = path.join(projectPath, nextRelativePath);
|
|
547
|
+
if (!fs.existsSync(nextAbsolutePath) || !fs.statSync(nextAbsolutePath).isDirectory()) {
|
|
548
|
+
return [];
|
|
549
|
+
}
|
|
550
|
+
return expandWorkspacePattern(projectPath, rest, nextRelativePath);
|
|
551
|
+
}
|
|
552
|
+
function isRecord(value) {
|
|
553
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
554
|
+
}
|
|
471
555
|
function formatAdvisoryDbFreshness(lastSyncAt) {
|
|
472
556
|
if (!lastSyncAt) {
|
|
473
557
|
return chalk.yellow("unknown");
|
|
@@ -2,6 +2,7 @@ import { chalk } from "../utils/chalk.js";
|
|
|
2
2
|
import { severityOrder } from "../constants.js";
|
|
3
3
|
import { loadCache } from "../osv/cache.js";
|
|
4
4
|
import { inferSeverity } from "../osv/severity.js";
|
|
5
|
+
import { getPrimaryParent } from "../utils/finding.js";
|
|
5
6
|
export function formatSeverityLabel(severity) {
|
|
6
7
|
const lower = severity.toLowerCase();
|
|
7
8
|
if (lower === "critical")
|
|
@@ -23,12 +24,6 @@ export function formatRelationshipLabel(value) {
|
|
|
23
24
|
return chalk.yellow(value);
|
|
24
25
|
return chalk.gray(value);
|
|
25
26
|
}
|
|
26
|
-
export function getPrimaryParent(finding) {
|
|
27
|
-
const firstPath = finding.dependencyPaths?.[0];
|
|
28
|
-
if (!firstPath || firstPath.length < 3)
|
|
29
|
-
return null;
|
|
30
|
-
return firstPath[1] ?? null;
|
|
31
|
-
}
|
|
32
27
|
export function getRecommendedAction(finding) {
|
|
33
28
|
if (finding.relationship === "direct" && finding.firstFixedVersion) {
|
|
34
29
|
return `Upgrade ${finding.pkg.name} to ${finding.firstFixedVersion}+ in this project.`;
|
|
@@ -36,18 +31,25 @@ export function getRecommendedAction(finding) {
|
|
|
36
31
|
if (finding.relationship === "direct") {
|
|
37
32
|
return `Review and upgrade ${finding.pkg.name} directly in this project.`;
|
|
38
33
|
}
|
|
34
|
+
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
35
|
+
return `Update ${finding.recommendedNpmTransitiveRemediation.package} within its current dependency range to pull in vulnerable ${finding.pkg.name}@${finding.recommendedNpmTransitiveRemediation.targetChildVersion}.`;
|
|
36
|
+
}
|
|
37
|
+
if (finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version" &&
|
|
38
|
+
finding.recommendedNpmTransitiveRemediation.targetVersion) {
|
|
39
|
+
return `Upgrade ${finding.recommendedNpmTransitiveRemediation.package} from ${finding.recommendedNpmTransitiveRemediation.currentVersion} to ${finding.recommendedNpmTransitiveRemediation.targetVersion} to stop pulling in vulnerable ${finding.pkg.name}.`;
|
|
40
|
+
}
|
|
39
41
|
if (finding.recommendedParentUpgrade) {
|
|
40
42
|
return `Upgrade ${finding.recommendedParentUpgrade.package} from ${finding.recommendedParentUpgrade.currentVersion} to ${finding.recommendedParentUpgrade.targetVersion} to stop pulling in vulnerable ${finding.pkg.name}.`;
|
|
41
43
|
}
|
|
42
44
|
const parent = getPrimaryParent(finding);
|
|
43
45
|
if (parent && finding.firstFixedVersion) {
|
|
44
|
-
return `
|
|
46
|
+
return `Upgrade ${parent} โ no safe version was identified automatically. Check for a release that resolves ${finding.pkg.name} to ${finding.firstFixedVersion}+.`;
|
|
45
47
|
}
|
|
46
48
|
if (parent) {
|
|
47
49
|
return `Review ${parent}; it currently pulls in vulnerable ${finding.pkg.name}.`;
|
|
48
50
|
}
|
|
49
51
|
if (finding.firstFixedVersion) {
|
|
50
|
-
return `
|
|
52
|
+
return `No dependency path found for ${finding.pkg.name}. Inspect your lockfile to identify which package pulls it in.`;
|
|
51
53
|
}
|
|
52
54
|
return `Inspect the dependency path for ${finding.pkg.name} and choose the safest upgrade path.`;
|
|
53
55
|
}
|
|
@@ -59,6 +61,12 @@ export function summarizeRisk(finding) {
|
|
|
59
61
|
else if (finding.severity === "high" && finding.relationship === "direct") {
|
|
60
62
|
risk = "High-severity direct dependency. A direct upgrade is likely the fastest path.";
|
|
61
63
|
}
|
|
64
|
+
else if (finding.relationship === "transitive" && finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
65
|
+
risk = `Transitive issue. The current parent range can already absorb a safe ${finding.pkg.name} update via ${finding.recommendedNpmTransitiveRemediation.package}.`;
|
|
66
|
+
}
|
|
67
|
+
else if (finding.relationship === "transitive" && finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version") {
|
|
68
|
+
risk = `Transitive issue. A specific parent upgrade target was found for ${finding.recommendedNpmTransitiveRemediation.package}.`;
|
|
69
|
+
}
|
|
62
70
|
else if (finding.relationship === "transitive" && finding.recommendedParentUpgrade) {
|
|
63
71
|
risk = `Transitive issue. A specific parent upgrade target was found for ${finding.recommendedParentUpgrade.package}.`;
|
|
64
72
|
}
|
|
@@ -91,11 +99,22 @@ export function summarizeNextAction(finding) {
|
|
|
91
99
|
if (finding.relationship === "direct") {
|
|
92
100
|
return `Review and upgrade ${finding.pkg.name} directly in this project.`;
|
|
93
101
|
}
|
|
102
|
+
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
103
|
+
return `Update ${finding.recommendedNpmTransitiveRemediation.package} within its current dependency range.`;
|
|
104
|
+
}
|
|
105
|
+
if (finding.recommendedNpmTransitiveRemediation?.kind === "upgrade-parent-to-version" &&
|
|
106
|
+
finding.recommendedNpmTransitiveRemediation.targetVersion) {
|
|
107
|
+
return `Upgrade ${finding.recommendedNpmTransitiveRemediation.package} ${finding.recommendedNpmTransitiveRemediation.currentVersion} -> ${finding.recommendedNpmTransitiveRemediation.targetVersion}.`;
|
|
108
|
+
}
|
|
94
109
|
if (finding.recommendedParentUpgrade) {
|
|
95
110
|
return `Upgrade ${finding.recommendedParentUpgrade.package} ${finding.recommendedParentUpgrade.currentVersion} -> ${finding.recommendedParentUpgrade.targetVersion}.`;
|
|
96
111
|
}
|
|
112
|
+
const parent = getPrimaryParent(finding);
|
|
113
|
+
if (parent && finding.firstFixedVersion) {
|
|
114
|
+
return `Upgrade ${parent} โ no safe version identified. Find a release resolving ${finding.pkg.name} to ${finding.firstFixedVersion}+.`;
|
|
115
|
+
}
|
|
97
116
|
if (finding.firstFixedVersion) {
|
|
98
|
-
return `
|
|
117
|
+
return `No dependency path found for ${finding.pkg.name}. Check your lockfile for which package pulls it in.`;
|
|
99
118
|
}
|
|
100
119
|
return `Inspect the parent dependency chain for ${finding.pkg.name} and choose the safest available upgrade.`;
|
|
101
120
|
}
|
|
@@ -113,6 +132,7 @@ export function serializeFinding(finding) {
|
|
|
113
132
|
recommendedAction: getRecommendedAction(finding),
|
|
114
133
|
primaryParent: getPrimaryParent(finding),
|
|
115
134
|
recommendedParentUpgrade: finding.recommendedParentUpgrade,
|
|
135
|
+
recommendedNpmTransitiveRemediation: finding.recommendedNpmTransitiveRemediation ?? null,
|
|
116
136
|
cves: finding.cveAliases,
|
|
117
137
|
dependencyPaths: finding.dependencyPaths,
|
|
118
138
|
usage: finding.usage ?? null,
|