cve-lite-cli 1.39.0 → 1.41.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 +28 -22
- package/dist/advisory/local-advisory-source.js +9 -5
- package/dist/advisory/local-db.js +91 -13
- package/dist/advisory/osv-sync.js +187 -56
- package/dist/advisory/staging-directory.js +112 -0
- package/dist/cli/advisories-sync.js +16 -2
- package/dist/cli/args.js +46 -35
- package/dist/cli/config.js +4 -1
- package/dist/cli/help.js +5 -3
- package/dist/cli/validate.js +23 -1
- package/dist/constants.js +15 -28
- package/dist/index.js +8 -3
- package/dist/osv/severity.js +1 -1
- package/dist/output/cyclonedx.js +24 -15
- package/dist/output/debug.js +68 -18
- package/dist/output/formatters.js +35 -7
- package/dist/output/html-reporter.js +68 -12
- package/dist/output/multi-folder-html-reporter.js +71 -11
- package/dist/output/output-dir.js +193 -7
- package/dist/output/override-findings-html.js +3 -6
- package/dist/output/override-findings-terminal.js +7 -12
- package/dist/output/override-fix-command.js +13 -0
- package/dist/output/printers.js +27 -12
- package/dist/output/sarif.js +168 -57
- package/dist/output/sbom-dependency-edges.js +16 -10
- package/dist/output/sbom-file.js +14 -6
- package/dist/output/scan-json.js +46 -3
- package/dist/output/spdx.js +61 -23
- package/dist/output/spinner.js +2 -1
- package/dist/output/write-outputs.js +143 -41
- package/dist/overrides/context-builder.js +23 -70
- package/dist/overrides/parsing/registry.js +1 -1
- package/dist/parsers/bun-lock.js +1 -2
- package/dist/parsers/index.js +22 -1
- package/dist/parsers/npm-lock-graph.js +39 -1
- package/dist/parsers/package-lock.js +25 -5
- package/dist/parsers/pnpm-lock.js +26 -12
- package/dist/parsers/utils.js +5 -3
- package/dist/parsers/yarn-lock-graph.js +5 -2
- package/dist/parsers/yarn-lock.js +1 -2
- package/dist/remediation/fix-commands.js +140 -50
- package/dist/remediation/npm-registry.js +56 -7
- package/dist/remediation/npm-transitive-graph.js +30 -72
- package/dist/remediation/npm-transitive-resolution.js +35 -107
- package/dist/remediation/parent-candidate-resolver.js +65 -0
- package/dist/remediation/parent-upgrade-blockers.js +51 -0
- package/dist/remediation/parent-upgrade.js +11 -116
- package/dist/remediation/registry-parent-ranges.js +21 -0
- package/dist/remediation/transitive-chain-resolver.js +3 -3
- package/dist/scan/completeness.js +17 -11
- package/dist/scan/multi-folder-scan.js +154 -59
- package/dist/scan/override-audit.js +11 -1
- package/dist/scan/single-scan.js +123 -67
- package/dist/scanner.js +288 -66
- package/dist/skills/content.js +12 -12
- package/dist/usage/scanner.js +19 -8
- package/dist/utils/array.js +11 -3
- package/dist/utils/contextual-signals.js +1 -1
- package/dist/utils/debug-bundle.js +118 -0
- package/dist/utils/debug-project.js +102 -0
- package/dist/utils/debug-redaction.js +117 -0
- package/dist/utils/effective-options.js +55 -0
- package/dist/utils/file.js +2 -1
- package/dist/utils/finding.js +1 -1
- package/dist/utils/fix-runner.js +98 -15
- package/dist/utils/import-type-queries.js +322 -0
- package/dist/utils/network.js +14 -10
- package/dist/utils/npm-lockfile.js +12 -0
- package/dist/utils/osv-fetch.js +70 -0
- package/dist/utils/package-identity.js +43 -0
- package/dist/utils/package-manager-source.js +24 -0
- package/dist/utils/purl.js +37 -0
- package/dist/utils/registry-config.js +129 -0
- package/dist/utils/severity.js +8 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/validate-url.js +4 -4
- package/dist/utils/version.js +47 -8
- package/dist/utils/versions/osv-range.js +191 -0
- package/dist/utils/versions/pep440.js +246 -0
- package/dist/utils/versions/scheme.js +10 -0
- package/dist/utils/vuln.js +75 -0
- package/package.json +3 -2
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { ensureSentence } from "../utils/string.js";
|
|
6
|
+
const OWNER_FILE = "owner.json";
|
|
7
|
+
export function stagingDirectoryPrefix(dbPath) {
|
|
8
|
+
return path.join(path.dirname(dbPath), `.${path.basename(dbPath)}.tmp-${process.pid}-`);
|
|
9
|
+
}
|
|
10
|
+
/** Called after the caller records the directory, so finally also covers write failures. */
|
|
11
|
+
export function recordStagingOwner(tempDir, dbPath) {
|
|
12
|
+
const owner = {
|
|
13
|
+
version: 1,
|
|
14
|
+
pid: process.pid,
|
|
15
|
+
hostname: os.hostname(),
|
|
16
|
+
dbPath,
|
|
17
|
+
directoryName: path.basename(tempDir),
|
|
18
|
+
};
|
|
19
|
+
fs.writeFileSync(path.join(tempDir, OWNER_FILE), JSON.stringify(owner), { flag: "wx", mode: 0o600 });
|
|
20
|
+
}
|
|
21
|
+
function readOwner(directory, dbPath) {
|
|
22
|
+
const entry = fs.lstatSync(directory);
|
|
23
|
+
if (!entry.isDirectory() || entry.isSymbolicLink())
|
|
24
|
+
return null;
|
|
25
|
+
const metadata = fs.lstatSync(path.join(directory, OWNER_FILE));
|
|
26
|
+
if (!metadata.isFile() || metadata.isSymbolicLink())
|
|
27
|
+
return null;
|
|
28
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(directory, OWNER_FILE), "utf8"));
|
|
29
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
30
|
+
return null;
|
|
31
|
+
const owner = parsed;
|
|
32
|
+
if (owner.version !== 1 || !Number.isSafeInteger(owner.pid) || owner.pid <= 0 || owner.pid > 2147483647)
|
|
33
|
+
return null;
|
|
34
|
+
if (owner.hostname !== os.hostname() || owner.dbPath !== dbPath || typeof owner.directoryName !== "string")
|
|
35
|
+
return null;
|
|
36
|
+
const prefix = `.${path.basename(dbPath)}.tmp-${owner.pid}-`;
|
|
37
|
+
if (!owner.directoryName.startsWith(prefix) || path.basename(owner.directoryName) !== owner.directoryName)
|
|
38
|
+
return null;
|
|
39
|
+
const name = path.basename(directory);
|
|
40
|
+
if (name !== owner.directoryName && !name.startsWith(`${owner.directoryName}.cleanup-`))
|
|
41
|
+
return null;
|
|
42
|
+
// On POSIX, do not sweep another user's staging directory, even with matching metadata.
|
|
43
|
+
if (process.getuid && (entry.uid !== process.getuid() || metadata.uid !== process.getuid()))
|
|
44
|
+
return null;
|
|
45
|
+
return owner;
|
|
46
|
+
}
|
|
47
|
+
function ownerHasExited(pid) {
|
|
48
|
+
try {
|
|
49
|
+
process.kill(pid, 0);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
// EPERM and any unfamiliar error mean the process may still be active.
|
|
54
|
+
return error.code === "ESRCH";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function removeAbandonedDirectory(directory, dbPath) {
|
|
58
|
+
const before = fs.lstatSync(directory);
|
|
59
|
+
const owner = readOwner(directory, dbPath);
|
|
60
|
+
if (owner === null || !ownerHasExited(owner.pid))
|
|
61
|
+
return;
|
|
62
|
+
if (path.basename(directory) !== owner.directoryName) {
|
|
63
|
+
const claim = path.basename(directory).match(/\.cleanup-([1-9]\d*)-[\da-f-]{36}$/i);
|
|
64
|
+
if (claim === null || !ownerHasExited(Number(claim[1])))
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const current = fs.lstatSync(directory);
|
|
68
|
+
if (current.dev !== before.dev || current.ino !== before.ino)
|
|
69
|
+
return;
|
|
70
|
+
const claimedPath = path.join(path.dirname(directory), `${owner.directoryName}.cleanup-${process.pid}-${randomUUID()}`);
|
|
71
|
+
// A claim avoids two scavengers recursively removing the same directory.
|
|
72
|
+
fs.renameSync(directory, claimedPath);
|
|
73
|
+
const claimed = fs.lstatSync(claimedPath);
|
|
74
|
+
const claimedOwner = readOwner(claimedPath, dbPath);
|
|
75
|
+
if (claimed.dev !== before.dev || claimed.ino !== before.ino || claimedOwner === null || !ownerHasExited(claimedOwner.pid))
|
|
76
|
+
return;
|
|
77
|
+
try {
|
|
78
|
+
fs.rmSync(claimedPath, { recursive: true, force: true });
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
throw new Error(`Could not remove abandoned advisory sync directory ${claimedPath}: ${ensureSentence(error instanceof Error ? error.message : String(error))} Resolve the filesystem error and remove it manually once no sync is using it.`, { cause: error });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Never infer ownership from a glob or age: legacy/unverifiable directories are left alone. */
|
|
85
|
+
export function cleanupAbandonedStagingDirectories(dbPath) {
|
|
86
|
+
const warnings = [];
|
|
87
|
+
const parent = path.dirname(dbPath);
|
|
88
|
+
const prefix = `.${path.basename(dbPath)}.tmp-`;
|
|
89
|
+
let entries;
|
|
90
|
+
try {
|
|
91
|
+
entries = fs.readdirSync(parent, { withFileTypes: true });
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return [`Could not inspect abandoned advisory sync directories in ${parent}: ${ensureSentence(error instanceof Error ? error.message : String(error))} Check directory permissions and remove abandoned staging files manually once no sync is using them.`];
|
|
95
|
+
}
|
|
96
|
+
for (const entry of entries) {
|
|
97
|
+
if (!entry.isDirectory() || entry.isSymbolicLink() || !entry.name.startsWith(prefix))
|
|
98
|
+
continue;
|
|
99
|
+
const directory = path.join(parent, entry.name);
|
|
100
|
+
try {
|
|
101
|
+
removeAbandonedDirectory(directory, dbPath);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error.code === "ENOENT" || error instanceof SyntaxError)
|
|
105
|
+
continue;
|
|
106
|
+
warnings.push(error instanceof Error && error.message.startsWith("Could not remove abandoned advisory sync directory")
|
|
107
|
+
? error.message
|
|
108
|
+
: `Could not inspect abandoned advisory sync directory ${directory}: ${ensureSentence(error instanceof Error ? error.message : String(error))} Check this directory and remove it manually only when no sync is using it.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return warnings;
|
|
112
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { AdvisorySyncError, getDefaultAdvisoryDbPath, syncOsvAdvisories } from "../advisory/osv-sync.js";
|
|
4
|
+
import { logWarn } from "../output/formatters.js";
|
|
3
5
|
import { createSpinner } from "../output/spinner.js";
|
|
4
6
|
import { chalk } from "../utils/chalk.js";
|
|
5
|
-
import { pluralize } from "../utils/string.js";
|
|
7
|
+
import { ensureSentence, pluralize } from "../utils/string.js";
|
|
6
8
|
export async function runAdvisoriesSync({ options, fetchImpl }) {
|
|
9
|
+
const databaseExisted = fs.existsSync(getDefaultAdvisoryDbPath(options.output));
|
|
7
10
|
const spinner = createSpinner("Preparing advisory sync...", options);
|
|
8
11
|
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
9
12
|
const result = await syncOsvAdvisories({
|
|
@@ -19,7 +22,18 @@ export async function runAdvisoriesSync({ options, fetchImpl }) {
|
|
|
19
22
|
}
|
|
20
23
|
spinner.update(event.message);
|
|
21
24
|
},
|
|
25
|
+
}).catch((error) => {
|
|
26
|
+
spinner.stop();
|
|
27
|
+
if (error instanceof AdvisorySyncError && error.databaseState === "unchanged") {
|
|
28
|
+
const stateMessage = databaseExisted
|
|
29
|
+
? "The existing advisory database was not changed."
|
|
30
|
+
: "No advisory database was created.";
|
|
31
|
+
throw new Error(`${ensureSentence(error.message)} ${stateMessage}`, { cause: error });
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
22
34
|
});
|
|
35
|
+
for (const warning of result.warnings ?? [])
|
|
36
|
+
logWarn(warning, { json: options.json });
|
|
23
37
|
if (usePlainProgressLogs) {
|
|
24
38
|
console.log(`Advisory sync complete (${result.advisoryCount} records)`);
|
|
25
39
|
}
|
package/dist/cli/args.js
CHANGED
|
@@ -10,9 +10,27 @@ export const SBOM_FORMAT_ALIASES = {
|
|
|
10
10
|
spdx: "spdx",
|
|
11
11
|
"spdx2.3": "spdx",
|
|
12
12
|
};
|
|
13
|
+
/** Severities `--fail-on` accepts, matched case-insensitively. */
|
|
14
|
+
export const FAIL_ON_SEVERITIES = ["critical", "high", "medium", "low"];
|
|
15
|
+
function parseFailOn(value) {
|
|
16
|
+
const valid = FAIL_ON_SEVERITIES.join(", ");
|
|
17
|
+
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
18
|
+
throw new Error(`--fail-on requires a severity. Valid severities: ${valid}.`);
|
|
19
|
+
}
|
|
20
|
+
if (!FAIL_ON_SEVERITIES.includes(value.toLowerCase())) {
|
|
21
|
+
throw new Error(`Unknown --fail-on severity "${value}". Valid severities: ${valid}.`);
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function requireFlagValue(flag, value, noun) {
|
|
26
|
+
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
27
|
+
throw new Error(`${flag} requires a ${noun} argument`);
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
13
31
|
function parseSbomFormat(value) {
|
|
14
32
|
const valid = Object.keys(SBOM_FORMAT_ALIASES).join(", ");
|
|
15
|
-
if (value === undefined || value.startsWith("-")) {
|
|
33
|
+
if (value === undefined || value === "" || value.startsWith("-")) {
|
|
16
34
|
throw new Error(`--sbom requires a format. Valid formats: ${valid}.`);
|
|
17
35
|
}
|
|
18
36
|
const format = SBOM_FORMAT_ALIASES[value.toLowerCase()];
|
|
@@ -124,13 +142,10 @@ export function parseArgs(argv) {
|
|
|
124
142
|
}
|
|
125
143
|
if (sub === ConfigAction.Set) {
|
|
126
144
|
const key = argv[2];
|
|
127
|
-
const value = argv[3];
|
|
128
145
|
if (key !== ConfigKey.CaCert) {
|
|
129
146
|
throw new Error(`Unknown config key: ${key ?? "(none)"}. Valid keys: ${ConfigKey.CaCert}`);
|
|
130
147
|
}
|
|
131
|
-
|
|
132
|
-
throw new Error(`cve-lite config set ${ConfigKey.CaCert} requires a path argument`);
|
|
133
|
-
}
|
|
148
|
+
const value = requireFlagValue(`cve-lite config set ${ConfigKey.CaCert}`, argv[3], "path");
|
|
134
149
|
return { command: "config", options, configSubcommand: { action: ConfigAction.Set, key: ConfigKey.CaCert, value } };
|
|
135
150
|
}
|
|
136
151
|
if (sub === ConfigAction.Unset) {
|
|
@@ -167,27 +182,27 @@ export function parseArgs(argv) {
|
|
|
167
182
|
continue;
|
|
168
183
|
}
|
|
169
184
|
if (arg === FLAG_AUDIT_LOG) {
|
|
170
|
-
options.auditLog = argv[++i];
|
|
185
|
+
options.auditLog = requireFlagValue(FLAG_AUDIT_LOG, argv[++i], "path");
|
|
171
186
|
continue;
|
|
172
187
|
}
|
|
173
188
|
if (arg.startsWith(`${FLAG_AUDIT_LOG}=`)) {
|
|
174
|
-
options.auditLog = arg.slice(FLAG_AUDIT_LOG.length + 1);
|
|
189
|
+
options.auditLog = requireFlagValue(FLAG_AUDIT_LOG, arg.slice(FLAG_AUDIT_LOG.length + 1), "path");
|
|
175
190
|
continue;
|
|
176
191
|
}
|
|
177
192
|
if (arg === FLAG_RULE) {
|
|
178
|
-
options.rule = argv[++i];
|
|
193
|
+
options.rule = requireFlagValue(FLAG_RULE, argv[++i], "rule id");
|
|
179
194
|
continue;
|
|
180
195
|
}
|
|
181
196
|
if (arg.startsWith(`${FLAG_RULE}=`)) {
|
|
182
|
-
options.rule = arg.slice(FLAG_RULE.length + 1);
|
|
197
|
+
options.rule = requireFlagValue(FLAG_RULE, arg.slice(FLAG_RULE.length + 1), "rule id");
|
|
183
198
|
continue;
|
|
184
199
|
}
|
|
185
200
|
if (arg === FLAG_FAIL_ON) {
|
|
186
|
-
options.failOn = argv[++i]
|
|
201
|
+
options.failOn = parseFailOn(argv[++i]);
|
|
187
202
|
continue;
|
|
188
203
|
}
|
|
189
204
|
if (arg.startsWith(`${FLAG_FAIL_ON}=`)) {
|
|
190
|
-
options.failOn = arg.slice(FLAG_FAIL_ON.length + 1);
|
|
205
|
+
options.failOn = parseFailOn(arg.slice(FLAG_FAIL_ON.length + 1));
|
|
191
206
|
continue;
|
|
192
207
|
}
|
|
193
208
|
if (arg.startsWith("-")) {
|
|
@@ -261,11 +276,11 @@ export function parseArgs(argv) {
|
|
|
261
276
|
continue;
|
|
262
277
|
}
|
|
263
278
|
if (arg === FLAG_OFFLINE_DB) {
|
|
264
|
-
options.offlineDb = argv[++i];
|
|
279
|
+
options.offlineDb = requireFlagValue(FLAG_OFFLINE_DB, argv[++i], "path");
|
|
265
280
|
continue;
|
|
266
281
|
}
|
|
267
282
|
if (arg.startsWith(`${FLAG_OFFLINE_DB}=`)) {
|
|
268
|
-
options.offlineDb = arg.slice(FLAG_OFFLINE_DB.length + 1);
|
|
283
|
+
options.offlineDb = requireFlagValue(FLAG_OFFLINE_DB, arg.slice(FLAG_OFFLINE_DB.length + 1), "path");
|
|
269
284
|
continue;
|
|
270
285
|
}
|
|
271
286
|
if (arg === FLAG_ALL) {
|
|
@@ -273,35 +288,35 @@ export function parseArgs(argv) {
|
|
|
273
288
|
continue;
|
|
274
289
|
}
|
|
275
290
|
if (arg === FLAG_FAIL_ON) {
|
|
276
|
-
options.failOn = argv[++i]
|
|
291
|
+
options.failOn = parseFailOn(argv[++i]);
|
|
277
292
|
continue;
|
|
278
293
|
}
|
|
279
294
|
if (arg.startsWith(`${FLAG_FAIL_ON}=`)) {
|
|
280
|
-
options.failOn = arg.slice(FLAG_FAIL_ON.length + 1);
|
|
295
|
+
options.failOn = parseFailOn(arg.slice(FLAG_FAIL_ON.length + 1));
|
|
281
296
|
continue;
|
|
282
297
|
}
|
|
283
298
|
if (arg === FLAG_BATCH_SIZE) {
|
|
284
|
-
options.batchSize = argv[++i]
|
|
299
|
+
options.batchSize = requireFlagValue(FLAG_BATCH_SIZE, argv[++i], "number");
|
|
285
300
|
continue;
|
|
286
301
|
}
|
|
287
302
|
if (arg.startsWith(`${FLAG_BATCH_SIZE}=`)) {
|
|
288
|
-
options.batchSize = arg.slice(FLAG_BATCH_SIZE.length + 1);
|
|
303
|
+
options.batchSize = requireFlagValue(FLAG_BATCH_SIZE, arg.slice(FLAG_BATCH_SIZE.length + 1), "number");
|
|
289
304
|
continue;
|
|
290
305
|
}
|
|
291
306
|
if (arg === FLAG_CACHE_DIR) {
|
|
292
|
-
options.cacheDir = argv[++i];
|
|
307
|
+
options.cacheDir = requireFlagValue(FLAG_CACHE_DIR, argv[++i], "path");
|
|
293
308
|
continue;
|
|
294
309
|
}
|
|
295
310
|
if (arg.startsWith(`${FLAG_CACHE_DIR}=`)) {
|
|
296
|
-
options.cacheDir = arg.slice(FLAG_CACHE_DIR.length + 1);
|
|
311
|
+
options.cacheDir = requireFlagValue(FLAG_CACHE_DIR, arg.slice(FLAG_CACHE_DIR.length + 1), "path");
|
|
297
312
|
continue;
|
|
298
313
|
}
|
|
299
314
|
if (arg === FLAG_OSV_URL) {
|
|
300
|
-
options.osvUrl = argv[++i];
|
|
315
|
+
options.osvUrl = requireFlagValue(FLAG_OSV_URL, argv[++i], "url");
|
|
301
316
|
continue;
|
|
302
317
|
}
|
|
303
318
|
if (arg.startsWith(`${FLAG_OSV_URL}=`)) {
|
|
304
|
-
options.osvUrl = arg.slice(FLAG_OSV_URL.length + 1);
|
|
319
|
+
options.osvUrl = requireFlagValue(FLAG_OSV_URL, arg.slice(FLAG_OSV_URL.length + 1), "url");
|
|
305
320
|
continue;
|
|
306
321
|
}
|
|
307
322
|
if (arg === FLAG_ALLOW_PRIVATE_OSV_URL) {
|
|
@@ -310,7 +325,7 @@ export function parseArgs(argv) {
|
|
|
310
325
|
}
|
|
311
326
|
if (arg === FLAG_OUTPUT) {
|
|
312
327
|
const val = argv[++i];
|
|
313
|
-
if (!val || val.startsWith("-")) {
|
|
328
|
+
if (!val || (val !== "-" && val.startsWith("-"))) {
|
|
314
329
|
throw new Error("--output requires a directory argument");
|
|
315
330
|
}
|
|
316
331
|
options.output = val;
|
|
@@ -318,26 +333,26 @@ export function parseArgs(argv) {
|
|
|
318
333
|
}
|
|
319
334
|
if (arg.startsWith(`${FLAG_OUTPUT}=`)) {
|
|
320
335
|
const val = arg.slice(FLAG_OUTPUT.length + 1);
|
|
321
|
-
if (!val || val.startsWith("-")) {
|
|
336
|
+
if (!val || (val !== "-" && val.startsWith("-"))) {
|
|
322
337
|
throw new Error("--output requires a directory argument");
|
|
323
338
|
}
|
|
324
339
|
options.output = val;
|
|
325
340
|
continue;
|
|
326
341
|
}
|
|
327
342
|
if (arg === FLAG_SEARCH_DEPTH) {
|
|
328
|
-
options.searchDepth = argv[++i]
|
|
343
|
+
options.searchDepth = requireFlagValue(FLAG_SEARCH_DEPTH, argv[++i], "number");
|
|
329
344
|
continue;
|
|
330
345
|
}
|
|
331
346
|
if (arg.startsWith(`${FLAG_SEARCH_DEPTH}=`)) {
|
|
332
|
-
options.searchDepth = arg.slice(FLAG_SEARCH_DEPTH.length + 1);
|
|
347
|
+
options.searchDepth = requireFlagValue(FLAG_SEARCH_DEPTH, arg.slice(FLAG_SEARCH_DEPTH.length + 1), "number");
|
|
333
348
|
continue;
|
|
334
349
|
}
|
|
335
350
|
if (arg === FLAG_MIN_SEVERITY) {
|
|
336
|
-
options.minSeverity = argv[++i]
|
|
351
|
+
options.minSeverity = requireFlagValue(FLAG_MIN_SEVERITY, argv[++i], "level");
|
|
337
352
|
continue;
|
|
338
353
|
}
|
|
339
354
|
if (arg.startsWith(`${FLAG_MIN_SEVERITY}=`)) {
|
|
340
|
-
options.minSeverity = arg.slice(FLAG_MIN_SEVERITY.length + 1);
|
|
355
|
+
options.minSeverity = requireFlagValue(FLAG_MIN_SEVERITY, arg.slice(FLAG_MIN_SEVERITY.length + 1), "level");
|
|
341
356
|
continue;
|
|
342
357
|
}
|
|
343
358
|
if (arg === FLAG_USAGE || arg === FLAG_USAGE_HINTS) {
|
|
@@ -373,15 +388,11 @@ export function parseArgs(argv) {
|
|
|
373
388
|
continue;
|
|
374
389
|
}
|
|
375
390
|
if (arg === FLAG_CA_CERT) {
|
|
376
|
-
|
|
377
|
-
if (!val) {
|
|
378
|
-
throw new Error("--ca-cert requires a path argument");
|
|
379
|
-
}
|
|
380
|
-
options.caCert = val;
|
|
391
|
+
options.caCert = requireFlagValue(FLAG_CA_CERT, argv[++i], "path");
|
|
381
392
|
continue;
|
|
382
393
|
}
|
|
383
394
|
if (arg.startsWith(`${FLAG_CA_CERT}=`)) {
|
|
384
|
-
options.caCert = arg.slice(FLAG_CA_CERT.length + 1);
|
|
395
|
+
options.caCert = requireFlagValue(FLAG_CA_CERT, arg.slice(FLAG_CA_CERT.length + 1), "path");
|
|
385
396
|
continue;
|
|
386
397
|
}
|
|
387
398
|
if (arg === FLAG_SARIF) {
|
|
@@ -407,11 +418,11 @@ export function parseArgs(argv) {
|
|
|
407
418
|
continue;
|
|
408
419
|
}
|
|
409
420
|
if (arg === FLAG_AUDIT_LOG) {
|
|
410
|
-
options.auditLog = argv[++i];
|
|
421
|
+
options.auditLog = requireFlagValue(FLAG_AUDIT_LOG, argv[++i], "path");
|
|
411
422
|
continue;
|
|
412
423
|
}
|
|
413
424
|
if (arg.startsWith(`${FLAG_AUDIT_LOG}=`)) {
|
|
414
|
-
options.auditLog = arg.slice(FLAG_AUDIT_LOG.length + 1);
|
|
425
|
+
options.auditLog = requireFlagValue(FLAG_AUDIT_LOG, arg.slice(FLAG_AUDIT_LOG.length + 1), "path");
|
|
415
426
|
continue;
|
|
416
427
|
}
|
|
417
428
|
if (arg === FLAG_CHECK_OVERRIDES) {
|
package/dist/cli/config.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import { chalk } from "../utils/chalk.js";
|
|
6
6
|
import { createCertAwareFetch } from "../utils/network.js";
|
|
7
|
+
import { createOsvFetch } from "../utils/osv-fetch.js";
|
|
7
8
|
export const ConfigAction = {
|
|
8
9
|
Set: "set",
|
|
9
10
|
Unset: "unset",
|
|
@@ -91,5 +92,7 @@ export function setupCaCert(options, debugLog) {
|
|
|
91
92
|
nodeExtraCaCerts: process.env.NODE_EXTRA_CA_CERTS ?? null,
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
|
-
return
|
|
95
|
+
return options.osvUrl
|
|
96
|
+
? createOsvFetch(options.osvUrl, !!options.allowPrivateOsvUrl, resolvedCaCert)
|
|
97
|
+
: certFetch;
|
|
95
98
|
}
|
package/dist/cli/help.js
CHANGED
|
@@ -2,6 +2,7 @@ import { chalk } from "../utils/chalk.js";
|
|
|
2
2
|
import { getCliVersion } from "../utils/version-info.js";
|
|
3
3
|
import { checkForUpdate } from "../utils/update-check.js";
|
|
4
4
|
import { OVERRIDES_COMMAND } from "../constants.js";
|
|
5
|
+
import { isOutputStdout } from "../output/output-dir.js";
|
|
5
6
|
const CLI_VERSION = getCliVersion();
|
|
6
7
|
const CLI_BANNER = [
|
|
7
8
|
`${chalk.green(">_")} ${chalk.bold.whiteBright(`CVE Lite CLI (${CLI_VERSION})`)}`,
|
|
@@ -13,7 +14,7 @@ const CLI_BANNER = [
|
|
|
13
14
|
chalk.gray("Fast. Local. Developer-first.")
|
|
14
15
|
].join("\n");
|
|
15
16
|
export function printBanner(options) {
|
|
16
|
-
if (options?.json)
|
|
17
|
+
if (options?.json || isOutputStdout(options?.output))
|
|
17
18
|
return;
|
|
18
19
|
console.log(CLI_BANNER);
|
|
19
20
|
console.log("");
|
|
@@ -37,16 +38,17 @@ export function printHelp() {
|
|
|
37
38
|
" --sbom <format> Write an SBOM: cyclonedx (1.6) or spdx (2.3), to a timestamped file",
|
|
38
39
|
" --sbom-inventory-only Omit the vulnerability overlay from --sbom, leaving a pure inventory",
|
|
39
40
|
" --cdx Alias for --sbom cyclonedx",
|
|
40
|
-
" --output <
|
|
41
|
+
" --output <path> Directory or file path for --json, --sarif and --sbom files (use '-' for stdout; default: current directory)",
|
|
41
42
|
" --no-open Don't auto-open the report in the browser",
|
|
42
43
|
" --fix Apply validated direct dependency fixes and rescan",
|
|
43
44
|
" --ratchet Save current findings as baseline or, if baseline exists, only fail on new findings",
|
|
45
|
+
" (the run that saves a baseline still gates on --fail-on)",
|
|
44
46
|
" --create-pr After --fix, commit changes and open a GitHub pull request (requires gh)",
|
|
45
47
|
" --base <branch> Base branch for --create-pr (default: main)",
|
|
46
48
|
" --osv-url <url> Use a custom OSV-compatible advisory endpoint (HTTPS only)",
|
|
47
49
|
" --allow-private-osv-url Allow --osv-url to resolve to private/reserved IPs",
|
|
48
50
|
" --ca-cert <path> Path to a CA certificate file for corporate SSL proxies",
|
|
49
|
-
" --debug Write
|
|
51
|
+
" --debug Write a redacted diagnostic bundle to attach to bug reports",
|
|
50
52
|
" --verbose Show detailed output with fix plan, paths, and full table",
|
|
51
53
|
" --prod-only Exclude dev dependencies where available",
|
|
52
54
|
" --check-overrides Also audit package.json overrides (OA001-OA011, PD001-PD002); findings",
|
package/dist/cli/validate.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { validateCaCertFile } from "./config.js";
|
|
2
|
-
import { 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_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";
|
|
3
3
|
import { validateOsvUrl } from "../utils/validate-url.js";
|
|
4
4
|
import { resolveSbomFormat } from "../utils/sbom-format.js";
|
|
5
|
+
import { isOutputFile, isOutputStdout } from "../output/output-dir.js";
|
|
5
6
|
function conflictMessage(flag, withFlag) {
|
|
6
7
|
return `${flag} cannot be used with ${withFlag}.`;
|
|
7
8
|
}
|
|
@@ -11,6 +12,13 @@ function requiresMessage(flag, requiredFlag) {
|
|
|
11
12
|
return `${flag} requires ${requiredFlag}.`;
|
|
12
13
|
}
|
|
13
14
|
export async function validateOptions(options) {
|
|
15
|
+
// chunk() steps its index by this size. 0 stays put and a negative size walks backward, so either loops until OOM.
|
|
16
|
+
// Missing or empty keeps the default. Anything else must be digits only and at least 1.
|
|
17
|
+
if (options.batchSize !== undefined && options.batchSize !== "") {
|
|
18
|
+
if (!/^[0-9]+$/.test(options.batchSize) || Number(options.batchSize) < 1) {
|
|
19
|
+
throw new Error(`${FLAG_BATCH_SIZE} must be a positive integer`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
14
22
|
if (options.allowPrivateOsvUrl && !options.osvUrl) {
|
|
15
23
|
throw new Error(`${requiresMessage("--allow-private-osv-url", "--osv-url")} Provide a custom OSV endpoint with --osv-url, or remove --allow-private-osv-url.`);
|
|
16
24
|
}
|
|
@@ -58,6 +66,20 @@ export async function validateOptions(options) {
|
|
|
58
66
|
if (options.output && !(options.json || options.sarif || resolveSbomFormat(options))) {
|
|
59
67
|
throw new Error("--output requires --json, --sarif or --sbom. Add one of them to write a file into the output directory, or remove --output.");
|
|
60
68
|
}
|
|
69
|
+
const fileOutputsCount = (options.json ? 1 : 0) +
|
|
70
|
+
(options.sarif ? 1 : 0) +
|
|
71
|
+
(resolveSbomFormat(options) ? 1 : 0);
|
|
72
|
+
if (isOutputStdout(options.output) && options.report) {
|
|
73
|
+
throw new Error("--output cannot be stdout when --report is specified. Remove --report or select a file output target.");
|
|
74
|
+
}
|
|
75
|
+
if (options.output && fileOutputsCount > 1) {
|
|
76
|
+
if (isOutputFile(options.output)) {
|
|
77
|
+
throw new Error("--output cannot be a file path when multiple output formats are specified. Use an output directory instead.");
|
|
78
|
+
}
|
|
79
|
+
if (isOutputStdout(options.output)) {
|
|
80
|
+
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
|
+
}
|
|
82
|
+
}
|
|
61
83
|
if (options.checkNetwork && !options.checkOverrides) {
|
|
62
84
|
throw new Error(`${requiresMessage(FLAG_CHECK_NETWORK, FLAG_CHECK_OVERRIDES)} It lets the network-backed override rules run, so add ${FLAG_CHECK_OVERRIDES}, or remove ${FLAG_CHECK_NETWORK}.`);
|
|
63
85
|
}
|
package/dist/constants.js
CHANGED
|
@@ -6,6 +6,7 @@ export const severityOrder = {
|
|
|
6
6
|
critical: 4,
|
|
7
7
|
unknown: 1
|
|
8
8
|
};
|
|
9
|
+
export const RATCHET_BASELINE_COMMIT_HINT = "to accept the existing debt; until then --ratchet gates like --fail-on.";
|
|
9
10
|
export const DEFAULT_BATCH_SIZE = 100;
|
|
10
11
|
export const DEFAULT_SEARCH_DEPTH = 4;
|
|
11
12
|
export const CACHE_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
|
@@ -13,31 +14,22 @@ export const NPM_PUBLIC_REGISTRY = "https://registry.npmjs.org/";
|
|
|
13
14
|
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.";
|
|
14
15
|
export const MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE = "MAL- advisory could not be confirmed for this artifact.";
|
|
15
16
|
export const MAL_PRIVATE_REGISTRY_LEGEND_MESSAGE = "verify artifact source manually";
|
|
16
|
-
export const MAL_GIT_SOURCE_PINNED_MESSAGE = "Advisory targets registry packages. This package resolves from a git source pinned to a commit SHA
|
|
17
|
-
export const MAL_GIT_SOURCE_FLOATING_MESSAGE = "Advisory targets registry packages. This package resolves from a git source with a floating reference
|
|
18
|
-
export const MAL_GIT_SOURCE_COMPACT_MESSAGE = "Git source
|
|
17
|
+
export const MAL_GIT_SOURCE_PINNED_MESSAGE = "Advisory targets registry packages. This package resolves from a git source pinned to a commit SHA: verify the repository and org are trusted.";
|
|
18
|
+
export const MAL_GIT_SOURCE_FLOATING_MESSAGE = "Advisory targets registry packages. This package resolves from a git source with a floating reference: verify the repository, org, and ref are safe.";
|
|
19
|
+
export const MAL_GIT_SOURCE_COMPACT_MESSAGE = "Git source: verify repository and org are trusted.";
|
|
19
20
|
export const MAL_GIT_SOURCE_LEGEND_MESSAGE = "verify repository and org are trusted";
|
|
20
21
|
export const MAL_GIT_SOURCE_PINNED_DISPLAY = "⚠ Git source (SHA-pinned)";
|
|
21
22
|
export const MAL_GIT_SOURCE_FLOATING_DISPLAY = "⚠ Git source (floating ref)";
|
|
22
|
-
/**
|
|
23
|
-
|
|
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
|
-
*/
|
|
23
|
+
/** npm ignores package-lock.json whenever npm-shrinkwrap.json is present. */
|
|
24
|
+
export const NPM_LOCKFILE_NAMES = ["npm-shrinkwrap.json", "package-lock.json"];
|
|
32
25
|
/**
|
|
33
26
|
* Every lockfile the scanner understands. Order here is not precedence: it only
|
|
34
27
|
* fixes the set and the type. The two precedence lists below are what decide
|
|
35
|
-
* which file wins
|
|
28
|
+
* which file wins.
|
|
36
29
|
*/
|
|
37
30
|
export const LOCKFILE_NAMES = [
|
|
38
31
|
"bun.lock",
|
|
39
|
-
|
|
40
|
-
"package-lock.json",
|
|
32
|
+
...NPM_LOCKFILE_NAMES,
|
|
41
33
|
"pnpm-lock.yaml",
|
|
42
34
|
"yarn.lock",
|
|
43
35
|
];
|
|
@@ -46,30 +38,25 @@ export const LOCKFILE_NAMES = [
|
|
|
46
38
|
*/
|
|
47
39
|
export const LOCKFILE_PRIORITY_ROOT = [
|
|
48
40
|
"bun.lock",
|
|
49
|
-
|
|
50
|
-
"package-lock.json",
|
|
41
|
+
...NPM_LOCKFILE_NAMES,
|
|
51
42
|
"pnpm-lock.yaml",
|
|
52
43
|
"yarn.lock",
|
|
53
44
|
];
|
|
54
45
|
/**
|
|
55
46
|
* Precedence when several lockfiles sit in the same directory below the root.
|
|
56
47
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
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.
|
|
48
|
+
* As at the root, npm-shrinkwrap.json outranks package-lock.json because npm
|
|
49
|
+
* ignores package-lock.json when a shrinkwrap is present.
|
|
62
50
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
51
|
+
* The shrinkwrap now also outranks bun.lock here, unlike root detection, which
|
|
52
|
+
* prefers Bun. The relative order of package-lock.json, pnpm, Yarn and Bun is
|
|
53
|
+
* retained; reconciling the other cross-manager choices is outside #1494.
|
|
66
54
|
*/
|
|
67
55
|
export const LOCKFILE_PRIORITY_NESTED = [
|
|
68
|
-
|
|
56
|
+
...NPM_LOCKFILE_NAMES,
|
|
69
57
|
"pnpm-lock.yaml",
|
|
70
58
|
"yarn.lock",
|
|
71
59
|
"bun.lock",
|
|
72
|
-
"npm-shrinkwrap.json",
|
|
73
60
|
];
|
|
74
61
|
export const EXCLUDED_DIRS = new Set([
|
|
75
62
|
".git",
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,7 @@ if (parsedArgs) {
|
|
|
65
65
|
const searchDepth = Math.max(0, Number(options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
66
66
|
const debugSession = createDebugLogger(!!options.debug);
|
|
67
67
|
const debugLog = debugSession.log;
|
|
68
|
+
let scanJsonPath;
|
|
68
69
|
const scanStartedAt = Date.now();
|
|
69
70
|
const auditLogHandle = createAuditLog(options.auditLog ?? process.env.CVE_LITE_AUDIT_LOG);
|
|
70
71
|
async function main() {
|
|
@@ -133,7 +134,10 @@ if (parsedArgs) {
|
|
|
133
134
|
options,
|
|
134
135
|
fetchImpl: certFetch,
|
|
135
136
|
auditLog: auditLogHandle,
|
|
137
|
+
debugLog,
|
|
138
|
+
onScanJsonPath: (jsonPath) => { scanJsonPath = jsonPath; },
|
|
136
139
|
});
|
|
140
|
+
debugSession.finalize(projectPath, options, scanJsonPath);
|
|
137
141
|
auditLogHandle.close();
|
|
138
142
|
process.exit(exitCode);
|
|
139
143
|
return;
|
|
@@ -149,7 +153,9 @@ if (parsedArgs) {
|
|
|
149
153
|
auditLog: auditLogHandle,
|
|
150
154
|
scanStartedAt,
|
|
151
155
|
cliVersion,
|
|
156
|
+
onScanJsonPath: (jsonPath) => { scanJsonPath = jsonPath; },
|
|
152
157
|
});
|
|
158
|
+
debugSession.finalize(projectPath, options, scanJsonPath);
|
|
153
159
|
auditLogHandle.close();
|
|
154
160
|
process.exit(exitCode);
|
|
155
161
|
return;
|
|
@@ -157,9 +163,7 @@ if (parsedArgs) {
|
|
|
157
163
|
main().catch((error) => {
|
|
158
164
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
159
165
|
console.error(chalk.red(`Error: ${errorMessage}`));
|
|
160
|
-
|
|
161
|
-
debugLog("Unhandled error", { message: error.message, stack: error.stack });
|
|
162
|
-
}
|
|
166
|
+
debugLog("Unhandled error", { message: errorMessage, stack: error instanceof Error ? error.stack : undefined });
|
|
163
167
|
// Emit error event to audit-log
|
|
164
168
|
auditLogHandle.emit({
|
|
165
169
|
ts: new Date().toISOString(),
|
|
@@ -169,6 +173,7 @@ if (parsedArgs) {
|
|
|
169
173
|
message: errorMessage,
|
|
170
174
|
stack: error instanceof Error ? error.stack : undefined,
|
|
171
175
|
});
|
|
176
|
+
debugSession.finalize(projectPath, options, scanJsonPath);
|
|
172
177
|
auditLogHandle.close();
|
|
173
178
|
formatHintLines(getNetworkErrorHint(error, errorMessage)).forEach((line) => console.error(line));
|
|
174
179
|
process.exit(1);
|
package/dist/osv/severity.js
CHANGED
|
@@ -30,7 +30,7 @@ export function inferSeverity(vuln) {
|
|
|
30
30
|
function severityFromScore(score) {
|
|
31
31
|
// CVSS vector strings (e.g. "CVSS:3.1/AV:N/...") are not numerical scores.
|
|
32
32
|
// Extracting the first number would yield the CVSS version (3.1), not the base
|
|
33
|
-
// score
|
|
33
|
+
// score - causing every CVSS_V3 advisory to be misclassified as "low".
|
|
34
34
|
// Return unknown so the caller falls through to database_specific.severity.
|
|
35
35
|
if (String(score).startsWith("CVSS:"))
|
|
36
36
|
return "unknown";
|