cve-lite-cli 1.33.0 → 1.35.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 -3
- package/dist/advisory/local-db.js +31 -2
- package/dist/advisory/osv-advisory-source.js +3 -0
- package/dist/cli/advisories-init.js +13 -0
- package/dist/cli/advisories-sync.js +30 -0
- package/dist/cli/args.js +41 -2
- package/dist/cli/config-command.js +15 -0
- package/dist/cli/config.js +29 -0
- package/dist/cli/help.js +7 -5
- package/dist/cli/overrides.js +10 -1
- package/dist/cli/validate.js +6 -2
- package/dist/constants.js +52 -0
- package/dist/index.js +25 -719
- package/dist/output/cyclonedx.js +28 -24
- package/dist/output/formatters.js +13 -0
- package/dist/output/html-reporter.js +81 -40
- package/dist/output/multi-folder-html-reporter.js +16 -10
- package/dist/output/multi-folder-printer.js +1 -1
- package/dist/output/override-findings-sarif.js +1 -0
- package/dist/output/printers.js +436 -271
- package/dist/output/sarif.js +17 -1
- package/dist/output/sbom-dependency-edges.js +86 -0
- package/dist/output/sbom-file.js +27 -0
- package/dist/output/spdx.js +293 -0
- package/dist/output/write-outputs.js +18 -3
- package/dist/overrides/admitted-scan.js +158 -0
- package/dist/overrides/api.js +16 -0
- package/dist/overrides/context-builder.js +4 -0
- package/dist/overrides/context.js +8 -1
- package/dist/overrides/detectors/index.js +2 -0
- package/dist/overrides/detectors/oa010-vulnerable-floor.js +123 -0
- package/dist/overrides/parsing/registry.js +53 -0
- package/dist/parsers/bun-lock-graph.js +182 -0
- package/dist/parsers/bun-lock.js +93 -132
- package/dist/parsers/index.js +75 -149
- package/dist/parsers/multi-package.js +5 -6
- package/dist/parsers/package-lock.js +11 -1
- package/dist/parsers/pnpm-lock-graph.js +94 -0
- package/dist/parsers/pnpm-lock.js +5 -5
- package/dist/parsers/utils.js +3 -0
- package/dist/parsers/yarn-lock-graph.js +148 -0
- package/dist/parsers/yarn-lock.js +3 -3
- package/dist/remediation/fix-commands.js +48 -7
- package/dist/remediation/npm-registry.js +8 -2
- package/dist/scan/completeness.js +1 -0
- package/dist/scan/single-scan.js +643 -0
- package/dist/scanner.js +62 -7
- package/dist/types.js +1 -1
- package/dist/utils/file.js +11 -14
- package/dist/utils/purl.js +10 -0
- package/dist/utils/sbom-format.js +12 -0
- package/dist/utils/version.js +84 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
*Most tools tell you what's wrong. CVE Lite CLI tells you what to run.*
|
|
3
2
|
|
|
4
3
|
[](https://owasp.org/cve-lite-cli)
|
|
@@ -95,6 +94,7 @@ cve-lite /path/to/project --fix # apply validated direct fixes and r
|
|
|
95
94
|
cve-lite /path/to/project --fail-on high # exit non-zero on high severity and above
|
|
96
95
|
cve-lite /path/to/project --json # JSON output
|
|
97
96
|
cve-lite /path/to/project --sarif # SARIF output for GitHub Code Scanning
|
|
97
|
+
cve-lite /path/to/project --sbom spdx # SPDX 2.3 SBOM (also: --sbom cyclonedx)
|
|
98
98
|
cve-lite /path/to/project --report # interactive HTML dashboard
|
|
99
99
|
cve-lite /path/to/project --check-overrides # audit override hygiene alongside the CVE scan
|
|
100
100
|
cve-lite /path/to/project --check-maintenance # flag CVE-blocking version drag and npm-deprecated direct deps
|
|
@@ -210,7 +210,7 @@ The closer a security tool is to a developer's natural workflow, the more likely
|
|
|
210
210
|
|
|
211
211
|
## How it compares
|
|
212
212
|
|
|
213
|
-
No other free tool combines all of the following: lockfile scanning across npm, pnpm, Yarn, and Bun; parent-aware transitive remediation that tells you which package to upgrade (not just which one is vulnerable); fix version validation before suggesting an upgrade; a fully offline advisory DB for restricted environments; CVE + license compliance scanning in a single pass; and an EPSS priority signal that combines CVSS severity with exploitation likelihood into four actionable tiers.
|
|
213
|
+
No other free tool combines all of the following: lockfile scanning across npm, pnpm, Yarn, and Bun; parent-aware transitive remediation that tells you which package to upgrade (not just which one is vulnerable); fix version validation before suggesting an upgrade; a fully offline advisory DB for restricted environments; CVE + license compliance scanning in a single pass; SBOM output in both CycloneDX and SPDX with the vulnerability findings attached rather than as a separate inventory step; and an EPSS priority signal that combines CVSS severity with exploitation likelihood into four actionable tiers.
|
|
214
214
|
|
|
215
215
|
| Capability | CVE Lite CLI | npm audit | OSV-Scanner | Snyk CLI | Socket CLI |
|
|
216
216
|
|---|:---:|:---:|:---:|:---:|:---:|
|
|
@@ -228,6 +228,7 @@ No other free tool combines all of the following: lockfile scanning across npm,
|
|
|
228
228
|
| [Interactive HTML report](https://owasp.org/cve-lite-cli/docs/html-report) | ✅ | ❌ | ❌ | ✅ | ❌ |
|
|
229
229
|
| [SARIF / GitHub Code Scanning output](https://owasp.org/cve-lite-cli/docs/sarif) | ✅ | ❌ | ✅ | ✅ | ❌ |
|
|
230
230
|
| [JSON output](https://owasp.org/cve-lite-cli/docs/cli-reference#output-options) | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
231
|
+
| [SBOM output with findings attached (CycloneDX + SPDX)](https://owasp.org/cve-lite-cli/docs/spdx) | ✅ | ❌ | ❌ | ⚠️ | ⚠️ |
|
|
231
232
|
| [Offline/local advisory DB](https://owasp.org/cve-lite-cli/docs/offline-advisory-db) | ✅ | ❌ | ⚠️ | ❌ | ❌ |
|
|
232
233
|
| [Override hygiene auditing](https://owasp.org/cve-lite-cli/docs/override-hygiene) | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
233
234
|
| [Maintenance-risk detection (CVE-fix drag)](https://owasp.org/cve-lite-cli/docs/maintenance-risk) | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
@@ -363,6 +364,8 @@ This is intentional. Because CVE Lite CLI is a security-oriented tool, runtime d
|
|
|
363
364
|
- [Parser Coverage guide](https://owasp.org/cve-lite-cli/docs/parser-coverage) - supported lockfile formats, selection priority, `package.json` fallback, monorepos, private registries
|
|
364
365
|
- [Remediation Strategy guide](https://owasp.org/cve-lite-cli/docs/remediation-strategy) - how CVE Lite CLI chooses upgrade targets and parent update paths
|
|
365
366
|
- [Release Cooldown Awareness guide](https://owasp.org/cve-lite-cli/docs/release-cooldown) - how CVE Lite CLI reads your package manager's cooldown and warns on fix versions newer than the window you trust
|
|
367
|
+
- [SPDX SBOM guide](https://owasp.org/cve-lite-cli/docs/spdx) - SPDX 2.3 output, how findings are attached, NTIA minimum elements, and inventory-only mode
|
|
368
|
+
- [CycloneDX SBOM guide](https://owasp.org/cve-lite-cli/docs/cyclonedx) - CycloneDX 1.6 output and Dependency-Track integration
|
|
366
369
|
|
|
367
370
|
## Security and verification
|
|
368
371
|
|
|
@@ -437,4 +440,4 @@ Thank you to those who sponsor CVE Lite CLI and help keep it maintained:
|
|
|
437
440
|
|
|
438
441
|
## License
|
|
439
442
|
|
|
440
|
-
MIT - built in public and maintained as an OWASP Foundation Project by Sonu Kapoor.
|
|
443
|
+
MIT - built in public and maintained as an OWASP Foundation Project by Sonu Kapoor.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import Database from "better-sqlite3";
|
|
4
|
-
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
4
|
+
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
5
5
|
const SCHEMA_SQL = `
|
|
6
6
|
CREATE TABLE IF NOT EXISTS advisories (
|
|
7
7
|
id TEXT PRIMARY KEY,
|
|
@@ -177,11 +177,40 @@ export class LocalAdvisoryDatabase {
|
|
|
177
177
|
return [...ids];
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* The release core of a version, with any pre-release and build metadata
|
|
182
|
+
* stripped: `1.2.0-beta.1+exp` becomes `1.2.0`.
|
|
183
|
+
*/
|
|
184
|
+
function releaseCore(version) {
|
|
185
|
+
return version.split("+")[0].split("-")[0];
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Whether `version` is at or above an advisory's `introduced` bound.
|
|
189
|
+
*
|
|
190
|
+
* Plain semver precedence puts a pre-release below its release, so
|
|
191
|
+
* `1.2.0-beta.1` sorts below an `introduced` of `1.2.0` and would fall outside
|
|
192
|
+
* the range the advisory declared. In practice a `1.2.0-beta.1` build is a
|
|
193
|
+
* pre-release *of* `1.2.0` and carries whatever was introduced there, so
|
|
194
|
+
* excluding it is a false negative.
|
|
195
|
+
*
|
|
196
|
+
* The relaxation cannot widen a pre-release lower bound, which matters because
|
|
197
|
+
* OSV declares plenty of them: 64 of 352 sampled `introduced` events, with
|
|
198
|
+
* Next.js using values like `15.0.1-canary.0` routinely. Those are deliberate
|
|
199
|
+
* canary boundaries and must keep comparing exactly, or we would pull in
|
|
200
|
+
* earlier canaries the advisory explicitly excluded and trade this false
|
|
201
|
+
* negative for a false positive. No guard is needed for that: a release core
|
|
202
|
+
* never contains "-", so it can never equal a pre-release `introduced`.
|
|
203
|
+
*/
|
|
204
|
+
function versionAtOrAboveIntroduced(version, introduced) {
|
|
205
|
+
if (compareVersions(version, introduced) >= 0)
|
|
206
|
+
return true;
|
|
207
|
+
return isPreReleaseVersion(version) && releaseCore(version) === introduced;
|
|
208
|
+
}
|
|
180
209
|
function versionMatchesRange(version, row) {
|
|
181
210
|
const introduced = row.introduced;
|
|
182
211
|
const fixed = row.fixed;
|
|
183
212
|
const lastAffected = row.last_affected;
|
|
184
|
-
if (introduced && introduced !== "0" &&
|
|
213
|
+
if (introduced && introduced !== "0" && !versionAtOrAboveIntroduced(version, introduced)) {
|
|
185
214
|
return false;
|
|
186
215
|
}
|
|
187
216
|
if (fixed && compareVersions(version, fixed) >= 0) {
|
|
@@ -62,6 +62,9 @@ export class OsvAdvisorySource {
|
|
|
62
62
|
if (!Array.isArray(data?.results)) {
|
|
63
63
|
throw new Error('OSV batch query returned a 200 response with no "results" array');
|
|
64
64
|
}
|
|
65
|
+
if (data.results.length !== packages.length) {
|
|
66
|
+
throw new Error(`OSV batch query returned ${data.results.length} result(s) for ${packages.length} quer(ies) - response length mismatch`);
|
|
67
|
+
}
|
|
65
68
|
return data.results.map((r, i) => ({
|
|
66
69
|
package: packages[i].name,
|
|
67
70
|
version: packages[i].version,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
+
import process from "node:process";
|
|
2
3
|
import { LocalAdvisoryDatabase } from "../advisory/local-db.js";
|
|
3
4
|
import { getDefaultAdvisoryDbPath } from "../advisory/osv-sync.js";
|
|
5
|
+
import { chalk } from "../utils/chalk.js";
|
|
4
6
|
/**
|
|
5
7
|
* Creates an empty local advisory database with the current schema and no data.
|
|
6
8
|
* This is for air-gapped users who cannot run `advisories sync`: they run
|
|
@@ -22,3 +24,14 @@ export function initAdvisoryDatabase(outputPath) {
|
|
|
22
24
|
db.close();
|
|
23
25
|
return dbPath;
|
|
24
26
|
}
|
|
27
|
+
export function runAdvisoriesInit(options) {
|
|
28
|
+
try {
|
|
29
|
+
const dbPath = initAdvisoryDatabase(options.output);
|
|
30
|
+
console.log(`${chalk.gray("Advisory database:")} created an empty advisory database at ${chalk.cyan(dbPath)}`);
|
|
31
|
+
console.log(chalk.gray(`Populate it from your own sources, then scan with \`--offline-db ${dbPath}\`.`));
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { syncOsvAdvisories } from "../advisory/osv-sync.js";
|
|
3
|
+
import { createSpinner } from "../output/spinner.js";
|
|
4
|
+
import { chalk } from "../utils/chalk.js";
|
|
5
|
+
import { pluralize } from "../utils/string.js";
|
|
6
|
+
export async function runAdvisoriesSync({ options, fetchImpl }) {
|
|
7
|
+
const spinner = createSpinner("Preparing advisory sync...", options);
|
|
8
|
+
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
9
|
+
const result = await syncOsvAdvisories({
|
|
10
|
+
outputPath: options.output,
|
|
11
|
+
fetchImpl,
|
|
12
|
+
onProgress: (event) => {
|
|
13
|
+
if (event.phase === "complete") {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (usePlainProgressLogs) {
|
|
17
|
+
console.log(event.message);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
spinner.update(event.message);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
if (usePlainProgressLogs) {
|
|
24
|
+
console.log(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
spinner.succeed(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
28
|
+
}
|
|
29
|
+
console.log(`${chalk.gray("Advisory database:")} synced ${result.advisoryCount} ${pluralize(result.advisoryCount, "record")} to ${chalk.cyan(result.dbPath)}`);
|
|
30
|
+
}
|
package/dist/cli/args.js
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
import { ConfigAction, ConfigKey } from "./config.js";
|
|
2
|
+
/**
|
|
3
|
+
* Accepted `--sbom` values. `spdx2.3` is an explicit alias for the version we
|
|
4
|
+
* emit today, so a future `spdx3` can be added without changing what a plain
|
|
5
|
+
* `spdx` means for anyone already using it in CI.
|
|
6
|
+
*/
|
|
7
|
+
const SBOM_FORMAT_ALIASES = {
|
|
8
|
+
cyclonedx: "cyclonedx",
|
|
9
|
+
spdx: "spdx",
|
|
10
|
+
"spdx2.3": "spdx",
|
|
11
|
+
};
|
|
12
|
+
function parseSbomFormat(value) {
|
|
13
|
+
const valid = Object.keys(SBOM_FORMAT_ALIASES).join(", ");
|
|
14
|
+
if (value === undefined || value.startsWith("-")) {
|
|
15
|
+
throw new Error(`--sbom requires a format. Valid formats: ${valid}.`);
|
|
16
|
+
}
|
|
17
|
+
const format = SBOM_FORMAT_ALIASES[value.toLowerCase()];
|
|
18
|
+
if (!format) {
|
|
19
|
+
throw new Error(`Unknown --sbom format "${value}". Valid formats: ${valid}.`);
|
|
20
|
+
}
|
|
21
|
+
return format;
|
|
22
|
+
}
|
|
2
23
|
export function parseArgs(argv) {
|
|
3
24
|
// Normalize "cve-lite <path> overrides [flags]" to "cve-lite overrides <path> [flags]"
|
|
4
25
|
// so both orderings work. Only reorder when "overrides" is a bare positional (not argv[0]).
|
|
@@ -351,7 +372,21 @@ export function parseArgs(argv) {
|
|
|
351
372
|
continue;
|
|
352
373
|
}
|
|
353
374
|
if (arg === "--cdx") {
|
|
375
|
+
// Permanent alias. --cdx shipped before --sbom existed and stays supported.
|
|
354
376
|
options.cdx = true;
|
|
377
|
+
options.sbom = "cyclonedx";
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (arg === "--sbom") {
|
|
381
|
+
options.sbom = parseSbomFormat(argv[++i]);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (arg.startsWith("--sbom=")) {
|
|
385
|
+
options.sbom = parseSbomFormat(arg.slice("--sbom=".length));
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
if (arg === "--sbom-inventory-only") {
|
|
389
|
+
options.sbomInventoryOnly = true;
|
|
355
390
|
continue;
|
|
356
391
|
}
|
|
357
392
|
if (arg === "--audit-log") {
|
|
@@ -399,8 +434,12 @@ export function parseArgs(argv) {
|
|
|
399
434
|
}
|
|
400
435
|
throw new Error(`Unexpected argument: ${arg}`);
|
|
401
436
|
}
|
|
402
|
-
if (options.
|
|
403
|
-
|
|
437
|
+
if (options.sbom && options.report) {
|
|
438
|
+
const flag = options.cdx ? "--cdx" : "--sbom";
|
|
439
|
+
throw new Error(`cannot combine ${flag} and --report`);
|
|
440
|
+
}
|
|
441
|
+
if (options.sbomInventoryOnly && !options.sbom) {
|
|
442
|
+
throw new Error("--sbom-inventory-only only applies to SBOM output. Add --sbom <format>, or drop --sbom-inventory-only.");
|
|
404
443
|
}
|
|
405
444
|
return { command: "scan", options, projectArg };
|
|
406
445
|
}
|
|
@@ -38,3 +38,18 @@ export function runConfigCommand(sub) {
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
export function handleConfigCommand(configSubcommand) {
|
|
42
|
+
if (!configSubcommand) {
|
|
43
|
+
console.error(chalk.red("Error: config requires a subcommand: set, unset, show"));
|
|
44
|
+
console.error(chalk.gray("Run `cve-lite --help` for usage."));
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
runConfigCommand(configSubcommand);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
+
console.error(chalk.red(`Error: ${message}`));
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
}
|
package/dist/cli/config.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { chalk } from "../utils/chalk.js";
|
|
6
|
+
import { createCertAwareFetch } from "../utils/network.js";
|
|
4
7
|
export const ConfigAction = {
|
|
5
8
|
Set: "set",
|
|
6
9
|
Unset: "unset",
|
|
@@ -64,3 +67,29 @@ export function writeConfig(config) {
|
|
|
64
67
|
}
|
|
65
68
|
fs.writeFileSync(getConfigPath(), JSON.stringify(config, null, 2) + "\n", "utf8");
|
|
66
69
|
}
|
|
70
|
+
export function setupCaCert(options, debugLog) {
|
|
71
|
+
const savedConfig = readConfig();
|
|
72
|
+
const resolvedCaCert = options.caCert ?? savedConfig.caCert;
|
|
73
|
+
if (resolvedCaCert) {
|
|
74
|
+
if (!options.caCert && savedConfig.caCert) {
|
|
75
|
+
try {
|
|
76
|
+
validateCaCertFile(resolvedCaCert);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
80
|
+
console.error(chalk.red(`Error: Saved ca-cert is no longer valid: ${message}`));
|
|
81
|
+
console.error(chalk.gray(`Run \`cve-lite config unset ca-cert\` to remove it.`));
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
process.env.NODE_EXTRA_CA_CERTS = resolvedCaCert;
|
|
86
|
+
}
|
|
87
|
+
const certFetch = resolvedCaCert ? createCertAwareFetch(resolvedCaCert) : undefined;
|
|
88
|
+
if (debugLog) {
|
|
89
|
+
debugLog("Config loaded", {
|
|
90
|
+
caCert: resolvedCaCert ?? null,
|
|
91
|
+
nodeExtraCaCerts: process.env.NODE_EXTRA_CA_CERTS ?? null,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return certFetch;
|
|
95
|
+
}
|
package/dist/cli/help.js
CHANGED
|
@@ -34,7 +34,9 @@ export function printHelp() {
|
|
|
34
34
|
" --json Save scan results to a timestamped JSON file",
|
|
35
35
|
" --report [dir] Generate an HTML report in [dir] (default: ./cve-report)",
|
|
36
36
|
" --sarif Write SARIF 2.1.0 output to a timestamped .sarif file",
|
|
37
|
-
" --
|
|
37
|
+
" --sbom <format> Write an SBOM: cyclonedx (1.6) or spdx (2.3), to a timestamped file",
|
|
38
|
+
" --sbom-inventory-only Omit the vulnerability overlay from --sbom, leaving a pure inventory",
|
|
39
|
+
" --cdx Alias for --sbom cyclonedx",
|
|
38
40
|
" --no-open Don't auto-open the report in the browser",
|
|
39
41
|
" --fix Apply validated direct dependency fixes and rescan",
|
|
40
42
|
" --ratchet Save current findings as baseline or, if baseline exists, only fail on new findings",
|
|
@@ -46,7 +48,7 @@ export function printHelp() {
|
|
|
46
48
|
" --debug Write verbose runtime/network diagnostics to a timestamped log file",
|
|
47
49
|
" --verbose Show detailed output with fix plan, paths, and full table",
|
|
48
50
|
" --prod-only Exclude dev dependencies where available",
|
|
49
|
-
" --check-overrides Also audit package.json overrides (OA001-
|
|
51
|
+
" --check-overrides Also audit package.json overrides (OA001-OA010, PD001-PD002); findings",
|
|
50
52
|
" print, thread to JSON/SARIF/HTML, and count toward --fail-on",
|
|
51
53
|
" --check-maintenance Also flag direct deps that block a transitive CVE fix via a major-version",
|
|
52
54
|
" drag, or are marked deprecated on npm (DM001); counts toward --fail-on",
|
|
@@ -98,13 +100,13 @@ export function printOverridesHelp() {
|
|
|
98
100
|
const lines = [
|
|
99
101
|
`${OVERRIDES_COMMAND} [path] [flags]`,
|
|
100
102
|
"",
|
|
101
|
-
"Audit package.json overrides and phantom dependency imports (OA001-
|
|
103
|
+
"Audit package.json overrides and phantom dependency imports (OA001-OA010, PD001-PD002).",
|
|
102
104
|
"",
|
|
103
105
|
"Flags:",
|
|
104
106
|
" --json Emit findings as JSON",
|
|
105
107
|
" --fix Apply RFC 6902 patches for findings with auto-fix",
|
|
106
|
-
" --rule <id> Only run a specific rule (OA001-
|
|
107
|
-
" --check-network Enable OA007 registry drift
|
|
108
|
+
" --rule <id> Only run a specific rule (OA001-OA010, PD001-PD002)",
|
|
109
|
+
" --check-network Enable OA007 registry drift + OA010 admitted-range checks (opt-in network)",
|
|
108
110
|
" --audit-log <path> Stream NDJSON change-control to <path>",
|
|
109
111
|
" --fail-on <severity> Exit non-zero at or above this severity (default: critical)",
|
|
110
112
|
" --debug Enable debug logging",
|
package/dist/cli/overrides.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path, { resolve } from "node:path";
|
|
3
3
|
import { buildOverrideContext, audit, applyFix } from "../overrides/index.js";
|
|
4
|
+
import { createAdvisorySource } from "../scanner.js";
|
|
4
5
|
import { createAuditLog } from "../audit-log/index.js";
|
|
5
6
|
import { EXIT_OK, EXIT_FINDINGS, EXIT_ERROR } from "../types.js";
|
|
6
7
|
import { renderOverrideFindings } from "../output/override-findings-terminal.js";
|
|
@@ -10,13 +11,20 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
|
|
|
10
11
|
const projectPath = resolve(projectArg ?? ".");
|
|
11
12
|
const ownsAuditLog = !injectedAuditLog;
|
|
12
13
|
const auditLog = injectedAuditLog ?? createAuditLog(options.auditLog ?? process.env.CVE_LITE_AUDIT_LOG);
|
|
14
|
+
// OA010 needs an advisory source on top of the network opt-in. Built here
|
|
15
|
+
// rather than inside audit() to keep the overrides module free of a scanner
|
|
16
|
+
// import; closed in the finally so an offline database handle never leaks.
|
|
17
|
+
const advisoryContext = options.checkNetwork === true ? createAdvisorySource() : null;
|
|
13
18
|
try {
|
|
14
19
|
const ctx = buildOverrideContext(projectPath, {
|
|
15
20
|
auditLog,
|
|
16
21
|
logger,
|
|
17
22
|
checkNetwork: options.checkNetwork === true,
|
|
18
23
|
});
|
|
19
|
-
const result = await audit(ctx, {
|
|
24
|
+
const result = await audit(ctx, {
|
|
25
|
+
checkNetwork: options.checkNetwork === true,
|
|
26
|
+
advisorySource: advisoryContext?.advisorySource,
|
|
27
|
+
});
|
|
20
28
|
let findings = result.findings;
|
|
21
29
|
if (options.rule) {
|
|
22
30
|
findings = findings.filter((f) => f.ruleId === options.rule);
|
|
@@ -65,6 +73,7 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
|
|
|
65
73
|
return EXIT_ERROR;
|
|
66
74
|
}
|
|
67
75
|
finally {
|
|
76
|
+
advisoryContext?.cleanup?.();
|
|
68
77
|
if (ownsAuditLog)
|
|
69
78
|
auditLog.close();
|
|
70
79
|
}
|
package/dist/cli/validate.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { validateCaCertFile } from "./config.js";
|
|
2
2
|
import { validateOsvUrl } from "../utils/validate-url.js";
|
|
3
|
+
import { resolveSbomFormat } from "../utils/sbom-format.js";
|
|
3
4
|
export async function validateOptions(options) {
|
|
4
5
|
if (options.allowPrivateOsvUrl && !options.osvUrl) {
|
|
5
6
|
throw new Error("--allow-private-osv-url requires --osv-url. Provide a custom OSV endpoint with --osv-url, or remove --allow-private-osv-url.");
|
|
@@ -30,8 +31,11 @@ export async function validateOptions(options) {
|
|
|
30
31
|
if (options.fix && options.sarif) {
|
|
31
32
|
throw new Error("--fix cannot be used with --sarif. Use --fix to apply validated fixes and rescan, or --sarif to save scan results as SARIF, not both.");
|
|
32
33
|
}
|
|
33
|
-
if (options.fix && options
|
|
34
|
-
|
|
34
|
+
if (options.fix && resolveSbomFormat(options)) {
|
|
35
|
+
// Name the flag the user actually typed: --cdx is an alias for --sbom cyclonedx.
|
|
36
|
+
const flag = options.cdx ? "--cdx" : "--sbom";
|
|
37
|
+
const what = options.cdx ? "a CycloneDX SBOM" : "an SBOM";
|
|
38
|
+
throw new Error(`--fix cannot be used with ${flag}. Use --fix to apply validated fixes and rescan, or ${flag} to save ${what}, not both.`);
|
|
35
39
|
}
|
|
36
40
|
if (options.createPr && !options.fix) {
|
|
37
41
|
throw new Error("--create-pr requires --fix. Add --fix to apply validated fixes before opening a pull request, or remove --create-pr.");
|
package/dist/constants.js
CHANGED
|
@@ -19,6 +19,58 @@ export const MAL_GIT_SOURCE_COMPACT_MESSAGE = "Git source — verify repository
|
|
|
19
19
|
export const MAL_GIT_SOURCE_LEGEND_MESSAGE = "verify repository and org are trusted";
|
|
20
20
|
export const MAL_GIT_SOURCE_PINNED_DISPLAY = "⚠ Git source (SHA-pinned)";
|
|
21
21
|
export const MAL_GIT_SOURCE_FLOATING_DISPLAY = "⚠ Git source (floating ref)";
|
|
22
|
+
/**
|
|
23
|
+
* Supported lockfiles in precedence order, strongest signal first.
|
|
24
|
+
*
|
|
25
|
+
* This is the single source of truth for lockfile precedence. Root detection,
|
|
26
|
+
* nested discovery and `chooseBestLockfile` all read it, so a repo resolves to
|
|
27
|
+
* the same lockfile whether it sits at the root or in a subdirectory.
|
|
28
|
+
*
|
|
29
|
+
* npm-shrinkwrap.json outranks package-lock.json because npm itself ignores
|
|
30
|
+
* package-lock.json when a shrinkwrap is present.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Every lockfile the scanner understands. Order here is not precedence: it only
|
|
34
|
+
* fixes the set and the type. The two precedence lists below are what decide
|
|
35
|
+
* which file wins, and they currently disagree with each other.
|
|
36
|
+
*/
|
|
37
|
+
export const LOCKFILE_NAMES = [
|
|
38
|
+
"bun.lock",
|
|
39
|
+
"npm-shrinkwrap.json",
|
|
40
|
+
"package-lock.json",
|
|
41
|
+
"pnpm-lock.yaml",
|
|
42
|
+
"yarn.lock",
|
|
43
|
+
];
|
|
44
|
+
/**
|
|
45
|
+
* Precedence when several lockfiles sit at the repo root.
|
|
46
|
+
*/
|
|
47
|
+
export const LOCKFILE_PRIORITY_ROOT = [
|
|
48
|
+
"bun.lock",
|
|
49
|
+
"npm-shrinkwrap.json",
|
|
50
|
+
"package-lock.json",
|
|
51
|
+
"pnpm-lock.yaml",
|
|
52
|
+
"yarn.lock",
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* Precedence when several lockfiles sit in the same directory below the root.
|
|
56
|
+
*
|
|
57
|
+
* This disagrees with the root order on six of the ten pairs: `bun.lock` ranks
|
|
58
|
+
* last here and first at the root, and `npm-shrinkwrap.json` ranks last here
|
|
59
|
+
* and second at the root. That is a real inconsistency, and the shrinkwrap
|
|
60
|
+
* placement is a bug, since npm ignores `package-lock.json` whenever a
|
|
61
|
+
* shrinkwrap is present.
|
|
62
|
+
*
|
|
63
|
+
* Both are preserved exactly as they were so that this change is behaviour
|
|
64
|
+
* neutral. Reconciling them changes which lockfile is scanned on real projects,
|
|
65
|
+
* so it belongs in its own change where that can be argued and tested.
|
|
66
|
+
*/
|
|
67
|
+
export const LOCKFILE_PRIORITY_NESTED = [
|
|
68
|
+
"package-lock.json",
|
|
69
|
+
"pnpm-lock.yaml",
|
|
70
|
+
"yarn.lock",
|
|
71
|
+
"bun.lock",
|
|
72
|
+
"npm-shrinkwrap.json",
|
|
73
|
+
];
|
|
22
74
|
export const EXCLUDED_DIRS = new Set([
|
|
23
75
|
".git",
|
|
24
76
|
"node_modules",
|