cve-lite-cli 1.20.0 → 1.22.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 +6 -2
- package/dist/cli/args.js +4 -0
- package/dist/cli/help.js +1 -0
- package/dist/index.js +32 -4
- package/dist/output/formatters.js +5 -0
- package/dist/output/html-reporter.js +8 -1
- package/dist/output/printers.js +4 -4
- package/dist/parsers/bun-lock.js +2 -0
- package/dist/parsers/pnpm-lock.js +19 -3
- package/dist/parsers/utils.js +15 -0
- package/dist/parsers/yarn-lock.js +9 -6
- package/dist/utils/baseline.js +58 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -173,7 +173,7 @@ CVE Lite CLI fits at every stage of the development workflow, not just CI.
|
|
|
173
173
|
|
|
174
174
|
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).
|
|
175
175
|
|
|
176
|
-
For full CI patterns including offline workflows, git hooks, and scripted automation, see the [CI and Workflow Integration guide](https://owasp.org/cve-lite-cli/docs/
|
|
176
|
+
For full CI patterns including offline workflows, git hooks, and scripted automation, see the [CI and Workflow Integration guide](https://owasp.org/cve-lite-cli/docs/workflow-integration).
|
|
177
177
|
|
|
178
178
|
## How it compares
|
|
179
179
|
|
|
@@ -187,9 +187,13 @@ No other free tool combines all of the following: lockfile scanning across npm,
|
|
|
187
187
|
| Free to use | ✅ | ✅ | ✅ | ❌ | ❌ |
|
|
188
188
|
| Usage-aware reachability scanning | ✅ | ❌ | ❌ | ✅ | ⚠️ |
|
|
189
189
|
| Direct vs transitive visibility | ✅ | ⚠️ | ✅ | ✅ | ✅ |
|
|
190
|
+
| Dev vs runtime dependency labelling | ✅ | ⚠️ | ❌ | ⚠️ | ❌ |
|
|
190
191
|
| Copy-and-run fix commands | ✅ | ❌ | ❌ | ✅ | ⚠️ |
|
|
191
192
|
| Transitive parent update guidance | ✅ | ❌ | ⚠️ | ⚠️ | ⚠️ |
|
|
192
193
|
| Suggested remediation plan | ✅ | ❌ | ⚠️ | ✅ | ⚠️ |
|
|
194
|
+
| Ratcheting mode (baseline suppression) | ✅ | ❌ | ❌ | ⚠️ | ❌ |
|
|
195
|
+
| Interactive HTML report | ✅ | ❌ | ❌ | ✅ | ❌ |
|
|
196
|
+
| SARIF / GitHub Code Scanning output | ✅ | ❌ | ✅ | ✅ | ❌ |
|
|
193
197
|
| JSON output | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
194
198
|
| Offline/local advisory DB | ✅ | ❌ | ⚠️ | ❌ | ❌ |
|
|
195
199
|
|
|
@@ -428,7 +432,7 @@ It is a good fit for:
|
|
|
428
432
|
- **Enterprise teams with restricted networks** — offline advisory DB removes the need for runtime outbound calls during scans
|
|
429
433
|
- **Teams running npm, pnpm, Yarn, and Bun** — unified scanning across all four package managers in one tool
|
|
430
434
|
|
|
431
|
-
See the [CI and Workflow Integration guide](https://owasp.org/cve-lite-cli/docs/
|
|
435
|
+
See the [CI and Workflow Integration guide](https://owasp.org/cve-lite-cli/docs/workflow-integration) for concrete patterns across these scenarios.
|
|
432
436
|
|
|
433
437
|
Using CVE Lite CLI at your company or in your projects? [Share your use case in the community thread](https://github.com/OWASP/cve-lite-cli/discussions/481) - we'd love to hear about it.
|
|
434
438
|
|
package/dist/cli/args.js
CHANGED
package/dist/cli/help.js
CHANGED
|
@@ -34,6 +34,7 @@ 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
|
+
" --ratchet Save current findings as baseline or, if baseline exists, only fail on new findings",
|
|
37
38
|
" --create-pr After --fix, commit changes and open a GitHub pull request (requires gh)",
|
|
38
39
|
" --base <branch> Base branch for --create-pr (default: main)",
|
|
39
40
|
" --osv-url <url> Use a custom OSV-compatible advisory endpoint",
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ import { applyFixesIfRequested, printFixModeSummary, } from "./utils/fix-runner.
|
|
|
32
32
|
import { hasRootLockfile, findNestedLockfiles } from "./parsers/multi-package.js";
|
|
33
33
|
import { handleMultiFolderScan } from "./scan/multi-folder-scan.js";
|
|
34
34
|
import { createPullRequestForFixes, } from "./utils/create-pr.js";
|
|
35
|
+
import { readBaseline, writeBaseline, filterNewFindings } from "./utils/baseline.js";
|
|
35
36
|
let parsedArgs = null;
|
|
36
37
|
try {
|
|
37
38
|
parsedArgs = parseArgs(process.argv.slice(2));
|
|
@@ -177,7 +178,7 @@ if (parsedArgs) {
|
|
|
177
178
|
}
|
|
178
179
|
throw error;
|
|
179
180
|
}
|
|
180
|
-
if (!options.json) {
|
|
181
|
+
if (!options.json && !options.ratchet) {
|
|
181
182
|
if (options.offline || options.offlineDb) {
|
|
182
183
|
console.log(chalk.gray("Offline mode:") + " " + chalk.yellow("enabled") + " " + chalk.gray("(no external advisory calls will be made)"));
|
|
183
184
|
}
|
|
@@ -203,8 +204,10 @@ if (parsedArgs) {
|
|
|
203
204
|
count: packages.length,
|
|
204
205
|
source: scanInput.source,
|
|
205
206
|
});
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
if (!options.ratchet) {
|
|
208
|
+
logInfo(`Parsed ${packages.length} ${pluralize(packages.length, "package")} from ${scanInput.source}${scanInput.filePath ? ` (${path.relative(projectPath, scanInput.filePath) || path.basename(scanInput.filePath)})` : ""}`, options);
|
|
209
|
+
printCacheSummary(options.cacheDir, options);
|
|
210
|
+
}
|
|
208
211
|
if (scanInput.warnings.length > 0) {
|
|
209
212
|
for (const warning of scanInput.warnings) {
|
|
210
213
|
logWarn(warning, options);
|
|
@@ -216,7 +219,7 @@ if (parsedArgs) {
|
|
|
216
219
|
process.exit(0);
|
|
217
220
|
return;
|
|
218
221
|
}
|
|
219
|
-
if (!options.json)
|
|
222
|
+
if (!options.json && !options.ratchet)
|
|
220
223
|
console.log();
|
|
221
224
|
let scanState = await scanProject({
|
|
222
225
|
scanInput,
|
|
@@ -228,6 +231,8 @@ if (parsedArgs) {
|
|
|
228
231
|
const findingsBeforeFixList = scanState.sorted;
|
|
229
232
|
const findingsBeforeFix = findingsBeforeFixList.length;
|
|
230
233
|
let fixResult = null;
|
|
234
|
+
let baseline = readBaseline(projectArg ?? ".");
|
|
235
|
+
let suppressedCount = 0;
|
|
231
236
|
if (options.fix) {
|
|
232
237
|
fixResult = await applyFixesIfRequested({
|
|
233
238
|
plan: scanState.suggestedFixCommands,
|
|
@@ -290,6 +295,21 @@ if (parsedArgs) {
|
|
|
290
295
|
}
|
|
291
296
|
}
|
|
292
297
|
else {
|
|
298
|
+
// --ratchet: save baseline and exit 0
|
|
299
|
+
if (options.ratchet) {
|
|
300
|
+
writeBaseline(projectArg ?? ".", scanState.sorted);
|
|
301
|
+
const count = scanState.sorted.length;
|
|
302
|
+
console.log(chalk.green(`✓ Baseline saved to .cve-lite/baseline.json with ${count} ${count === 1 ? "finding" : "findings"}. Future scans will only report findings above this baseline.`));
|
|
303
|
+
process.exit(0);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
// auto-apply baseline if it exists - filter before output
|
|
307
|
+
if (baseline) {
|
|
308
|
+
const filtered = filterNewFindings(scanState.sorted, baseline);
|
|
309
|
+
scanState.sorted = filtered.newFindings;
|
|
310
|
+
scanState.tableFindings = scanState.tableFindings.filter(f => filtered.newFindings.some(nf => nf.pkg.name === f.pkg.name && nf.pkg.version === f.pkg.version));
|
|
311
|
+
suppressedCount = filtered.suppressedCount;
|
|
312
|
+
}
|
|
293
313
|
await writeOutputs(options, {
|
|
294
314
|
sorted: scanState.sorted,
|
|
295
315
|
allPackages: scanState.allPackages,
|
|
@@ -350,6 +370,14 @@ if (parsedArgs) {
|
|
|
350
370
|
findings: scanState.sorted.length,
|
|
351
371
|
packages: packages.length,
|
|
352
372
|
});
|
|
373
|
+
if (baseline) {
|
|
374
|
+
if (scanState.sorted.length === 0) {
|
|
375
|
+
console.log(chalk.green(`No new findings above baseline - ${suppressedCount} existing ${suppressedCount === 1 ? "finding" : "findings"} suppressed`));
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
console.log(chalk.yellow(`${scanState.sorted.length} new ${scanState.sorted.length === 1 ? "finding" : "findings"} above baseline - ${suppressedCount} existing ${suppressedCount === 1 ? "finding" : "findings"} suppressed`));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
353
381
|
const failLevel = normalizeSeverity(options.failOn);
|
|
354
382
|
const shouldFail = scanState.sorted.some(f => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
355
383
|
process.exit(shouldFail ? 1 : 0);
|
|
@@ -27,6 +27,10 @@ export function formatRelationshipLabel(value) {
|
|
|
27
27
|
return chalk.yellow(value);
|
|
28
28
|
return chalk.gray(value);
|
|
29
29
|
}
|
|
30
|
+
export function formatRelLabel(finding) {
|
|
31
|
+
const base = finding.relationship;
|
|
32
|
+
return finding.pkg.dev === true ? `${base} · dev` : base;
|
|
33
|
+
}
|
|
30
34
|
export function formatAdvisorySourceLine(sourceLabel) {
|
|
31
35
|
const match = sourceLabel.match(/^(.*) \((.*)\)$/);
|
|
32
36
|
if (!match) {
|
|
@@ -187,6 +191,7 @@ export function serializeFinding(finding, plan) {
|
|
|
187
191
|
version: finding.pkg.version,
|
|
188
192
|
severity: finding.severity,
|
|
189
193
|
relationship: finding.relationship,
|
|
194
|
+
dev: finding.pkg.dev ?? false,
|
|
190
195
|
firstFixedVersion: finding.firstFixedVersion,
|
|
191
196
|
validatedFirstFixedVersion: finding.validatedFirstFixedVersion ?? null,
|
|
192
197
|
fixVersionValidationNote: finding.fixVersionValidationNote ?? null,
|
|
@@ -102,6 +102,7 @@ button.header-link:hover{color:#58a6ff;border-color:#58a6ff}
|
|
|
102
102
|
.rel-badge.direct{color:#3fb950;background:#3fb95022}
|
|
103
103
|
.rel-badge.transitive{color:#e3b341;background:#e3b34122}
|
|
104
104
|
.rel-badge.unknown{color:#8b949e;background:#8b949e22}
|
|
105
|
+
.rel-badge.dev{color:#a371f7;background:#6e40c922;border:1px solid #6e40c955}
|
|
105
106
|
.cve-link{font-size:11px;color:#58a6ff;font-family:monospace;text-decoration:none;border-bottom:1px dotted #58a6ff66}
|
|
106
107
|
.cve-link:hover{color:#79c0ff}
|
|
107
108
|
.fix-hint{font-size:11px;color:#3fb950;font-family:monospace}
|
|
@@ -394,6 +395,12 @@ function advisoryLink(id) {
|
|
|
394
395
|
}
|
|
395
396
|
return `<a class="cve-link" href="https://osv.dev/vulnerability/${escapeHtml(id)}" target="_blank">${escapeHtml(id)}</a>`;
|
|
396
397
|
}
|
|
398
|
+
function renderRelBadge(finding) {
|
|
399
|
+
if (finding.dev) {
|
|
400
|
+
return `<span class="rel-badge dev">${escapeHtml(finding.relationship)} · dev</span>`;
|
|
401
|
+
}
|
|
402
|
+
return `<span class="rel-badge ${escapeHtml(finding.relationship)}">${escapeHtml(finding.relationship)}</span>`;
|
|
403
|
+
}
|
|
397
404
|
export function renderFindingRow(finding, idx, skippedKeys) {
|
|
398
405
|
const cveLinks = finding.cves.length > 0
|
|
399
406
|
? finding.cves.map(advisoryLink).join(", ")
|
|
@@ -432,7 +439,7 @@ export function renderFindingRow(finding, idx, skippedKeys) {
|
|
|
432
439
|
<td><div class="pkg-name">${escapeHtml(finding.package)}</div><div class="pkg-version">${escapeHtml(finding.version)}</div></td>
|
|
433
440
|
<td>${fixHtml}</td>
|
|
434
441
|
<td><span class="sev-badge ${escapeHtml(finding.severity)}">${escapeHtml(finding.severity)}</span></td>
|
|
435
|
-
<td
|
|
442
|
+
<td>${renderRelBadge(finding)}</td>
|
|
436
443
|
<td>${cveLinks}</td>
|
|
437
444
|
</tr>
|
|
438
445
|
<tr id="detail-${idx}" class="detail-row">
|
package/dist/output/printers.js
CHANGED
|
@@ -2,7 +2,7 @@ import { chalk, stripAnsi } from "../utils/chalk.js";
|
|
|
2
2
|
import { buildSuggestedFixCommandPlan } from "../remediation/fix-commands.js";
|
|
3
3
|
import { isMajorVersionBump } from "../utils/version.js";
|
|
4
4
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
5
|
-
import { countUniqueAdvisories, formatSeverityLabel, formatRelationshipLabel } from "./formatters.js";
|
|
5
|
+
import { countUniqueAdvisories, formatSeverityLabel, formatRelationshipLabel, formatRelLabel } from "./formatters.js";
|
|
6
6
|
import { pluralize } from "../utils/string.js";
|
|
7
7
|
import { selectFindingsForCompact } from "./finding-display.js";
|
|
8
8
|
import { MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE, MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE } from "../constants.js";
|
|
@@ -178,7 +178,7 @@ export function printTable(findings, threshold, skippedKeys) {
|
|
|
178
178
|
f.pkg.name,
|
|
179
179
|
f.pkg.version,
|
|
180
180
|
f.severity,
|
|
181
|
-
f
|
|
181
|
+
formatRelLabel(f),
|
|
182
182
|
usageText,
|
|
183
183
|
fixedDisplay,
|
|
184
184
|
f.vulnerabilities.map(v => v.id).join(", ")
|
|
@@ -316,9 +316,9 @@ export function printCompactOutput(findings, scanInput, options) {
|
|
|
316
316
|
for (const finding of urgentFindings) {
|
|
317
317
|
const sevLabel = finding.severity.toUpperCase().padEnd(8);
|
|
318
318
|
const typeLabel = finding.relationship === "direct"
|
|
319
|
-
?
|
|
319
|
+
? `Direct dependency${finding.pkg.dev === true ? " · dev" : ""}`
|
|
320
320
|
: finding.relationship === "transitive"
|
|
321
|
-
?
|
|
321
|
+
? `Transitive dependency${finding.pkg.dev === true ? " · dev" : ""}`
|
|
322
322
|
: "Unknown dependency";
|
|
323
323
|
let usageContext = "";
|
|
324
324
|
if (finding.usage) {
|
package/dist/parsers/bun-lock.js
CHANGED
|
@@ -120,12 +120,14 @@ export function loadFromBunLock(filePath, prodOnly) {
|
|
|
120
120
|
const dev = devNames.has(pkgName) && !prodNames.has(pkgName);
|
|
121
121
|
if (prodOnly && dev)
|
|
122
122
|
continue;
|
|
123
|
+
const resolvedUrl = typeof entry[1] === "string" && entry[1] !== "" ? entry[1] : undefined;
|
|
123
124
|
upsertPackage(map, {
|
|
124
125
|
name,
|
|
125
126
|
version,
|
|
126
127
|
ecosystem: "npm",
|
|
127
128
|
dev,
|
|
128
129
|
paths: [],
|
|
130
|
+
resolvedUrl,
|
|
129
131
|
});
|
|
130
132
|
}
|
|
131
133
|
collectBunPaths(rootDepNames, childDepsByPackageName, map, packageNameToVersion);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import YAML from "yaml";
|
|
3
3
|
import { looksLikeVersion, normalizeRawVersion } from "../utils/version.js";
|
|
4
|
-
import { upsertPackage } from "./utils.js";
|
|
4
|
+
import { upsertPackage, markDevPackages } from "./utils.js";
|
|
5
5
|
import { uniquePathArrays } from "../utils/array.js";
|
|
6
6
|
const MAX_PATHS_PER_PACKAGE = 5;
|
|
7
7
|
const MAX_PATH_DEPTH = 10;
|
|
@@ -54,7 +54,8 @@ function loadLegacy(parsed, prodOnly) {
|
|
|
54
54
|
const dev = !!meta?.dev;
|
|
55
55
|
if (prodOnly && dev)
|
|
56
56
|
continue;
|
|
57
|
-
|
|
57
|
+
const resolvedUrl = meta?.resolution?.tarball;
|
|
58
|
+
upsertPackage(map, { name: ref.name, version: ref.version, ecosystem: "npm", dev, paths: [], resolvedUrl });
|
|
58
59
|
}
|
|
59
60
|
const rootDeps = [];
|
|
60
61
|
for (const importer of Object.values(importers)) {
|
|
@@ -91,6 +92,16 @@ function loadV9(parsed, prodOnly) {
|
|
|
91
92
|
const importers = parsed?.importers ?? {};
|
|
92
93
|
const graph = new Map();
|
|
93
94
|
const map = new Map();
|
|
95
|
+
const packagesMetaSection = parsed?.packages ?? {};
|
|
96
|
+
const resolutionUrls = new Map();
|
|
97
|
+
for (const [key, pkgMeta] of Object.entries(packagesMetaSection)) {
|
|
98
|
+
const ref = parsePnpmPackageKeyV9(String(key));
|
|
99
|
+
if (!ref)
|
|
100
|
+
continue;
|
|
101
|
+
const tarball = pkgMeta?.resolution?.tarball;
|
|
102
|
+
if (tarball)
|
|
103
|
+
resolutionUrls.set(ref.key, tarball);
|
|
104
|
+
}
|
|
94
105
|
for (const [key, meta] of Object.entries(snapshotsSection)) {
|
|
95
106
|
const ref = parsePnpmPackageKeyV9(String(key));
|
|
96
107
|
if (!ref)
|
|
@@ -109,9 +120,10 @@ function loadV9(parsed, prodOnly) {
|
|
|
109
120
|
const dev = !!meta?.dev;
|
|
110
121
|
if (prodOnly && dev)
|
|
111
122
|
continue;
|
|
112
|
-
upsertPackage(map, { name: ref.name, version: ref.version, ecosystem: "npm", dev, paths: [] });
|
|
123
|
+
upsertPackage(map, { name: ref.name, version: ref.version, ecosystem: "npm", dev, paths: [], resolvedUrl: resolutionUrls.get(ref.key) });
|
|
113
124
|
}
|
|
114
125
|
const rootDeps = [];
|
|
126
|
+
const devDepNames = new Set();
|
|
115
127
|
for (const importer of Object.values(importers)) {
|
|
116
128
|
for (const depSectionName of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
117
129
|
if (prodOnly && depSectionName === "devDependencies")
|
|
@@ -120,6 +132,9 @@ function loadV9(parsed, prodOnly) {
|
|
|
120
132
|
if (!depSection || typeof depSection !== "object")
|
|
121
133
|
continue;
|
|
122
134
|
for (const [depName, depRef] of Object.entries(depSection)) {
|
|
135
|
+
if (depSectionName === "devDependencies") {
|
|
136
|
+
devDepNames.add(String(depName));
|
|
137
|
+
}
|
|
123
138
|
const resolved = normalizePnpmDepRefV9(String(depName), depRef);
|
|
124
139
|
if (resolved) {
|
|
125
140
|
rootDeps.push(resolved);
|
|
@@ -139,6 +154,7 @@ function loadV9(parsed, prodOnly) {
|
|
|
139
154
|
}
|
|
140
155
|
}
|
|
141
156
|
collectPnpmPaths(rootDeps, graph, map, parsePnpmPackageKeyV9);
|
|
157
|
+
markDevPackages(map, devDepNames);
|
|
142
158
|
return [...map.values()];
|
|
143
159
|
}
|
|
144
160
|
function collectPnpmPaths(rootDeps, graph, map, parsePackageKey) {
|
package/dist/parsers/utils.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { uniquePathArrays } from "../utils/array.js";
|
|
2
|
+
export function markDevPackages(map, devDepNames) {
|
|
3
|
+
if (devDepNames.size === 0)
|
|
4
|
+
return;
|
|
5
|
+
for (const pkg of map.values()) {
|
|
6
|
+
const paths = pkg.paths ?? [];
|
|
7
|
+
if (paths.length === 0)
|
|
8
|
+
continue;
|
|
9
|
+
// A package is dev only if every known path starts from a devDependency root.
|
|
10
|
+
// path[1] is the root dep name (path[0] is always "project").
|
|
11
|
+
const allPathsFromDev = paths.every(p => p.length >= 2 && devDepNames.has(p[1]));
|
|
12
|
+
if (allPathsFromDev) {
|
|
13
|
+
pkg.dev = true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
2
17
|
export function upsertPackage(map, candidate) {
|
|
3
18
|
const key = `${candidate.name}@${candidate.version}`;
|
|
4
19
|
const existing = map.get(key);
|
|
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { parse as parseYarnLock } from "yarn-lockfile";
|
|
4
4
|
import { uniquePathArrays } from "../utils/array.js";
|
|
5
5
|
import { normalizeRawVersion } from "../utils/version.js";
|
|
6
|
-
import { upsertPackage } from "./utils.js";
|
|
6
|
+
import { upsertPackage, markDevPackages } from "./utils.js";
|
|
7
7
|
const MAX_PATHS_PER_PACKAGE = 5;
|
|
8
8
|
const MAX_PATH_DEPTH = 10;
|
|
9
9
|
export function buildYarnWorkspaceMap(filePath) {
|
|
@@ -117,8 +117,9 @@ function loadRootDepKeys(filePath, selectorToKey, map) {
|
|
|
117
117
|
rootPkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
118
118
|
}
|
|
119
119
|
catch {
|
|
120
|
-
return [];
|
|
120
|
+
return { keys: [], devDepNames: new Set() };
|
|
121
121
|
}
|
|
122
|
+
const devDepNames = new Set(Object.keys(rootPkg.devDependencies ?? {}));
|
|
122
123
|
const rootDepKeys = [];
|
|
123
124
|
for (const depSection of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
124
125
|
const deps = rootPkg[depSection];
|
|
@@ -142,7 +143,7 @@ function loadRootDepKeys(filePath, selectorToKey, map) {
|
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
|
-
return rootDepKeys;
|
|
146
|
+
return { keys: rootDepKeys, devDepNames };
|
|
146
147
|
}
|
|
147
148
|
function parseBerryDependencies(block) {
|
|
148
149
|
const dependencies = {};
|
|
@@ -212,8 +213,9 @@ function loadFromYarnBerryLock(content, filePath) {
|
|
|
212
213
|
}
|
|
213
214
|
graph.set(canonicalKey, [...depKeys]);
|
|
214
215
|
}
|
|
215
|
-
const rootDepKeys = loadRootDepKeys(filePath, selectorToKey, map);
|
|
216
|
+
const { keys: rootDepKeys, devDepNames } = loadRootDepKeys(filePath, selectorToKey, map);
|
|
216
217
|
collectYarnPaths(rootDepKeys, graph, map);
|
|
218
|
+
markDevPackages(map, devDepNames);
|
|
217
219
|
return [...map.values()];
|
|
218
220
|
}
|
|
219
221
|
function loadFromYarnClassicLock(parsed, filePath) {
|
|
@@ -234,7 +236,7 @@ function loadFromYarnClassicLock(parsed, filePath) {
|
|
|
234
236
|
for (const selector of selectors) {
|
|
235
237
|
selectorToKey.set(selector, canonicalKey);
|
|
236
238
|
}
|
|
237
|
-
upsertPackage(map, { name, version, ecosystem: "npm", paths: [] });
|
|
239
|
+
upsertPackage(map, { name, version, ecosystem: "npm", paths: [], resolvedUrl: meta?.resolved });
|
|
238
240
|
}
|
|
239
241
|
for (const [selectorKey, meta] of Object.entries(parsed.object)) {
|
|
240
242
|
const version = meta?.version;
|
|
@@ -258,8 +260,9 @@ function loadFromYarnClassicLock(parsed, filePath) {
|
|
|
258
260
|
}
|
|
259
261
|
graph.set(canonicalKey, [...depKeys]);
|
|
260
262
|
}
|
|
261
|
-
const rootDepKeys = loadRootDepKeys(filePath, selectorToKey, map);
|
|
263
|
+
const { keys: rootDepKeys, devDepNames } = loadRootDepKeys(filePath, selectorToKey, map);
|
|
262
264
|
collectYarnPaths(rootDepKeys, graph, map);
|
|
265
|
+
markDevPackages(map, devDepNames);
|
|
263
266
|
return [...map.values()];
|
|
264
267
|
}
|
|
265
268
|
export function loadFromYarnLock(filePath) {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const BASELINE_DIR = ".cve-lite";
|
|
4
|
+
const BASELINE_FILE = "baseline.json";
|
|
5
|
+
function baselinePath(projectRoot) {
|
|
6
|
+
return path.join(projectRoot, BASELINE_DIR, BASELINE_FILE);
|
|
7
|
+
}
|
|
8
|
+
export function readBaseline(projectRoot) {
|
|
9
|
+
const filePath = baselinePath(projectRoot);
|
|
10
|
+
if (!fs.existsSync(filePath))
|
|
11
|
+
return null;
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function writeBaseline(projectRoot, findings) {
|
|
20
|
+
const dir = path.join(projectRoot, BASELINE_DIR);
|
|
21
|
+
if (!fs.existsSync(dir)) {
|
|
22
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
const baseline = {
|
|
25
|
+
version: 1,
|
|
26
|
+
createdAt: new Date().toISOString(),
|
|
27
|
+
findings: findings.map(f => ({
|
|
28
|
+
name: f.pkg.name,
|
|
29
|
+
version: f.pkg.version,
|
|
30
|
+
advisoryIds: f.vulnerabilities.map(v => v.id),
|
|
31
|
+
})),
|
|
32
|
+
};
|
|
33
|
+
fs.writeFileSync(baselinePath(projectRoot), JSON.stringify(baseline, null, 2) + "\n", "utf8");
|
|
34
|
+
}
|
|
35
|
+
export function filterNewFindings(findings, baseline) {
|
|
36
|
+
const baselineMap = new Map();
|
|
37
|
+
for (const entry of baseline.findings) {
|
|
38
|
+
baselineMap.set(`${entry.name}@${entry.version}`, new Set(entry.advisoryIds));
|
|
39
|
+
}
|
|
40
|
+
const newFindings = [];
|
|
41
|
+
let suppressedCount = 0;
|
|
42
|
+
for (const finding of findings) {
|
|
43
|
+
const key = `${finding.pkg.name}@${finding.pkg.version}`;
|
|
44
|
+
const baselineAdvisories = baselineMap.get(key);
|
|
45
|
+
if (!baselineAdvisories) {
|
|
46
|
+
newFindings.push(finding);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const allKnown = finding.vulnerabilities.every(v => baselineAdvisories.has(v.id));
|
|
50
|
+
if (allKnown) {
|
|
51
|
+
suppressedCount++;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
newFindings.push(finding);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { newFindings, suppressedCount };
|
|
58
|
+
}
|