cve-lite-cli 1.20.0 → 1.21.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/dist/cli/args.js +4 -0
- package/dist/cli/help.js +1 -0
- package/dist/index.js +32 -4
- package/dist/utils/baseline.js +58 -0
- package/package.json +1 -1
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);
|
|
@@ -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
|
+
}
|