cve-lite-cli 1.41.5 → 1.42.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 +22 -19
- package/dist/advisory/detail-resolution.js +62 -0
- package/dist/advisory/local-db.js +90 -15
- package/dist/advisory/osv-advisory-source.js +113 -62
- package/dist/advisory/osv-sync.js +18 -16
- package/dist/advisory/sqlite.js +50 -0
- package/dist/audit-log/ndjson-writer.js +6 -3
- package/dist/audit-log/open-error.js +22 -0
- package/dist/cli/args.js +145 -87
- package/dist/cli/flags.js +2 -0
- package/dist/cli/help.js +6 -2
- package/dist/cli/overrides.js +5 -2
- package/dist/cli/validate.js +45 -5
- package/dist/constants.js +10 -0
- package/dist/index.js +15 -6
- package/dist/licenses/license-check.js +17 -4
- package/dist/osv/cache.js +7 -13
- package/dist/output/cyclonedx.js +57 -18
- package/dist/output/finding-display.js +8 -1
- package/dist/output/formatters.js +52 -11
- package/dist/output/html-reporter.js +40 -8
- package/dist/output/override-findings-terminal.js +21 -13
- package/dist/output/printers.js +185 -76
- package/dist/output/sarif.js +182 -16
- package/dist/output/spdx.js +15 -1
- package/dist/output/write-outputs.js +29 -20
- package/dist/overrides/context-builder.js +1 -7
- package/dist/overrides/detectors/oa005-nested-ineffective.js +6 -1
- package/dist/overrides/detectors/oa008-materialized.js +33 -10
- package/dist/overrides/detectors/oa009-stale-floor.js +2 -2
- package/dist/overrides/detectors/oa010-vulnerable-floor.js +19 -13
- package/dist/overrides/detectors/phantom-utils.js +2 -10
- package/dist/overrides/fixer.js +13 -2
- package/dist/overrides/index.js +1 -0
- package/dist/overrides/types.js +15 -1
- package/dist/parsers/bun-lock.js +6 -0
- package/dist/parsers/index.js +177 -40
- package/dist/parsers/multi-package.js +4 -0
- package/dist/parsers/package-lock.js +6 -2
- package/dist/parsers/pnpm-lock.js +4 -7
- package/dist/parsers/requirements-txt.js +185 -0
- package/dist/parsers/utils.js +11 -6
- package/dist/parsers/yarn-lock.js +1 -5
- package/dist/remediation/fix-commands.js +60 -36
- package/dist/remediation/parent-update-child-note.js +3 -2
- package/dist/scan/completeness.js +57 -4
- package/dist/scan/multi-folder-scan.js +27 -13
- package/dist/scan/single-scan.js +118 -37
- package/dist/scanner.js +59 -36
- package/dist/types.js +1 -1
- package/dist/utils/array.js +5 -0
- package/dist/utils/baseline.js +8 -2
- package/dist/utils/chalk.js +1 -3
- package/dist/utils/create-pr.js +2 -2
- package/dist/utils/debug-bundle.js +37 -22
- package/dist/utils/debug-project.js +6 -5
- package/dist/utils/debug-redaction.js +1 -1
- package/dist/utils/effective-options.js +5 -1
- package/dist/utils/finding.js +4 -0
- package/dist/utils/fix-runner.js +110 -36
- package/dist/utils/import-type-queries.js +5 -1
- package/dist/utils/install-command.js +6 -0
- package/dist/utils/malicious.js +11 -0
- package/dist/utils/package-identity.js +12 -2
- package/dist/utils/path-coverage.js +1 -5
- package/dist/utils/sanitize.js +59 -0
- package/dist/utils/sbom-format.js +17 -8
- package/dist/utils/severity.js +61 -7
- package/dist/utils/url.js +175 -0
- package/dist/utils/version.js +44 -0
- package/dist/utils/vuln.js +11 -14
- package/package.json +2 -4
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
let sqlite;
|
|
3
|
+
export class SQLiteUnavailableError extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(`The offline advisory database requires Node 22.13.0 or later on 22.x, or 23.4.0 or later, with SQLite enabled. Found Node ${process.version}.`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function openDatabase(path, readOnly) {
|
|
9
|
+
if (!sqlite) {
|
|
10
|
+
// Older Node releases emit this notice synchronously on first load.
|
|
11
|
+
// Keep application warnings and the caller's warning handler intact.
|
|
12
|
+
const emitWarning = process.emitWarning;
|
|
13
|
+
process.emitWarning = new Proxy(emitWarning, {
|
|
14
|
+
apply(target, receiver, args) {
|
|
15
|
+
if (args[0] === "SQLite is an experimental feature and might change at any time" &&
|
|
16
|
+
args[1] === "ExperimentalWarning")
|
|
17
|
+
return;
|
|
18
|
+
return Reflect.apply(target, receiver, args);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
try {
|
|
22
|
+
const binding = process.getBuiltinModule?.("node:sqlite");
|
|
23
|
+
if (typeof binding?.DatabaseSync !== "function")
|
|
24
|
+
throw new SQLiteUnavailableError();
|
|
25
|
+
sqlite = binding;
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
process.emitWarning = emitWarning;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const db = new sqlite.DatabaseSync(path, { readOnly });
|
|
32
|
+
// Match the previous driver's wait on a locked file, including on Node 22.13.
|
|
33
|
+
db.exec("PRAGMA busy_timeout = 5000");
|
|
34
|
+
return db;
|
|
35
|
+
}
|
|
36
|
+
export function inTransaction(db, write) {
|
|
37
|
+
db.exec("BEGIN");
|
|
38
|
+
try {
|
|
39
|
+
write();
|
|
40
|
+
db.exec("COMMIT");
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
// SQLite can roll back a transaction itself for some write errors.
|
|
44
|
+
try {
|
|
45
|
+
db.exec("ROLLBACK");
|
|
46
|
+
}
|
|
47
|
+
catch { /* Preserve the original failure. */ }
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { appendFileSync, closeSync, openSync } from "node:fs";
|
|
1
|
+
import { appendFileSync, closeSync, mkdirSync, openSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
2
3
|
/**
|
|
3
4
|
* Append-only NDJSON writer. Opens the file once, appends one JSON object
|
|
4
5
|
* per line per emit, closes on demand.
|
|
@@ -6,8 +7,10 @@ import { appendFileSync, closeSync, openSync } from "node:fs";
|
|
|
6
7
|
export class NdjsonAuditLog {
|
|
7
8
|
isNoOp = false;
|
|
8
9
|
fd;
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
10
|
+
constructor(filePath) {
|
|
11
|
+
const parentDir = path.dirname(filePath);
|
|
12
|
+
mkdirSync(parentDir, { recursive: true });
|
|
13
|
+
this.fd = openSync(filePath, "a");
|
|
11
14
|
}
|
|
12
15
|
emit(event) {
|
|
13
16
|
if (this.fd === null) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getSystemErrorMap } from "node:util";
|
|
2
|
+
const systemErrorReasons = new Map(getSystemErrorMap().values());
|
|
3
|
+
const writablePathErrors = new Set(["EACCES", "EPERM", "EROFS", "ENOENT", "ENOTDIR", "EISDIR", "EEXIST"]);
|
|
4
|
+
/** Format an audit-log initialization failure for a single line of CLI stderr. */
|
|
5
|
+
export function formatAuditLogOpenError(path, fromFlag, error) {
|
|
6
|
+
const source = fromFlag ? "--audit-log" : "CVE_LITE_AUDIT_LOG";
|
|
7
|
+
const code = error instanceof Error && "code" in error && typeof error.code === "string"
|
|
8
|
+
? error.code
|
|
9
|
+
: undefined;
|
|
10
|
+
const systemReason = code === undefined ? undefined : systemErrorReasons.get(code);
|
|
11
|
+
const reason = systemReason === undefined
|
|
12
|
+
? (error instanceof Error ? error.message : String(error))
|
|
13
|
+
: `${code}: ${systemReason}`;
|
|
14
|
+
let hint = "Resolve the reported filesystem error and retry.";
|
|
15
|
+
if (code === "ENAMETOOLONG") {
|
|
16
|
+
hint = "Choose a shorter audit-log path.";
|
|
17
|
+
}
|
|
18
|
+
else if (code !== undefined && writablePathErrors.has(code)) {
|
|
19
|
+
hint = "Choose a writable file path.";
|
|
20
|
+
}
|
|
21
|
+
return `Error: Failed to open audit log from ${source} at '${path}': ${reason}. ${hint}`.replace(/[\r\n]/g, " ");
|
|
22
|
+
}
|
package/dist/cli/args.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConfigAction, ConfigKey } from "./config.js";
|
|
2
|
-
import { FLAG_ALL, FLAG_ALLOW_PRIVATE_OSV_URL, FLAG_AUDIT_LOG, FLAG_BASE, FLAG_BATCH_SIZE, FLAG_CA_CERT, FLAG_CACHE_DIR, FLAG_CDX, FLAG_CHECK_LICENSES, FLAG_CHECK_MAINTENANCE, FLAG_CHECK_NETWORK, FLAG_CHECK_OVERRIDES, FLAG_CREATE_PR, FLAG_DEBUG, FLAG_FAIL_ON, FLAG_FIX, FLAG_HELP, FLAG_INCOMPLETE_POLICY, FLAG_JSON, FLAG_MIN_SEVERITY, FLAG_NO_CACHE, FLAG_NO_OPEN, FLAG_OFFLINE, FLAG_OFFLINE_DB, FLAG_ONLY_USED, FLAG_OSV_URL, FLAG_OUTPUT, FLAG_PROD_ONLY, FLAG_RATCHET, FLAG_REPORT, FLAG_RULE, FLAG_SARIF, FLAG_SBOM, FLAG_SBOM_INVENTORY_ONLY, FLAG_SEARCH_DEPTH, FLAG_USAGE, FLAG_USAGE_HINTS, FLAG_VERBOSE, FLAG_VERSION, } from "./flags.js";
|
|
2
|
+
import { FLAG_ALL, FLAG_ALLOW_EMPTY, FLAG_ALLOW_PRIVATE_OSV_URL, FLAG_AUDIT_LOG, FLAG_BASE, FLAG_BATCH_SIZE, FLAG_CA_CERT, FLAG_CACHE_DIR, FLAG_CDX, FLAG_CHECK_LICENSES, FLAG_CHECK_MAINTENANCE, FLAG_CHECK_NETWORK, FLAG_CHECK_OVERRIDES, FLAG_CREATE_PR, FLAG_DEBUG, FLAG_FAIL_ON, FLAG_FIX, FLAG_HELP, FLAG_INCOMPLETE_POLICY, FLAG_JSON, FLAG_MIN_SEVERITY, FLAG_NO_CACHE, FLAG_NO_OPEN, FLAG_OFFLINE, FLAG_OFFLINE_DB, FLAG_ONLY_USED, FLAG_OSV_URL, FLAG_OUTPUT, FLAG_PROD_ONLY, FLAG_PYTHON, FLAG_RATCHET, FLAG_REPORT, FLAG_RULE, FLAG_SARIF, FLAG_SBOM, FLAG_SBOM_INVENTORY_ONLY, FLAG_SEARCH_DEPTH, FLAG_USAGE, FLAG_USAGE_HINTS, FLAG_VERBOSE, FLAG_VERSION, } from "./flags.js";
|
|
3
|
+
import { OVERRIDE_RULE_IDS } from "../overrides/types.js";
|
|
3
4
|
/**
|
|
4
5
|
* Accepted `--sbom` values. `spdx2.3` is an explicit alias for the version we
|
|
5
6
|
* emit today, so a future `spdx3` can be added without changing what a plain
|
|
@@ -28,22 +29,62 @@ function requireFlagValue(flag, value, noun) {
|
|
|
28
29
|
}
|
|
29
30
|
return value;
|
|
30
31
|
}
|
|
31
|
-
function
|
|
32
|
+
function parseMinSeverity(value) {
|
|
33
|
+
const valid = FAIL_ON_SEVERITIES.join(", ");
|
|
34
|
+
const val = requireFlagValue(FLAG_MIN_SEVERITY, value, "level");
|
|
35
|
+
if (!FAIL_ON_SEVERITIES.includes(val.toLowerCase())) {
|
|
36
|
+
throw new Error(`Unknown --min-severity level "${val}". Valid levels: ${valid}.`);
|
|
37
|
+
}
|
|
38
|
+
return val.toLowerCase();
|
|
39
|
+
}
|
|
40
|
+
function parseSbomFormats(value) {
|
|
32
41
|
const valid = Object.keys(SBOM_FORMAT_ALIASES).join(", ");
|
|
33
42
|
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
34
43
|
throw new Error(`--sbom requires a format. Valid formats: ${valid}.`);
|
|
35
44
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
const parts = value.split(",");
|
|
46
|
+
const formats = [];
|
|
47
|
+
for (const rawPart of parts) {
|
|
48
|
+
const part = rawPart.trim();
|
|
49
|
+
if (!part) {
|
|
50
|
+
throw new Error(`--sbom format list has an empty entry. Valid formats: ${valid}.`);
|
|
51
|
+
}
|
|
52
|
+
const key = part.toLowerCase();
|
|
53
|
+
const format = Object.prototype.hasOwnProperty.call(SBOM_FORMAT_ALIASES, key)
|
|
54
|
+
? SBOM_FORMAT_ALIASES[key]
|
|
55
|
+
: undefined;
|
|
56
|
+
if (!format) {
|
|
57
|
+
throw new Error(`Unknown --sbom format "${part}". Valid formats: ${valid}.`);
|
|
58
|
+
}
|
|
59
|
+
formats.push(format);
|
|
60
|
+
}
|
|
61
|
+
return formats;
|
|
62
|
+
}
|
|
63
|
+
function appendSbomFormats(existing, incoming) {
|
|
64
|
+
const current = existing
|
|
65
|
+
? (Array.isArray(existing) ? [...existing] : [existing])
|
|
66
|
+
: [];
|
|
67
|
+
for (const fmt of incoming) {
|
|
68
|
+
if (!current.includes(fmt)) {
|
|
69
|
+
current.push(fmt);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return current.length === 1 ? current[0] : current;
|
|
73
|
+
}
|
|
74
|
+
function parseRuleId(value) {
|
|
75
|
+
const raw = requireFlagValue(FLAG_RULE, value, "rule id");
|
|
76
|
+
const normalized = raw.toUpperCase();
|
|
77
|
+
if (!OVERRIDE_RULE_IDS.includes(normalized)) {
|
|
78
|
+
const valid = OVERRIDE_RULE_IDS.join(", ");
|
|
79
|
+
throw new Error(`Unknown --rule ID "${raw}". Valid rules: ${valid}.`);
|
|
39
80
|
}
|
|
40
|
-
return
|
|
81
|
+
return normalized;
|
|
41
82
|
}
|
|
42
83
|
export function parseArgs(argv) {
|
|
43
84
|
// Normalize "cve-lite <path> overrides [flags]" to "cve-lite overrides <path> [flags]"
|
|
44
85
|
// so both orderings work. Only reorder when "overrides" is a bare positional (not argv[0]).
|
|
45
86
|
const overridesIdx = argv.indexOf("overrides");
|
|
46
|
-
if (overridesIdx > 0 && !argv[overridesIdx - 1].startsWith("-")) {
|
|
87
|
+
if (overridesIdx > 0 && argv[0] !== "advisories" && !argv[overridesIdx - 1].startsWith("-")) {
|
|
47
88
|
argv = ["overrides", ...argv.slice(0, overridesIdx), ...argv.slice(overridesIdx + 1)];
|
|
48
89
|
}
|
|
49
90
|
const options = {
|
|
@@ -53,73 +94,77 @@ export function parseArgs(argv) {
|
|
|
53
94
|
searchDepth: "4",
|
|
54
95
|
minSeverity: "medium"
|
|
55
96
|
};
|
|
56
|
-
if (argv[0] === "advisories"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
options.output = arg.slice(FLAG_OUTPUT.length + 1);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (arg === FLAG_CA_CERT) {
|
|
76
|
-
const val = argv[++i];
|
|
77
|
-
if (!val) {
|
|
78
|
-
throw new Error("--ca-cert requires a path argument");
|
|
97
|
+
if (argv[0] === "advisories") {
|
|
98
|
+
const sub = argv[1];
|
|
99
|
+
if (sub === "-h" || sub === FLAG_HELP) {
|
|
100
|
+
options.help = true;
|
|
101
|
+
return { command: "advisories-sync", options };
|
|
102
|
+
}
|
|
103
|
+
if (sub === "-v" || sub === FLAG_VERSION) {
|
|
104
|
+
options.version = true;
|
|
105
|
+
return { command: "advisories-sync", options };
|
|
106
|
+
}
|
|
107
|
+
if (sub === "sync") {
|
|
108
|
+
for (let i = 2; i < argv.length; i++) {
|
|
109
|
+
const arg = argv[i];
|
|
110
|
+
if (arg === "-h" || arg === FLAG_HELP) {
|
|
111
|
+
options.help = true;
|
|
112
|
+
continue;
|
|
79
113
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (arg.startsWith(`${FLAG_CA_CERT}=`)) {
|
|
84
|
-
const val = arg.slice(FLAG_CA_CERT.length + 1);
|
|
85
|
-
if (!val) {
|
|
86
|
-
throw new Error("--ca-cert requires a path argument");
|
|
114
|
+
if (arg === "-v" || arg === FLAG_VERSION) {
|
|
115
|
+
options.version = true;
|
|
116
|
+
continue;
|
|
87
117
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
118
|
+
if (arg === FLAG_OUTPUT) {
|
|
119
|
+
options.output = requireFlagValue(FLAG_OUTPUT, argv[++i], "path");
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (arg.startsWith(`${FLAG_OUTPUT}=`)) {
|
|
123
|
+
options.output = requireFlagValue(FLAG_OUTPUT, arg.slice(FLAG_OUTPUT.length + 1), "path");
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (arg === FLAG_CA_CERT) {
|
|
127
|
+
options.caCert = requireFlagValue(FLAG_CA_CERT, argv[++i], "path");
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (arg.startsWith(`${FLAG_CA_CERT}=`)) {
|
|
131
|
+
options.caCert = requireFlagValue(FLAG_CA_CERT, arg.slice(FLAG_CA_CERT.length + 1), "path");
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (arg.startsWith("-")) {
|
|
135
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
136
|
+
}
|
|
137
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
93
138
|
}
|
|
94
|
-
|
|
139
|
+
return { command: "advisories-sync", options };
|
|
95
140
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
throw new Error(`
|
|
141
|
+
if (sub === "init") {
|
|
142
|
+
for (let i = 2; i < argv.length; i++) {
|
|
143
|
+
const arg = argv[i];
|
|
144
|
+
if (arg === "-h" || arg === FLAG_HELP) {
|
|
145
|
+
options.help = true;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (arg === "-v" || arg === FLAG_VERSION) {
|
|
149
|
+
options.version = true;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (arg === FLAG_OUTPUT) {
|
|
153
|
+
options.output = requireFlagValue(FLAG_OUTPUT, argv[++i], "path");
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (arg.startsWith(`${FLAG_OUTPUT}=`)) {
|
|
157
|
+
options.output = requireFlagValue(FLAG_OUTPUT, arg.slice(FLAG_OUTPUT.length + 1), "path");
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (arg.startsWith("-")) {
|
|
161
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
162
|
+
}
|
|
163
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
119
164
|
}
|
|
120
|
-
|
|
165
|
+
return { command: "advisories-init", options };
|
|
121
166
|
}
|
|
122
|
-
|
|
167
|
+
throw new Error(`Unknown advisories subcommand: ${sub ?? "(none)"}. Use: sync, init`);
|
|
123
168
|
}
|
|
124
169
|
if (argv[0] === "install-skill") {
|
|
125
170
|
for (let i = 1; i < argv.length; i++) {
|
|
@@ -190,11 +235,11 @@ export function parseArgs(argv) {
|
|
|
190
235
|
continue;
|
|
191
236
|
}
|
|
192
237
|
if (arg === FLAG_RULE) {
|
|
193
|
-
options.rule =
|
|
238
|
+
options.rule = parseRuleId(argv[++i]);
|
|
194
239
|
continue;
|
|
195
240
|
}
|
|
196
241
|
if (arg.startsWith(`${FLAG_RULE}=`)) {
|
|
197
|
-
options.rule =
|
|
242
|
+
options.rule = parseRuleId(arg.slice(FLAG_RULE.length + 1));
|
|
198
243
|
continue;
|
|
199
244
|
}
|
|
200
245
|
if (arg === FLAG_FAIL_ON) {
|
|
@@ -217,6 +262,7 @@ export function parseArgs(argv) {
|
|
|
217
262
|
return { command: "overrides", options, projectArg };
|
|
218
263
|
}
|
|
219
264
|
let projectArg;
|
|
265
|
+
let reportDirectoryFromNextArg = false;
|
|
220
266
|
for (let i = 0; i < argv.length; i++) {
|
|
221
267
|
const arg = argv[i];
|
|
222
268
|
if (arg === "-h" || arg === FLAG_HELP) {
|
|
@@ -252,25 +298,21 @@ export function parseArgs(argv) {
|
|
|
252
298
|
continue;
|
|
253
299
|
}
|
|
254
300
|
if (arg === FLAG_BASE) {
|
|
255
|
-
|
|
256
|
-
if (!val) {
|
|
257
|
-
throw new Error("--base requires a branch name");
|
|
258
|
-
}
|
|
259
|
-
options.prBase = val;
|
|
301
|
+
options.prBase = requireFlagValue(FLAG_BASE, argv[++i], "branch name");
|
|
260
302
|
continue;
|
|
261
303
|
}
|
|
262
304
|
if (arg.startsWith(`${FLAG_BASE}=`)) {
|
|
263
|
-
|
|
264
|
-
if (!val) {
|
|
265
|
-
throw new Error("--base requires a branch name");
|
|
266
|
-
}
|
|
267
|
-
options.prBase = val;
|
|
305
|
+
options.prBase = requireFlagValue(FLAG_BASE, arg.slice(FLAG_BASE.length + 1), "branch name");
|
|
268
306
|
continue;
|
|
269
307
|
}
|
|
270
308
|
if (arg === FLAG_PROD_ONLY) {
|
|
271
309
|
options.prodOnly = true;
|
|
272
310
|
continue;
|
|
273
311
|
}
|
|
312
|
+
if (arg === FLAG_PYTHON) {
|
|
313
|
+
options.python = true;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
274
316
|
if (arg === FLAG_OFFLINE) {
|
|
275
317
|
options.offline = true;
|
|
276
318
|
continue;
|
|
@@ -287,6 +329,10 @@ export function parseArgs(argv) {
|
|
|
287
329
|
options.all = true;
|
|
288
330
|
continue;
|
|
289
331
|
}
|
|
332
|
+
if (arg === FLAG_ALLOW_EMPTY) {
|
|
333
|
+
options.allowEmpty = true;
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
290
336
|
if (arg === FLAG_FAIL_ON) {
|
|
291
337
|
options.failOn = parseFailOn(argv[++i]);
|
|
292
338
|
continue;
|
|
@@ -348,11 +394,11 @@ export function parseArgs(argv) {
|
|
|
348
394
|
continue;
|
|
349
395
|
}
|
|
350
396
|
if (arg === FLAG_MIN_SEVERITY) {
|
|
351
|
-
options.minSeverity =
|
|
397
|
+
options.minSeverity = parseMinSeverity(argv[++i]);
|
|
352
398
|
continue;
|
|
353
399
|
}
|
|
354
400
|
if (arg.startsWith(`${FLAG_MIN_SEVERITY}=`)) {
|
|
355
|
-
options.minSeverity =
|
|
401
|
+
options.minSeverity = parseMinSeverity(arg.slice(FLAG_MIN_SEVERITY.length + 1));
|
|
356
402
|
continue;
|
|
357
403
|
}
|
|
358
404
|
if (arg === FLAG_USAGE || arg === FLAG_USAGE_HINTS) {
|
|
@@ -367,7 +413,10 @@ export function parseArgs(argv) {
|
|
|
367
413
|
if (arg === FLAG_REPORT) {
|
|
368
414
|
const next = argv[i + 1];
|
|
369
415
|
if (next !== undefined && !next.startsWith("-")) {
|
|
370
|
-
|
|
416
|
+
// Keep the existing directory syntax, then reject it below if no
|
|
417
|
+
// separate project path makes the pre-project ordering unambiguous.
|
|
418
|
+
reportDirectoryFromNextArg = true;
|
|
419
|
+
options.report = requireFlagValue(FLAG_REPORT, next, "directory");
|
|
371
420
|
i++;
|
|
372
421
|
}
|
|
373
422
|
else {
|
|
@@ -376,7 +425,11 @@ export function parseArgs(argv) {
|
|
|
376
425
|
continue;
|
|
377
426
|
}
|
|
378
427
|
if (arg.startsWith(`${FLAG_REPORT}=`)) {
|
|
379
|
-
|
|
428
|
+
const value = arg.slice(FLAG_REPORT.length + 1);
|
|
429
|
+
if (value === "") {
|
|
430
|
+
throw new Error(`${FLAG_REPORT} requires a directory argument`);
|
|
431
|
+
}
|
|
432
|
+
options.report = value;
|
|
380
433
|
continue;
|
|
381
434
|
}
|
|
382
435
|
if (arg === FLAG_NO_OPEN) {
|
|
@@ -402,15 +455,17 @@ export function parseArgs(argv) {
|
|
|
402
455
|
if (arg === FLAG_CDX) {
|
|
403
456
|
// Permanent alias. --cdx shipped before --sbom existed and stays supported.
|
|
404
457
|
options.cdx = true;
|
|
405
|
-
options.sbom = "cyclonedx";
|
|
458
|
+
options.sbom = appendSbomFormats(options.sbom, ["cyclonedx"]);
|
|
406
459
|
continue;
|
|
407
460
|
}
|
|
408
461
|
if (arg === FLAG_SBOM) {
|
|
409
|
-
|
|
462
|
+
const parsed = parseSbomFormats(argv[++i]);
|
|
463
|
+
options.sbom = appendSbomFormats(options.sbom, parsed);
|
|
410
464
|
continue;
|
|
411
465
|
}
|
|
412
466
|
if (arg.startsWith(`${FLAG_SBOM}=`)) {
|
|
413
|
-
|
|
467
|
+
const parsed = parseSbomFormats(arg.slice(FLAG_SBOM.length + 1));
|
|
468
|
+
options.sbom = appendSbomFormats(options.sbom, parsed);
|
|
414
469
|
continue;
|
|
415
470
|
}
|
|
416
471
|
if (arg === FLAG_SBOM_INVENTORY_ONLY) {
|
|
@@ -468,6 +523,9 @@ export function parseArgs(argv) {
|
|
|
468
523
|
}
|
|
469
524
|
throw new Error(`Unexpected argument: ${arg}`);
|
|
470
525
|
}
|
|
526
|
+
if (reportDirectoryFromNextArg && !projectArg) {
|
|
527
|
+
throw new Error(`Ambiguous ${FLAG_REPORT} argument. Use ${FLAG_REPORT}=<dir> or put the project path first.`);
|
|
528
|
+
}
|
|
471
529
|
if (options.sbom && options.report) {
|
|
472
530
|
const flag = options.cdx ? FLAG_CDX : FLAG_SBOM;
|
|
473
531
|
throw new Error(`cannot combine ${flag} and --report`);
|
package/dist/cli/flags.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const FLAG_ALL = "--all";
|
|
2
|
+
export const FLAG_ALLOW_EMPTY = "--allow-empty";
|
|
2
3
|
export const FLAG_ALLOW_PRIVATE_OSV_URL = "--allow-private-osv-url";
|
|
3
4
|
export const FLAG_AUDIT_LOG = "--audit-log";
|
|
4
5
|
export const FLAG_BASE = "--base";
|
|
@@ -26,6 +27,7 @@ export const FLAG_ONLY_USED = "--only-used";
|
|
|
26
27
|
export const FLAG_OSV_URL = "--osv-url";
|
|
27
28
|
export const FLAG_OUTPUT = "--output";
|
|
28
29
|
export const FLAG_PROD_ONLY = "--prod-only";
|
|
30
|
+
export const FLAG_PYTHON = "--python";
|
|
29
31
|
export const FLAG_RATCHET = "--ratchet";
|
|
30
32
|
export const FLAG_REPORT = "--report";
|
|
31
33
|
export const FLAG_RULE = "--rule";
|
package/dist/cli/help.js
CHANGED
|
@@ -34,8 +34,9 @@ export function printHelp() {
|
|
|
34
34
|
"Scan options:",
|
|
35
35
|
" --json Save scan results to a timestamped JSON file",
|
|
36
36
|
" --report [dir] Generate an HTML report in [dir] (default: ./cve-report)",
|
|
37
|
+
" Use --report=<dir> or name projectPath when [dir] comes first",
|
|
37
38
|
" --sarif Write SARIF 2.1.0 output to a timestamped .sarif file",
|
|
38
|
-
" --sbom <format> Write an SBOM: cyclonedx (1.6) or spdx (2.3), to a timestamped file",
|
|
39
|
+
" --sbom <format> Write an SBOM: cyclonedx (1.6) or spdx (2.3), to a timestamped file (comma-separated for multiple)",
|
|
39
40
|
" --sbom-inventory-only Omit the vulnerability overlay from --sbom, leaving a pure inventory",
|
|
40
41
|
" --cdx Alias for --sbom cyclonedx",
|
|
41
42
|
" --output <path> Directory or file path for --json, --sarif and --sbom files (use '-' for stdout; default: current directory)",
|
|
@@ -60,8 +61,11 @@ export function printHelp() {
|
|
|
60
61
|
" drag, or are marked deprecated on npm (DM001); counts toward --fail-on",
|
|
61
62
|
" --check-licenses Also detect copyleft (LC001) and unknown (LC002) licenses; informational",
|
|
62
63
|
" only - does not affect exit code or --fail-on",
|
|
63
|
-
" --fail-on <severity> Exit non-zero at or above severity (default: critical)",
|
|
64
|
+
" --fail-on <severity> Exit non-zero at or above severity (default: critical);",
|
|
65
|
+
" Python findings are excluded from the gate",
|
|
66
|
+
" --allow-empty Exit 0 when no scannable packages are found (default: exit 3)",
|
|
64
67
|
" --incomplete-policy <mode> Incomplete scan handling: warn or error (default: warn)",
|
|
68
|
+
" --python Scan pinned Python requirements.txt dependencies (experimental)",
|
|
65
69
|
" --batch-size <number> OSV batch size (default: 100)",
|
|
66
70
|
" --usage Scan project source files to check if vulnerable dependencies are imported",
|
|
67
71
|
" --only-used Filter out findings for packages that are not imported in your source code",
|
package/dist/cli/overrides.js
CHANGED
|
@@ -41,8 +41,11 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
|
|
|
41
41
|
auditLog,
|
|
42
42
|
dryRun: false,
|
|
43
43
|
});
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// Match on the patch itself: one package can carry several findings, and only
|
|
45
|
+
// the ones whose patch was applied are resolved.
|
|
46
|
+
const key = (ruleId, patch) => `${ruleId}:${JSON.stringify(patch)}`;
|
|
47
|
+
const appliedKeys = new Set(report.appliedPatches.map((p) => key(p.ruleId, p.patches)));
|
|
48
|
+
const remaining = findings.filter((f) => !f.fix || !appliedKeys.has(key(f.ruleId, f.fix.patch)));
|
|
46
49
|
if (options.json) {
|
|
47
50
|
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
48
51
|
const jsonFilename = `cve-lite-overrides-${ts}.json`;
|
package/dist/cli/validate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { validateCaCertFile } from "./config.js";
|
|
2
|
-
import { FLAG_BATCH_SIZE, FLAG_CDX, FLAG_CHECK_NETWORK, FLAG_CHECK_OVERRIDES, FLAG_CREATE_PR, FLAG_FIX, FLAG_JSON, FLAG_NO_CACHE, FLAG_OFFLINE, FLAG_OFFLINE_DB, FLAG_OSV_URL, FLAG_REPORT, FLAG_SARIF, FLAG_SBOM, } from "./flags.js";
|
|
2
|
+
import { FLAG_BATCH_SIZE, FLAG_CDX, FLAG_CHECK_LICENSES, FLAG_CHECK_MAINTENANCE, FLAG_CHECK_NETWORK, FLAG_CHECK_OVERRIDES, FLAG_CREATE_PR, FLAG_FIX, FLAG_JSON, FLAG_NO_CACHE, FLAG_OFFLINE, FLAG_OFFLINE_DB, FLAG_ONLY_USED, FLAG_OSV_URL, FLAG_PYTHON, FLAG_REPORT, FLAG_SARIF, FLAG_SBOM, FLAG_SEARCH_DEPTH, FLAG_USAGE, } from "./flags.js";
|
|
3
3
|
import { validateOsvUrl } from "../utils/validate-url.js";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveSbomFormats } from "../utils/sbom-format.js";
|
|
5
5
|
import { isOutputFile, isOutputStdout } from "../output/output-dir.js";
|
|
6
6
|
function conflictMessage(flag, withFlag) {
|
|
7
7
|
return `${flag} cannot be used with ${withFlag}.`;
|
|
@@ -19,6 +19,42 @@ export async function validateOptions(options) {
|
|
|
19
19
|
throw new Error(`${FLAG_BATCH_SIZE} must be a positive integer`);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
if (options.searchDepth !== undefined && options.searchDepth !== "") {
|
|
23
|
+
if (!/^[0-9]+$/.test(options.searchDepth)) {
|
|
24
|
+
throw new Error(`${FLAG_SEARCH_DEPTH} must be a non-negative integer`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (options.python) {
|
|
28
|
+
if (options.checkLicenses) {
|
|
29
|
+
throw new Error(conflictMessage(FLAG_CHECK_LICENSES, FLAG_PYTHON));
|
|
30
|
+
}
|
|
31
|
+
if (options.checkMaintenance) {
|
|
32
|
+
throw new Error(conflictMessage(FLAG_CHECK_MAINTENANCE, FLAG_PYTHON));
|
|
33
|
+
}
|
|
34
|
+
if (options.checkOverrides) {
|
|
35
|
+
throw new Error(conflictMessage(FLAG_CHECK_OVERRIDES, FLAG_PYTHON));
|
|
36
|
+
}
|
|
37
|
+
if (options.fix) {
|
|
38
|
+
throw new Error(conflictMessage(FLAG_FIX, FLAG_PYTHON));
|
|
39
|
+
}
|
|
40
|
+
if (options.createPr) {
|
|
41
|
+
throw new Error(conflictMessage(FLAG_CREATE_PR, FLAG_PYTHON));
|
|
42
|
+
}
|
|
43
|
+
// --only-used also sets usage, so name the flag the user actually typed first.
|
|
44
|
+
if (options.onlyUsed) {
|
|
45
|
+
throw new Error(conflictMessage(FLAG_ONLY_USED, FLAG_PYTHON));
|
|
46
|
+
}
|
|
47
|
+
if (options.usage) {
|
|
48
|
+
throw new Error(conflictMessage(FLAG_USAGE, FLAG_PYTHON));
|
|
49
|
+
}
|
|
50
|
+
if (resolveSbomFormats(options).length > 0) {
|
|
51
|
+
const flag = options.cdx ? FLAG_CDX : FLAG_SBOM;
|
|
52
|
+
throw new Error(conflictMessage(flag, FLAG_PYTHON));
|
|
53
|
+
}
|
|
54
|
+
if (options.offline || options.offlineDb) {
|
|
55
|
+
throw new Error("Offline mode is not supported for Python scans: the local advisory database only contains npm advisories.");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
22
58
|
if (options.allowPrivateOsvUrl && !options.osvUrl) {
|
|
23
59
|
throw new Error(`${requiresMessage("--allow-private-osv-url", "--osv-url")} Provide a custom OSV endpoint with --osv-url, or remove --allow-private-osv-url.`);
|
|
24
60
|
}
|
|
@@ -48,7 +84,8 @@ export async function validateOptions(options) {
|
|
|
48
84
|
if (options.fix && options.sarif) {
|
|
49
85
|
throw new Error(`${conflictMessage(FLAG_FIX, FLAG_SARIF)} Use --fix to apply validated fixes and rescan, or --sarif to save scan results as SARIF, not both.`);
|
|
50
86
|
}
|
|
51
|
-
|
|
87
|
+
const sbomFormats = resolveSbomFormats(options);
|
|
88
|
+
if (options.fix && sbomFormats.length > 0) {
|
|
52
89
|
// Name the flag the user actually typed: --cdx is an alias for --sbom cyclonedx.
|
|
53
90
|
const flag = options.cdx ? FLAG_CDX : FLAG_SBOM;
|
|
54
91
|
const what = options.cdx ? "a CycloneDX SBOM" : "an SBOM";
|
|
@@ -63,12 +100,12 @@ export async function validateOptions(options) {
|
|
|
63
100
|
if (options.report && options.json) {
|
|
64
101
|
throw new Error(`${conflictMessage(FLAG_REPORT, FLAG_JSON)} Use --report to generate an HTML report, or --json to save scan results as JSON, not both.`);
|
|
65
102
|
}
|
|
66
|
-
if (options.output && !(options.json || options.sarif ||
|
|
103
|
+
if (options.output && !(options.json || options.sarif || sbomFormats.length > 0)) {
|
|
67
104
|
throw new Error("--output requires --json, --sarif or --sbom. Add one of them to write a file into the output directory, or remove --output.");
|
|
68
105
|
}
|
|
69
106
|
const fileOutputsCount = (options.json ? 1 : 0) +
|
|
70
107
|
(options.sarif ? 1 : 0) +
|
|
71
|
-
|
|
108
|
+
sbomFormats.length;
|
|
72
109
|
if (isOutputStdout(options.output) && options.report) {
|
|
73
110
|
throw new Error("--output cannot be stdout when --report is specified. Remove --report or select a file output target.");
|
|
74
111
|
}
|
|
@@ -77,6 +114,9 @@ export async function validateOptions(options) {
|
|
|
77
114
|
throw new Error("--output cannot be a file path when multiple output formats are specified. Use an output directory instead.");
|
|
78
115
|
}
|
|
79
116
|
if (isOutputStdout(options.output)) {
|
|
117
|
+
if (sbomFormats.length > 1 && !options.json && !options.sarif) {
|
|
118
|
+
throw new Error("--output cannot be stdout when multiple output formats are specified. Specify a single --sbom format, or use an output directory.");
|
|
119
|
+
}
|
|
80
120
|
throw new Error("--output cannot be stdout when multiple output formats are specified. Specify only one of --json, --sarif or --sbom, or use an output directory.");
|
|
81
121
|
}
|
|
82
122
|
}
|
package/dist/constants.js
CHANGED
|
@@ -10,6 +10,8 @@ export const RATCHET_BASELINE_COMMIT_HINT = "to accept the existing debt; until
|
|
|
10
10
|
export const DEFAULT_BATCH_SIZE = 100;
|
|
11
11
|
export const DEFAULT_SEARCH_DEPTH = 4;
|
|
12
12
|
export const CACHE_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
|
13
|
+
export const DEFAULT_OSV_URL = "https://api.osv.dev";
|
|
14
|
+
export const DEFAULT_OSV_NPM_DUMP_URL = "https://storage.googleapis.com/osv-vulnerabilities/npm/all.zip";
|
|
13
15
|
export const NPM_PUBLIC_REGISTRY = "https://registry.npmjs.org/";
|
|
14
16
|
export const MAL_PRIVATE_REGISTRY_MESSAGE = "This package has a MAL- advisory but resolved from a private registry - unverifiable whether this advisory applies to your artifact. Inspect the source manually.";
|
|
15
17
|
export const MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE = "MAL- advisory could not be confirmed for this artifact.";
|
|
@@ -33,6 +35,14 @@ export const LOCKFILE_NAMES = [
|
|
|
33
35
|
"pnpm-lock.yaml",
|
|
34
36
|
"yarn.lock",
|
|
35
37
|
];
|
|
38
|
+
/** The package manager that writes each supported lockfile. */
|
|
39
|
+
export const PACKAGE_MANAGER_BY_LOCKFILE = {
|
|
40
|
+
"bun.lock": "bun",
|
|
41
|
+
"npm-shrinkwrap.json": "npm",
|
|
42
|
+
"package-lock.json": "npm",
|
|
43
|
+
"pnpm-lock.yaml": "pnpm",
|
|
44
|
+
"yarn.lock": "yarn",
|
|
45
|
+
};
|
|
36
46
|
/**
|
|
37
47
|
* Precedence when several lockfiles sit at the repo root.
|
|
38
48
|
*/
|