cve-lite-cli 1.41.4 → 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/usage/scanner.js +345 -45
- 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
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH } from "../constants.js";
|
|
2
|
+
/** How deep nested lockfile discovery searches, resolved as the CLI resolves it. */
|
|
3
|
+
export function resolveSearchDepth(options) {
|
|
4
|
+
return Math.max(0, Number(options.searchDepth || DEFAULT_SEARCH_DEPTH));
|
|
5
|
+
}
|
|
2
6
|
export function summarizeEffectiveOptions(options) {
|
|
3
7
|
const summary = {
|
|
4
8
|
json: options.json ?? false,
|
|
@@ -26,7 +30,7 @@ export function summarizeEffectiveOptions(options) {
|
|
|
26
30
|
incompletePolicy: options.incompletePolicy,
|
|
27
31
|
// Same normalization as the CLI entrypoint (src/index.ts).
|
|
28
32
|
batchSize: Number(options.batchSize || DEFAULT_BATCH_SIZE),
|
|
29
|
-
searchDepth:
|
|
33
|
+
searchDepth: resolveSearchDepth(options),
|
|
30
34
|
};
|
|
31
35
|
if (options.minSeverity !== undefined)
|
|
32
36
|
summary.minSeverity = options.minSeverity;
|
package/dist/utils/finding.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { isPep440Ecosystem } from "./version.js";
|
|
2
|
+
export function isGatableFinding(finding) {
|
|
3
|
+
return !isPep440Ecosystem(finding.pkg.ecosystem);
|
|
4
|
+
}
|
|
1
5
|
export function isUnconfirmedFix(finding) {
|
|
2
6
|
return finding.relationship === "direct"
|
|
3
7
|
&& finding.validatedFirstFixedVersion === null
|
package/dist/utils/fix-runner.js
CHANGED
|
@@ -7,34 +7,91 @@ import { pluralize } from "./string.js";
|
|
|
7
7
|
import { isBreakingUpgrade } from "./version.js";
|
|
8
8
|
import { installPackageSpec, isOptionShapedName } from "./package-identity.js";
|
|
9
9
|
import { formatParentUpdateChildNote } from "../remediation/parent-update-child-note.js";
|
|
10
|
+
import { INSTALL_COMMANDS } from "./install-command.js";
|
|
11
|
+
import { shellQuote } from "./shell-quote.js";
|
|
12
|
+
const OUTPUT_LIMIT = 8 * 1024;
|
|
13
|
+
// Only these known codes can leave the package manager's error output.
|
|
14
|
+
const NPM_CODE = "(?:ERESOLVE|EACCES|ENOENT|ETARGET|EINTEGRITY|EAUTH|E401|E403|E404|ENOTFOUND|ECONNREFUSED|ETIMEDOUT)";
|
|
15
|
+
const PNPM_CODE = "ERR_PNPM_(?:OUTDATED_LOCKFILE|PEER_DEP_ISSUES|TARBALL_INTEGRITY|NO_OFFLINE_META|UNEXPECTED_STORE|FETCH_404|META_FETCH_FAIL|LOCKFILE_CONFIG_MISMATCH)";
|
|
16
|
+
const YARN_FAILURE_CODE = "(?:YN0001|YN0009|YN0016|YN0020|YN0021|YN0035|YN0047|YN0082)";
|
|
17
|
+
const CODE = new RegExp(`^(?:${NPM_CODE}|${PNPM_CODE}|${YARN_FAILURE_CODE})$`);
|
|
18
|
+
const ERROR_LINE = new RegExp(`^(?:npm (?:ERR!|error) (?:code )?(${NPM_CODE})\\b|\\[?(${PNPM_CODE})\\b\\]?|(?:➤\\s*)?(${YARN_FAILURE_CODE}):|(${NPM_CODE}|${PNPM_CODE})$)`);
|
|
19
|
+
const JSON_CODE = new RegExp(`^\\s*\\{.*?"code"\\s*:\\s*"(${NPM_CODE}|${PNPM_CODE})"`);
|
|
20
|
+
function fixErrorCode(output) {
|
|
21
|
+
let yarnFailureCode;
|
|
22
|
+
for (const line of output.split(/\r?\n/)) {
|
|
23
|
+
const match = line.trim().match(ERROR_LINE) ?? line.match(JSON_CODE);
|
|
24
|
+
const code = match?.[1] ?? match?.[2] ?? match?.[3] ?? match?.[4];
|
|
25
|
+
if (match?.[3])
|
|
26
|
+
yarnFailureCode = match[3];
|
|
27
|
+
else if (code)
|
|
28
|
+
return code;
|
|
29
|
+
}
|
|
30
|
+
return yarnFailureCode;
|
|
31
|
+
}
|
|
32
|
+
export function retainOutputTail(previous, chunk) {
|
|
33
|
+
if (chunk.byteLength >= OUTPUT_LIMIT) {
|
|
34
|
+
return Buffer.from(chunk.subarray(chunk.byteLength - OUTPUT_LIMIT));
|
|
35
|
+
}
|
|
36
|
+
const data = Buffer.concat([previous, chunk]);
|
|
37
|
+
return Buffer.from(data.subarray(Math.max(0, data.length - OUTPUT_LIMIT)));
|
|
38
|
+
}
|
|
39
|
+
export function formatRetryHint(commandParts, cwd, platform = process.platform, currentDirectory = process.cwd()) {
|
|
40
|
+
const pathApi = platform === "win32" ? path.win32 : path.posix;
|
|
41
|
+
const relativeDirectory = pathApi.relative(currentDirectory, cwd);
|
|
42
|
+
const crossDrive = platform === "win32" && pathApi.isAbsolute(relativeDirectory);
|
|
43
|
+
const parentDirectory = relativeDirectory === ".." || relativeDirectory.startsWith(`..${pathApi.sep}`);
|
|
44
|
+
const manualDirectory = crossDrive || parentDirectory;
|
|
45
|
+
const directory = manualDirectory ? "" : relativeDirectory;
|
|
46
|
+
if (platform === "win32") {
|
|
47
|
+
const quotePowerShell = (token) => "'" + token.replace(/'/g, "''") + "'";
|
|
48
|
+
const command = `& ${commandParts.map(quotePowerShell).join(" ")}`;
|
|
49
|
+
if (manualDirectory) {
|
|
50
|
+
return `Hint: In PowerShell, change to the project directory, then run ${command} for full details.`;
|
|
51
|
+
}
|
|
52
|
+
const changeDirectory = directory ? `Set-Location -LiteralPath ${quotePowerShell(directory)} -ErrorAction Stop; ` : "";
|
|
53
|
+
return `Hint: In PowerShell, run ${changeDirectory}${command} for full details.`;
|
|
54
|
+
}
|
|
55
|
+
if (manualDirectory) {
|
|
56
|
+
return `Hint: Change to the project directory, then run ${commandParts.map(shellQuote).join(" ")} for full details.`;
|
|
57
|
+
}
|
|
58
|
+
const changeDirectory = directory ? `cd ${shellQuote(`./${directory}`)} && ` : "";
|
|
59
|
+
return `Hint: Run ${changeDirectory}${commandParts.map(shellQuote).join(" ")} for full details.`;
|
|
60
|
+
}
|
|
10
61
|
export async function runInstallCommand(command, args, cwd, debugLog) {
|
|
11
62
|
const commandLine = [command, ...args].join(" ");
|
|
12
63
|
debugLog?.("Fix command", { command: commandLine, cwd });
|
|
13
64
|
return await new Promise(resolve => {
|
|
65
|
+
let stdout = Buffer.alloc(0);
|
|
66
|
+
let stderr = Buffer.alloc(0);
|
|
14
67
|
const child = spawn(command, args, {
|
|
15
68
|
cwd,
|
|
16
69
|
stdio: ["ignore", "pipe", "pipe"],
|
|
17
70
|
});
|
|
18
|
-
child.stdout.on("data", () => {
|
|
19
|
-
|
|
71
|
+
child.stdout.on("data", (chunk) => {
|
|
72
|
+
stdout = retainOutputTail(stdout, chunk);
|
|
73
|
+
});
|
|
74
|
+
child.stderr.on("data", (chunk) => {
|
|
75
|
+
stderr = retainOutputTail(stderr, chunk);
|
|
76
|
+
});
|
|
20
77
|
child.on("error", error => {
|
|
21
|
-
|
|
22
|
-
|
|
78
|
+
const nodeCode = error.code;
|
|
79
|
+
const errorCode = nodeCode && CODE.test(nodeCode) ? nodeCode : undefined;
|
|
80
|
+
debugLog?.("Fix command finished", { command: commandLine, exitCode: null, errorCode });
|
|
81
|
+
resolve({ status: null, error, errorCode });
|
|
23
82
|
});
|
|
24
83
|
child.on("close", code => {
|
|
25
84
|
debugLog?.("Fix command finished", { command: commandLine, exitCode: code });
|
|
26
|
-
|
|
85
|
+
if (code === 0) {
|
|
86
|
+
resolve({ status: code, error: null });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
resolve({ status: code, error: null, errorCode: fixErrorCode(stderr.toString("utf8")) ?? fixErrorCode(stdout.toString("utf8")) });
|
|
27
90
|
});
|
|
28
91
|
});
|
|
29
92
|
}
|
|
30
93
|
export function commandLabelForPackageManager(packageManager) {
|
|
31
|
-
|
|
32
|
-
return "npm install";
|
|
33
|
-
if (packageManager === "pnpm")
|
|
34
|
-
return "pnpm add";
|
|
35
|
-
if (packageManager === "bun")
|
|
36
|
-
return "bun add";
|
|
37
|
-
return "yarn add";
|
|
94
|
+
return INSTALL_COMMANDS[packageManager].join(" ");
|
|
38
95
|
}
|
|
39
96
|
// Categorize the fixes that --fix does NOT auto-apply. Direct upgrades and
|
|
40
97
|
// within-range refreshes (parent-update) are auto-applied, so only parent
|
|
@@ -74,57 +131,72 @@ export function buildApplyCommands(packageManager, target) {
|
|
|
74
131
|
return buildInstallApplyArgv(packageManager, target);
|
|
75
132
|
}
|
|
76
133
|
function buildInstallApplyArgv(packageManager, target) {
|
|
77
|
-
const workspaces =
|
|
134
|
+
const workspaces = target.workspaces ?? [];
|
|
78
135
|
const pkgArg = installPackageSpec(target);
|
|
79
136
|
if (isOptionShapedName(pkgArg))
|
|
80
137
|
return [];
|
|
81
138
|
const isDev = Boolean(target.isDev);
|
|
139
|
+
const [executable, subcommand] = INSTALL_COMMANDS[packageManager];
|
|
82
140
|
if (packageManager === "npm") {
|
|
83
|
-
const args = [
|
|
141
|
+
const args = [subcommand];
|
|
84
142
|
if (isDev)
|
|
85
143
|
args.push("-D");
|
|
86
|
-
for (const ws of workspaces) {
|
|
144
|
+
for (const ws of workspaces.filter(w => w !== ".")) {
|
|
87
145
|
args.push("-w", ws);
|
|
88
146
|
}
|
|
89
147
|
args.push(pkgArg);
|
|
90
|
-
return [[
|
|
148
|
+
return [[executable, ...args]];
|
|
91
149
|
}
|
|
92
150
|
if (packageManager === "pnpm") {
|
|
93
151
|
const args = [];
|
|
94
|
-
for (const ws of workspaces) {
|
|
152
|
+
for (const ws of workspaces.filter(w => w !== ".")) {
|
|
95
153
|
args.push("--filter", `./${ws}`);
|
|
96
154
|
}
|
|
97
|
-
args.push(
|
|
155
|
+
args.push(subcommand);
|
|
98
156
|
if (isDev)
|
|
99
157
|
args.push("-D");
|
|
100
158
|
args.push(pkgArg);
|
|
101
|
-
return [[
|
|
159
|
+
return [[executable, ...args]];
|
|
102
160
|
}
|
|
103
161
|
if (packageManager === "yarn") {
|
|
104
|
-
|
|
105
|
-
|
|
162
|
+
const nonRoot = workspaces.filter(w => w !== ".");
|
|
163
|
+
if (nonRoot.length === 0) {
|
|
164
|
+
const args = [subcommand];
|
|
106
165
|
if (isDev)
|
|
107
166
|
args.push("-D");
|
|
108
167
|
args.push(pkgArg);
|
|
109
|
-
return [[
|
|
168
|
+
return [[executable, ...args]];
|
|
110
169
|
}
|
|
111
|
-
return
|
|
112
|
-
const args = ["workspace", ws,
|
|
170
|
+
return nonRoot.map(ws => {
|
|
171
|
+
const args = ["workspace", ws, subcommand];
|
|
113
172
|
if (isDev)
|
|
114
173
|
args.push("-D");
|
|
115
174
|
args.push(pkgArg);
|
|
116
|
-
return [
|
|
175
|
+
return [executable, ...args];
|
|
117
176
|
});
|
|
118
177
|
}
|
|
119
|
-
// bun
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
178
|
+
// bun. --filter for add only works from Bun 1.4.0, so run from the member
|
|
179
|
+
// directory via --cwd, which works on older releases and never edits root.
|
|
180
|
+
// When declared in both root and members, emit a plain add for the root
|
|
181
|
+
// alongside the member command(s).
|
|
182
|
+
const hasRoot = workspaces.includes(".");
|
|
183
|
+
const nonRoot = workspaces.filter(ws => ws !== ".");
|
|
184
|
+
const runs = [];
|
|
185
|
+
if (hasRoot || nonRoot.length === 0) {
|
|
186
|
+
const args = [subcommand];
|
|
187
|
+
if (isDev)
|
|
188
|
+
args.push("--dev");
|
|
189
|
+
args.push(pkgArg);
|
|
190
|
+
runs.push([executable, ...args]);
|
|
191
|
+
}
|
|
192
|
+
for (const ws of nonRoot) {
|
|
193
|
+
const args = [subcommand];
|
|
194
|
+
if (isDev)
|
|
195
|
+
args.push("--dev");
|
|
196
|
+
args.push("--cwd", ws, pkgArg);
|
|
197
|
+
runs.push([executable, ...args]);
|
|
125
198
|
}
|
|
126
|
-
|
|
127
|
-
return [["bun", ...args]];
|
|
199
|
+
return runs;
|
|
128
200
|
}
|
|
129
201
|
function buildParentUpdateApplyArgv(packageManager, target) {
|
|
130
202
|
// Always build from structured fields. Never tokenize target.command: plan
|
|
@@ -199,7 +271,6 @@ export async function applyFixesIfRequested(params) {
|
|
|
199
271
|
const commandLabel = commandLabelForPackageManager(params.plan.packageManager);
|
|
200
272
|
const total = runnableTargets.length;
|
|
201
273
|
const spinner = createSpinner(`Applying safe package fixes with ${commandLabel}... 0/${total}`, params.options);
|
|
202
|
-
const fixHint = `\nHint: Check that \`${params.plan.packageManager}\` is available and you have write access to node_modules.\nIf running in CI, ensure the install step has already run before cve-lite --fix.`;
|
|
203
274
|
// parent-update is keyed per child, so two children behind one parent produce
|
|
204
275
|
// two targets. npm update names the child, so those commands differ. Two
|
|
205
276
|
// parents that refresh the same child can still share `npm update <child>`.
|
|
@@ -209,6 +280,7 @@ export async function applyFixesIfRequested(params) {
|
|
|
209
280
|
const target = runnableTargets[i];
|
|
210
281
|
for (const commandParts of buildApplyCommands(params.plan.packageManager, target)) {
|
|
211
282
|
const commandLine = commandParts.join(" ");
|
|
283
|
+
const retryHint = `\n${formatRetryHint(commandParts, params.projectPath)}\nCheck that \`${params.plan.packageManager}\` is available and you have write access to node_modules.\nIf running in CI, ensure the install step has already run before cve-lite --fix.`;
|
|
212
284
|
if (seenCommands.has(commandLine))
|
|
213
285
|
continue;
|
|
214
286
|
seenCommands.add(commandLine);
|
|
@@ -216,11 +288,13 @@ export async function applyFixesIfRequested(params) {
|
|
|
216
288
|
const run = await runCommand(commandParts[0], commandParts.slice(1), params.projectPath, params.debugLog);
|
|
217
289
|
if (run.error) {
|
|
218
290
|
spinner.fail("Failed to apply fixes");
|
|
219
|
-
|
|
291
|
+
const detail = run.errorCode ? `\nPackage manager error: ${run.errorCode}` : "";
|
|
292
|
+
throw new Error(`Failed to apply fixes${detail}${retryHint}`);
|
|
220
293
|
}
|
|
221
294
|
if ((run.status ?? 1) !== 0) {
|
|
222
295
|
spinner.fail(`Fix command failed (${commandLabel})`);
|
|
223
|
-
|
|
296
|
+
const detail = run.errorCode ? `\nPackage manager error: ${run.errorCode}` : "";
|
|
297
|
+
throw new Error(`Fix command exited with status ${run.status ?? 1}${detail}${retryHint}`);
|
|
224
298
|
}
|
|
225
299
|
}
|
|
226
300
|
}
|
|
@@ -261,6 +261,11 @@ export function importTypeQueryOffsets(source) {
|
|
|
261
261
|
addTypeQueries(tokens, queryStart ?? start, end, offsets);
|
|
262
262
|
i = end - 1;
|
|
263
263
|
}
|
|
264
|
+
collectSignatureTypeQueries(tokens, source, offsets);
|
|
265
|
+
return offsets;
|
|
266
|
+
}
|
|
267
|
+
/** Record type queries in function, class, method and arrow signatures. */
|
|
268
|
+
function collectSignatureTypeQueries(tokens, source, offsets) {
|
|
264
269
|
const pairs = syntaxPairs(tokens);
|
|
265
270
|
for (let i = 0; i < tokens.length; i++) {
|
|
266
271
|
const text = tokens[i].text;
|
|
@@ -318,5 +323,4 @@ export function importTypeQueryOffsets(source) {
|
|
|
318
323
|
}
|
|
319
324
|
}
|
|
320
325
|
}
|
|
321
|
-
return offsets;
|
|
322
326
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// MAL-* is the OSV prefix for malicious code advisories. Guarded because OSV
|
|
2
|
+
// records are external data - the declared `string` type on OsvVuln.id does
|
|
3
|
+
// not guarantee a malformed advisory record cannot have a missing/non-string id.
|
|
4
|
+
// Kept free of imports so the severity gate can use it without pulling in the
|
|
5
|
+
// advisory helpers.
|
|
6
|
+
export function isMaliciousVulnId(id) {
|
|
7
|
+
return typeof id === "string" && id.startsWith("MAL-");
|
|
8
|
+
}
|
|
9
|
+
export function hasMaliciousAdvisory(vulns) {
|
|
10
|
+
return vulns.some(v => isMaliciousVulnId(v.id));
|
|
11
|
+
}
|
|
@@ -13,13 +13,23 @@ export function packageInstanceKey(pkg) {
|
|
|
13
13
|
export function packageNameKey(pkg) {
|
|
14
14
|
return pkg.registryName ? `${pkg.name}\u0000${pkg.registryName}` : pkg.name;
|
|
15
15
|
}
|
|
16
|
-
export function
|
|
16
|
+
export function parseNpmAliasTarget(value) {
|
|
17
17
|
if (typeof value !== "string" || !value.startsWith(NPM_ALIAS_PROTOCOL)) {
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
20
|
const target = value.slice(NPM_ALIAS_PROTOCOL.length);
|
|
21
21
|
const separator = target.lastIndexOf("@");
|
|
22
|
-
|
|
22
|
+
if (separator <= 0) {
|
|
23
|
+
return { name: target, spec: "" };
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
name: target.slice(0, separator),
|
|
27
|
+
spec: target.slice(separator + 1).trim(),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function npmAliasRegistryName(value) {
|
|
31
|
+
const parsed = parseNpmAliasTarget(value);
|
|
32
|
+
return parsed ? parsed.name : null;
|
|
23
33
|
}
|
|
24
34
|
/** Keep an npm alias when installing a newer version of its registry package. */
|
|
25
35
|
export function installPackageSpec(target) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pathsEqual } from "./array.js";
|
|
1
2
|
export function calculatePathCoverage(knownPaths, coveredPath) {
|
|
2
3
|
const coveredPaths = coveredPath && coveredPath.length > 0 ? [coveredPath] : [];
|
|
3
4
|
const remainingPaths = knownPaths.filter(path => !coveredPaths.some(covered => pathsEqual(path, covered)));
|
|
@@ -10,8 +11,3 @@ export function calculatePathCoverage(knownPaths, coveredPath) {
|
|
|
10
11
|
export function formatDependencyPath(path) {
|
|
11
12
|
return path.join(" -> ");
|
|
12
13
|
}
|
|
13
|
-
function pathsEqual(left, right) {
|
|
14
|
-
if (left.length !== right.length)
|
|
15
|
-
return false;
|
|
16
|
-
return left.every((value, index) => value === right[index]);
|
|
17
|
-
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitization utilities for terminal output to prevent ANSI injection,
|
|
3
|
+
* terminal control escape sequences, and GitHub Actions workflow command injection
|
|
4
|
+
* (e.g. `\n::error::...` or legacy `##[error]...`).
|
|
5
|
+
*/
|
|
6
|
+
export const ANSI_REGEX = /(?:\x1b\[|\u009b)[0-9:;<=>?]*[ -/]*[@-~]|(?:\x1b\]|\u009d)[^\x07\x1b\u009c\u009d]*(?:\x07|\x1b\\|\u009c)|(?:\x1b\]|\u009d)|\x1b[@-Z\\\]^_]/g;
|
|
7
|
+
// Non-SGR ANSI sequences (OSC, non-color CSI such as clear screen or cursor movements, 2-character escapes)
|
|
8
|
+
export const NON_SGR_ANSI_REGEX = /(?:\x1b\[|\u009b)[0-9:;<=>?]*[ -/]*[@A-Za-ln-z_`{|}~[\\\]^]|(?:\x1b\]|\u009d)[^\x07\x1b\u009c\u009d]*(?:\x07|\x1b\\|\u009c)|(?:\x1b\]|\u009d)|\x1b[@-Z\\\]^_]/g;
|
|
9
|
+
// Control characters in C0 (0x00-0x1F, 0x7F) and C1 (0x80-0x9F) ranges.
|
|
10
|
+
// 0x1B (ESC) is already included in 0x00-0x1F.
|
|
11
|
+
export const CONTROL_OR_ANSI_REGEX = /[\x00-\x1f\x7f\u0080-\u009f]/;
|
|
12
|
+
export const FIX_COMMAND_SUPPRESSED_MESSAGE = "Fix command suppressed: package, version, or subfolder contains control characters or a workflow command marker. Inspect package, version, and path inputs before rescanning.";
|
|
13
|
+
export function stripAnsi(text) {
|
|
14
|
+
return text.replace(ANSI_REGEX, "");
|
|
15
|
+
}
|
|
16
|
+
export function hasControlCharsOrAnsi(text) {
|
|
17
|
+
return CONTROL_OR_ANSI_REGEX.test(text);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns true if a package, version, parent identity, or command string contains control characters,
|
|
21
|
+
* ANSI escape sequences, or legacy workflow command markers (`##[`), preventing them from being safely
|
|
22
|
+
* presented or executed.
|
|
23
|
+
*/
|
|
24
|
+
export function isMalformedOrUnsafeIdentity(value) {
|
|
25
|
+
if (!value)
|
|
26
|
+
return false;
|
|
27
|
+
return hasControlCharsOrAnsi(value) || /##\[/.test(value);
|
|
28
|
+
}
|
|
29
|
+
export function isCommandSuppressed(command) {
|
|
30
|
+
return isMalformedOrUnsafeIdentity(command);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sanitizes untrusted strings (package names, versions, free-text lines) for terminal/stdout
|
|
34
|
+
* printing by stripping ANSI sequences and control characters, replacing newlines/tabs with spaces,
|
|
35
|
+
* and neutralizing legacy workflow command markers (`##[`).
|
|
36
|
+
*/
|
|
37
|
+
export function sanitizeOutputString(value) {
|
|
38
|
+
if (!value)
|
|
39
|
+
return value;
|
|
40
|
+
return value
|
|
41
|
+
.replace(ANSI_REGEX, "")
|
|
42
|
+
.replace(/[\r\n\t\u0085]+/g, " ")
|
|
43
|
+
.replace(/[\x00-\x1f\x7f\u0080-\u009f]/g, "")
|
|
44
|
+
.replace(/##\[/g, "# #[");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sanitizes a rendered table cell string, preserving chalk SGR color formatting
|
|
48
|
+
* while stripping non-color CSI escapes (e.g. clear-screen), OSC sequences (e.g. hyperlinks),
|
|
49
|
+
* carriage returns, BEL, other control characters, and legacy `##[` markers.
|
|
50
|
+
*/
|
|
51
|
+
export function sanitizeTableCell(value) {
|
|
52
|
+
if (!value)
|
|
53
|
+
return value;
|
|
54
|
+
return value
|
|
55
|
+
.replace(NON_SGR_ANSI_REGEX, "")
|
|
56
|
+
.replace(/[\r\n\t\u0085]+/g, " ")
|
|
57
|
+
.replace(/[\x00-\x1a\x1c-\x1f\x7f\u0080-\u009f]/g, "")
|
|
58
|
+
.replace(/##\[/g, "# #[");
|
|
59
|
+
}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Resolves
|
|
2
|
+
* Resolves all SBOM formats a run should emit, deduplicated.
|
|
3
3
|
*
|
|
4
|
-
* `--
|
|
5
|
-
*
|
|
6
|
-
* that build options programmatically behave the same as the CLI.
|
|
4
|
+
* `--sbom` takes precedence, and `--cdx` remains supported as a permanent
|
|
5
|
+
* alias that adds CycloneDX output if not already selected.
|
|
7
6
|
*/
|
|
8
|
-
export function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export function resolveSbomFormats(options) {
|
|
8
|
+
const formats = [];
|
|
9
|
+
if (options.sbom) {
|
|
10
|
+
const list = Array.isArray(options.sbom) ? options.sbom : [options.sbom];
|
|
11
|
+
for (const fmt of list) {
|
|
12
|
+
if (!formats.includes(fmt)) {
|
|
13
|
+
formats.push(fmt);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (options.cdx && !formats.includes("cyclonedx")) {
|
|
18
|
+
formats.push("cyclonedx");
|
|
19
|
+
}
|
|
20
|
+
return formats;
|
|
12
21
|
}
|
package/dist/utils/severity.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { chalk } from "./chalk.js";
|
|
2
2
|
import { severityOrder } from "../constants.js";
|
|
3
3
|
import { normalizeSeverity } from "../osv/severity.js";
|
|
4
|
+
import { hasMaliciousAdvisory } from "./malicious.js";
|
|
5
|
+
import { pluralize } from "./string.js";
|
|
4
6
|
export const SEVERITY_ORDER = ["critical", "high", "medium", "low", "unknown", "none"];
|
|
5
7
|
export function reachesFailOn(findings, failOn) {
|
|
6
8
|
if (!failOn)
|
|
@@ -8,6 +10,9 @@ export function reachesFailOn(findings, failOn) {
|
|
|
8
10
|
const failLevel = normalizeSeverity(failOn);
|
|
9
11
|
return findings.some((f) => severityOrder[f.severity] >= severityOrder[failLevel]);
|
|
10
12
|
}
|
|
13
|
+
export function hasUnresolvedAdvisories(finding) {
|
|
14
|
+
return Boolean(finding.unresolvedAdvisoryIds && finding.unresolvedAdvisoryIds.length > 0);
|
|
15
|
+
}
|
|
11
16
|
// One line that names what tripped the --fail-on gate, so a red CI job says why
|
|
12
17
|
// it is red. The gate ORs three finding classes (CVE, override hygiene,
|
|
13
18
|
// maintenance risk) and none of the rendered output mentioned the gate before,
|
|
@@ -16,27 +21,76 @@ export function reachesFailOn(findings, failOn) {
|
|
|
16
21
|
// cannot disagree. The parenthetical echoes the raw flag value: --fail-on is not
|
|
17
22
|
// validated and normalizeSeverity falls back to critical, so echoing the
|
|
18
23
|
// normalized level would show the user a value they never typed.
|
|
19
|
-
// The
|
|
24
|
+
// The finding classes the --fail-on gate ORs, as failingGateSummary
|
|
20
25
|
// names them. Both scan paths build their gate input from this one list, so
|
|
21
26
|
// the wording for a class cannot differ between a single- and multi-folder scan.
|
|
22
27
|
export const GATE_CLASS_LABELS = {
|
|
28
|
+
malicious: "malicious package",
|
|
23
29
|
vulnerability: "vulnerability",
|
|
24
30
|
overrideHygiene: "override hygiene",
|
|
25
31
|
maintenanceRisk: "maintenance risk",
|
|
26
32
|
};
|
|
33
|
+
// MAL- advisories carry no CVSS vector, so a malicious package scores
|
|
34
|
+
// `unknown` and would pass every threshold above low. It is not a severity
|
|
35
|
+
// question: the advice is to remove it, so it fails the gate at any level and
|
|
36
|
+
// is counted apart from ordinary vulnerability findings.
|
|
37
|
+
export function vulnerabilityGateClasses(findings) {
|
|
38
|
+
const isMalicious = (f) => hasMaliciousAdvisory(f.vulnerabilities ?? []);
|
|
39
|
+
const malicious = findings.filter(isMalicious);
|
|
40
|
+
const rest = findings.filter((f) => !isMalicious(f));
|
|
41
|
+
return [
|
|
42
|
+
{ label: GATE_CLASS_LABELS.malicious, findings: malicious, anyLevel: true },
|
|
43
|
+
{ label: GATE_CLASS_LABELS.vulnerability, findings: rest },
|
|
44
|
+
];
|
|
45
|
+
}
|
|
27
46
|
export function failingGateSummary(classes, failOn) {
|
|
28
47
|
if (!failOn)
|
|
29
48
|
return null;
|
|
30
49
|
const failLevel = normalizeSeverity(failOn);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
50
|
+
if (failLevel === "none")
|
|
51
|
+
return null;
|
|
52
|
+
const anyLevelParts = [];
|
|
53
|
+
const thresholdParts = [];
|
|
54
|
+
for (const { label, findings, anyLevel } of classes) {
|
|
55
|
+
const count = anyLevel
|
|
56
|
+
? findings.length
|
|
57
|
+
: findings.filter((f) => {
|
|
58
|
+
if ((!f.vulnerabilities || f.vulnerabilities.length === 0) && hasUnresolvedAdvisories(f)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return severityOrder[f.severity] >= severityOrder[failLevel];
|
|
62
|
+
}).length;
|
|
34
63
|
if (count > 0)
|
|
35
|
-
|
|
64
|
+
(anyLevel ? anyLevelParts : thresholdParts).push(`${count} ${label} ${count === 1 ? "finding" : "findings"}`);
|
|
65
|
+
}
|
|
66
|
+
if (anyLevelParts.length === 0 && thresholdParts.length === 0)
|
|
67
|
+
return null;
|
|
68
|
+
const segments = [];
|
|
69
|
+
if (anyLevelParts.length > 0)
|
|
70
|
+
segments.push(`${anyLevelParts.join(", ")} at any level`);
|
|
71
|
+
if (thresholdParts.length > 0)
|
|
72
|
+
segments.push(`${thresholdParts.join(", ")} at or above ${failLevel}`);
|
|
73
|
+
return `Failing: ${segments.join(", and ")} (--fail-on ${failOn}).`;
|
|
74
|
+
}
|
|
75
|
+
export function unresolvedGateNotice(findings, failOn, incompletePolicy) {
|
|
76
|
+
if (!failOn || normalizeSeverity(failOn) === "none")
|
|
77
|
+
return null;
|
|
78
|
+
const ids = new Set();
|
|
79
|
+
for (const f of findings) {
|
|
80
|
+
if (hasUnresolvedAdvisories(f)) {
|
|
81
|
+
for (const id of f.unresolvedAdvisoryIds) {
|
|
82
|
+
ids.add(id);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
36
85
|
}
|
|
37
|
-
if (
|
|
86
|
+
if (ids.size === 0)
|
|
38
87
|
return null;
|
|
39
|
-
|
|
88
|
+
const count = ids.size;
|
|
89
|
+
const baseMessage = `${count} ${pluralize(count, "advisory", "advisories")} could not be evaluated`;
|
|
90
|
+
if (incompletePolicy === "error") {
|
|
91
|
+
return `${baseMessage}.`;
|
|
92
|
+
}
|
|
93
|
+
return `${baseMessage}; use --incomplete-policy error to fail the build.`;
|
|
40
94
|
}
|
|
41
95
|
export function formatSeverityLabel(severity) {
|
|
42
96
|
const lower = severity.toLowerCase();
|