cve-lite-cli 1.37.0 → 1.38.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 +20 -1
- package/dist/cli/args.js +120 -103
- package/dist/cli/flags.js +39 -0
- package/dist/cli/help.js +6 -3
- package/dist/cli/overrides.js +25 -19
- package/dist/cli/validate.js +31 -9
- package/dist/index.js +6 -1
- package/dist/output/compact-truncation.js +35 -0
- package/dist/output/formatters.js +10 -2
- package/dist/output/html-reporter.js +24 -12
- package/dist/output/multi-folder-html-reporter.js +26 -7
- package/dist/output/override-findings-html.js +24 -3
- package/dist/output/override-findings-json.js +5 -2
- package/dist/output/override-findings-sarif.js +1 -0
- package/dist/output/override-findings-terminal.js +21 -1
- package/dist/output/printers.js +34 -21
- package/dist/output/sarif.js +54 -3
- package/dist/output/scan-json.js +74 -0
- package/dist/output/skipped-override-rules.js +41 -0
- package/dist/output/write-outputs.js +16 -28
- package/dist/overrides/admitted-scan.js +12 -1
- package/dist/overrides/api.js +75 -21
- package/dist/overrides/context-builder.js +17 -2
- package/dist/overrides/detectors/index.js +2 -0
- package/dist/overrides/detectors/oa008-materialized.js +72 -13
- package/dist/overrides/detectors/oa009-stale-floor.js +12 -15
- package/dist/overrides/detectors/oa010-vulnerable-floor.js +5 -1
- package/dist/overrides/detectors/oa011-exceeds-range.js +128 -0
- package/dist/overrides/detectors/pd001-override-only-phantom.js +5 -4
- package/dist/overrides/detectors/pd002-transitive-only-phantom.js +5 -4
- package/dist/overrides/detectors/phantom-utils.js +29 -0
- package/dist/overrides/parsing/registry.js +79 -10
- package/dist/scan/multi-folder-scan.js +65 -51
- package/dist/scan/override-audit.js +49 -0
- package/dist/scan/single-scan.js +108 -33
- package/dist/scanner.js +8 -4
- package/dist/skills/content.js +4 -2
- package/dist/usage/scanner.js +219 -28
- package/dist/utils/contextual-signals.js +193 -0
- package/dist/utils/finding.js +5 -0
- package/dist/utils/package-json.js +66 -14
- package/dist/utils/severity.js +22 -0
- package/dist/utils/update-check.js +2 -1
- package/dist/utils/version.js +33 -19
- package/package.json +1 -1
package/dist/cli/overrides.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path, { resolve } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { applyFix } from "../overrides/index.js";
|
|
4
|
+
import { runOverrideAudit } from "../scan/override-audit.js";
|
|
5
5
|
import { createAuditLog } from "../audit-log/index.js";
|
|
6
6
|
import { EXIT_OK, EXIT_FINDINGS, EXIT_ERROR } from "../types.js";
|
|
7
|
-
import { renderOverrideFindings } from "../output/override-findings-terminal.js";
|
|
7
|
+
import { renderOverrideFindings, renderSkippedOverrideRules } from "../output/override-findings-terminal.js";
|
|
8
8
|
import { reachesFailOn } from "../utils/severity.js";
|
|
9
9
|
import { chalk } from "../utils/chalk.js";
|
|
10
|
-
export async function runOverrides({ projectArg, options, logger, auditLog: injectedAuditLog }) {
|
|
10
|
+
export async function runOverrides({ projectArg, options, logger, auditLog: injectedAuditLog, fetchImpl, debugLog }) {
|
|
11
11
|
const projectPath = resolve(projectArg ?? ".");
|
|
12
12
|
const ownsAuditLog = !injectedAuditLog;
|
|
13
13
|
const auditLog = injectedAuditLog ?? createAuditLog(options.auditLog ?? process.env.CVE_LITE_AUDIT_LOG);
|
|
14
|
-
// OA010 needs an advisory source on top of the network opt-in. Built here
|
|
15
|
-
// rather than inside audit() to keep the overrides module free of a scanner
|
|
16
|
-
// import; closed in the finally so an offline database handle never leaks.
|
|
17
|
-
const advisoryContext = options.checkNetwork === true ? createAdvisorySource() : null;
|
|
18
14
|
try {
|
|
19
|
-
|
|
15
|
+
// Same helper the scan paths use, so all three entry points wire up identically.
|
|
16
|
+
const result = await runOverrideAudit({
|
|
17
|
+
projectPath,
|
|
18
|
+
checkNetwork: options.checkNetwork === true,
|
|
19
|
+
osvUrl: options.osvUrl,
|
|
20
20
|
auditLog,
|
|
21
21
|
logger,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const result = await audit(ctx, {
|
|
25
|
-
checkNetwork: options.checkNetwork === true,
|
|
26
|
-
advisorySource: advisoryContext?.advisorySource,
|
|
22
|
+
fetchImpl,
|
|
23
|
+
debugLog,
|
|
27
24
|
});
|
|
28
25
|
let findings = result.findings;
|
|
26
|
+
let skipped = result.skipped;
|
|
29
27
|
if (options.rule) {
|
|
30
28
|
findings = findings.filter((f) => f.ruleId === options.rule);
|
|
29
|
+
// Scope the skip notice the same way. On `--rule OA001` the user asked about one
|
|
30
|
+
// rule, so reporting that six others did not run is noise and reads as a failure.
|
|
31
|
+
skipped = skipped.filter((s) => s.ruleId === options.rule);
|
|
31
32
|
}
|
|
32
33
|
if (options.fix) {
|
|
33
34
|
// Tier 1 only by default: "proposed" fixes write an inferred value (OA006
|
|
@@ -45,13 +46,13 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
|
|
|
45
46
|
if (options.json) {
|
|
46
47
|
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
47
48
|
const jsonFilename = `cve-lite-overrides-${ts}.json`;
|
|
48
|
-
fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings: remaining, fixReport: report }, null, 2));
|
|
49
|
+
fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings: remaining, skippedOverrideRules: skipped, fixReport: report }, null, 2));
|
|
49
50
|
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
|
|
50
51
|
}
|
|
51
52
|
else {
|
|
52
53
|
logger.info(`Applied ${report.appliedPatches.length} fix${report.appliedPatches.length === 1 ? "" : "es"}; skipped ${report.skipped.length}.`);
|
|
53
54
|
if (remaining.length > 0) {
|
|
54
|
-
process.stdout.write(renderOverrideFindings(remaining, { projectPath }) + "\n");
|
|
55
|
+
process.stdout.write(renderOverrideFindings(remaining, { projectPath, rulesSkipped: skipped.length > 0 }) + "\n");
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
return reachesFailOn(remaining, options.failOn) ? EXIT_FINDINGS : EXIT_OK;
|
|
@@ -60,11 +61,16 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
|
|
|
60
61
|
if (options.json) {
|
|
61
62
|
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
62
63
|
const jsonFilename = `cve-lite-overrides-${ts}.json`;
|
|
63
|
-
fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings }, null, 2));
|
|
64
|
+
fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings, skippedOverrideRules: skipped }, null, 2));
|
|
64
65
|
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
|
|
65
66
|
}
|
|
66
67
|
else {
|
|
67
|
-
process.stdout.write(renderOverrideFindings(findings, { projectPath }) + "\n");
|
|
68
|
+
process.stdout.write(renderOverrideFindings(findings, { projectPath, rulesSkipped: skipped.length > 0 }) + "\n");
|
|
69
|
+
// This subcommand is the documented home of --check-network, so it is the surface
|
|
70
|
+
// where a silently skipped rule is most misleading (#1222).
|
|
71
|
+
if (skipped.length > 0) {
|
|
72
|
+
process.stdout.write(renderSkippedOverrideRules(skipped) + "\n");
|
|
73
|
+
}
|
|
68
74
|
}
|
|
69
75
|
return reachesFailOn(findings, options.failOn) ? EXIT_FINDINGS : EXIT_OK;
|
|
70
76
|
}
|
|
@@ -73,7 +79,7 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
|
|
|
73
79
|
return EXIT_ERROR;
|
|
74
80
|
}
|
|
75
81
|
finally {
|
|
76
|
-
|
|
82
|
+
// The advisory source is opened and closed inside runOverrideAudit now.
|
|
77
83
|
if (ownsAuditLog)
|
|
78
84
|
auditLog.close();
|
|
79
85
|
}
|
package/dist/cli/validate.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
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
3
|
import { validateOsvUrl } from "../utils/validate-url.js";
|
|
3
4
|
import { resolveSbomFormat } from "../utils/sbom-format.js";
|
|
5
|
+
function conflictMessage(flag, withFlag) {
|
|
6
|
+
return `${flag} cannot be used with ${withFlag}.`;
|
|
7
|
+
}
|
|
8
|
+
/** Sibling of conflictMessage for the other shape of flag error, so the two kinds of
|
|
9
|
+
* message stay consistent as flags are added. */
|
|
10
|
+
function requiresMessage(flag, requiredFlag) {
|
|
11
|
+
return `${flag} requires ${requiredFlag}.`;
|
|
12
|
+
}
|
|
4
13
|
export async function validateOptions(options) {
|
|
5
14
|
if (options.allowPrivateOsvUrl && !options.osvUrl) {
|
|
6
|
-
throw new Error("--allow-private-osv-url
|
|
15
|
+
throw new Error(`${requiresMessage("--allow-private-osv-url", "--osv-url")} Provide a custom OSV endpoint with --osv-url, or remove --allow-private-osv-url.`);
|
|
7
16
|
}
|
|
8
17
|
if ((options.offline || options.offlineDb) && options.osvUrl) {
|
|
9
|
-
throw new Error(
|
|
18
|
+
throw new Error(`${conflictMessage(`${FLAG_OFFLINE}/${FLAG_OFFLINE_DB}`, FLAG_OSV_URL)} Choose offline mode (local DB) or online mode (custom OSV endpoint), not both.`);
|
|
10
19
|
}
|
|
11
20
|
if (options.noCache && (options.offline || options.offlineDb)) {
|
|
12
|
-
throw new Error(
|
|
21
|
+
throw new Error(`${conflictMessage(FLAG_NO_CACHE, `${FLAG_OFFLINE} or ${FLAG_OFFLINE_DB}`)} Offline mode uses the local advisory DB directly; --no-cache only applies to online scans.`);
|
|
13
22
|
}
|
|
14
23
|
let ssrfWarning;
|
|
15
24
|
if (options.osvUrl) {
|
|
@@ -23,19 +32,19 @@ export async function validateOptions(options) {
|
|
|
23
32
|
ssrfWarning = await validateOsvUrl(options.osvUrl, !!options.allowPrivateOsvUrl);
|
|
24
33
|
}
|
|
25
34
|
if (options.createPr && options.json) {
|
|
26
|
-
throw new Error(
|
|
35
|
+
throw new Error(`${conflictMessage(FLAG_CREATE_PR, FLAG_JSON)} Use --create-pr to open a pull request for applied fixes, or --json to save scan results as JSON, not both.`);
|
|
27
36
|
}
|
|
28
37
|
if (options.fix && options.json) {
|
|
29
|
-
throw new Error(
|
|
38
|
+
throw new Error(`${conflictMessage(FLAG_FIX, FLAG_JSON)} Use --fix to apply validated fixes and rescan, or --json to save scan results as JSON, not both.`);
|
|
30
39
|
}
|
|
31
40
|
if (options.fix && options.sarif) {
|
|
32
|
-
throw new Error(
|
|
41
|
+
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.`);
|
|
33
42
|
}
|
|
34
43
|
if (options.fix && resolveSbomFormat(options)) {
|
|
35
44
|
// Name the flag the user actually typed: --cdx is an alias for --sbom cyclonedx.
|
|
36
|
-
const flag = options.cdx ?
|
|
45
|
+
const flag = options.cdx ? FLAG_CDX : FLAG_SBOM;
|
|
37
46
|
const what = options.cdx ? "a CycloneDX SBOM" : "an SBOM";
|
|
38
|
-
throw new Error(
|
|
47
|
+
throw new Error(`${conflictMessage(FLAG_FIX, flag)} Use --fix to apply validated fixes and rescan, or ${flag} to save ${what}, not both.`);
|
|
39
48
|
}
|
|
40
49
|
if (options.createPr && !options.fix) {
|
|
41
50
|
throw new Error("--create-pr requires --fix. Add --fix to apply validated fixes before opening a pull request, or remove --create-pr.");
|
|
@@ -44,11 +53,24 @@ export async function validateOptions(options) {
|
|
|
44
53
|
throw new Error("--base can only be used with --create-pr. Add --create-pr to select its target branch, or remove --base.");
|
|
45
54
|
}
|
|
46
55
|
if (options.report && options.json) {
|
|
47
|
-
throw new Error(
|
|
56
|
+
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.`);
|
|
48
57
|
}
|
|
49
58
|
if (options.output && !(options.json || options.sarif || resolveSbomFormat(options))) {
|
|
50
59
|
throw new Error("--output requires --json, --sarif or --sbom. Add one of them to write a file into the output directory, or remove --output.");
|
|
51
60
|
}
|
|
61
|
+
if (options.checkNetwork && !options.checkOverrides) {
|
|
62
|
+
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
|
+
}
|
|
64
|
+
// Rejected rather than silently partly honoured, and deliberately covering BOTH offline
|
|
65
|
+
// flags. The network-backed rules reach the npm registry for dist-tags and published
|
|
66
|
+
// version lists, which no local advisory database can supply, so the combination would
|
|
67
|
+
// print "no external advisory calls will be made" and then call the registry anyway.
|
|
68
|
+
// Everywhere else in the codebase offline means --offline OR --offline-db (the advisory
|
|
69
|
+
// source factory and the banner both), so guarding only one would leave two different
|
|
70
|
+
// definitions of offline depending on which check you happen to be reading.
|
|
71
|
+
if ((options.offline || options.offlineDb) && options.checkNetwork) {
|
|
72
|
+
throw new Error(`${conflictMessage(`${FLAG_OFFLINE}/${FLAG_OFFLINE_DB}`, FLAG_CHECK_NETWORK)} The network-backed override rules query the npm registry for dist-tags and published version lists, which a local advisory database cannot supply. Drop ${FLAG_CHECK_NETWORK} to audit offline, or drop the offline flag to run them.`);
|
|
73
|
+
}
|
|
52
74
|
if (options.caCert) {
|
|
53
75
|
try {
|
|
54
76
|
validateCaCertFile(options.caCert);
|
package/dist/index.js
CHANGED
|
@@ -110,14 +110,19 @@ if (parsedArgs) {
|
|
|
110
110
|
options,
|
|
111
111
|
logger,
|
|
112
112
|
auditLog: auditLogHandle,
|
|
113
|
+
// Same cert-aware fetch and debug sink the scan path uses, so a CA certificate
|
|
114
|
+
// and --debug behave identically on both.
|
|
115
|
+
fetchImpl: certFetch,
|
|
116
|
+
debugLog,
|
|
113
117
|
});
|
|
114
118
|
auditLogHandle.close();
|
|
115
119
|
process.exit(exitCode);
|
|
116
120
|
return;
|
|
117
121
|
}
|
|
118
122
|
const validationWarning = await validateOptions(options);
|
|
119
|
-
if (validationWarning)
|
|
123
|
+
if (validationWarning) {
|
|
120
124
|
logWarn(validationWarning, options);
|
|
125
|
+
}
|
|
121
126
|
// Multi-folder mode: if no root lockfile and 2+ nested lockfiles exist,
|
|
122
127
|
// route to dedicated multi-folder handler instead of single-lockfile scan
|
|
123
128
|
const nestedLockfiles = findNestedLockfiles(projectPath, searchDepth);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { pluralize } from "../utils/string.js";
|
|
2
|
+
/** Compact finding-block cap. Selection still lives in `selectFindingsForCompact`. */
|
|
3
|
+
export const COMPACT_FINDING_BLOCK_LIMIT = 3;
|
|
4
|
+
/** Compact suggested-fix section cap. Hidden sections keep their original order. */
|
|
5
|
+
export const COMPACT_COMMAND_GROUP_LIMIT = 3;
|
|
6
|
+
/**
|
|
7
|
+
* Disclosure line printed after the last compact finding block when more
|
|
8
|
+
* findings exist than were shown. Returns null when nothing was withheld, so
|
|
9
|
+
* compact output stays quiet when it already shows everything.
|
|
10
|
+
*/
|
|
11
|
+
export function formatCompactFindingTruncationNotice(shownCount, totalCount) {
|
|
12
|
+
if (shownCount >= totalCount)
|
|
13
|
+
return null;
|
|
14
|
+
return `Showing ${shownCount} of ${totalCount} findings. Run --verbose --all to see them all.`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Disclosure line printed after the last compact suggested-fix section when
|
|
18
|
+
* sections were omitted. Count and severities are derived from the hidden
|
|
19
|
+
* sections themselves so the message stays honest when the mix differs.
|
|
20
|
+
*/
|
|
21
|
+
export function formatCompactCommandGroupTruncationNotice(hiddenSections) {
|
|
22
|
+
if (hiddenSections.length === 0)
|
|
23
|
+
return null;
|
|
24
|
+
const count = hiddenSections.length;
|
|
25
|
+
const severities = [];
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
for (const section of hiddenSections) {
|
|
28
|
+
if (seen.has(section.severity))
|
|
29
|
+
continue;
|
|
30
|
+
seen.add(section.severity);
|
|
31
|
+
severities.push(section.severity);
|
|
32
|
+
}
|
|
33
|
+
const severityPart = severities.length > 0 ? ` (${severities.join(", ")})` : "";
|
|
34
|
+
return `${count} more ${pluralize(count, "command group")}${severityPart}. Run --verbose to see them.`;
|
|
35
|
+
}
|
|
@@ -3,11 +3,12 @@ import { chalk } from "../utils/chalk.js";
|
|
|
3
3
|
import { severityOrder, MAL_PRIVATE_REGISTRY_MESSAGE, MAL_GIT_SOURCE_PINNED_MESSAGE, MAL_GIT_SOURCE_FLOATING_MESSAGE, } from "../constants.js";
|
|
4
4
|
import { loadCache } from "../osv/cache.js";
|
|
5
5
|
import { inferSeverity } from "../osv/severity.js";
|
|
6
|
-
import { getPrimaryParent, getRootDependencies } from "../utils/finding.js";
|
|
6
|
+
import { getPrimaryParent, getRootDependencies, isUnconfirmedFix } from "../utils/finding.js";
|
|
7
7
|
import { calculatePathCoverage, formatDependencyPath } from "../utils/path-coverage.js";
|
|
8
8
|
import { pluralize } from "../utils/string.js";
|
|
9
9
|
import { hasMaliciousAdvisory } from "../utils/vuln.js";
|
|
10
10
|
import { computePrioritySignal } from "../utils/priority-signal.js";
|
|
11
|
+
import { computeContextualSignals } from "../utils/contextual-signals.js";
|
|
11
12
|
export function formatRelationshipLabel(value) {
|
|
12
13
|
if (value.startsWith("direct"))
|
|
13
14
|
return chalk.green(value);
|
|
@@ -68,6 +69,9 @@ export function getRecommendedAction(finding) {
|
|
|
68
69
|
// may itself be vulnerable), and the validated target is what the fix
|
|
69
70
|
// command actually uses.
|
|
70
71
|
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
72
|
+
if (isUnconfirmedFix(finding)) {
|
|
73
|
+
return `Verify a safe version of ${finding.pkg.name} before upgrading.`;
|
|
74
|
+
}
|
|
71
75
|
if (finding.relationship === "direct" && directTarget) {
|
|
72
76
|
return `Upgrade ${finding.pkg.name} to ${directTarget}+ in this project.`;
|
|
73
77
|
}
|
|
@@ -143,7 +147,7 @@ export function summarizeRisk(finding) {
|
|
|
143
147
|
else {
|
|
144
148
|
risk = "Review this finding and inspect the dependency path for the safest upgrade path.";
|
|
145
149
|
}
|
|
146
|
-
if (finding.usage &&
|
|
150
|
+
if (finding.usage && finding.usage.imported === false) {
|
|
147
151
|
if (finding.relationship === "transitive") {
|
|
148
152
|
risk = risk.replace("Transitive issue.", "Transitive issue. No direct imports found in source code, so practical reachability may be low.");
|
|
149
153
|
}
|
|
@@ -176,6 +180,9 @@ export function summarizeNextAction(finding) {
|
|
|
176
180
|
? "This package has a malicious code advisory. Remove it from your dependencies."
|
|
177
181
|
: "This package has a malicious code advisory. Upgrade or remove the parent package that pulls it in.";
|
|
178
182
|
}
|
|
183
|
+
if (isUnconfirmedFix(finding)) {
|
|
184
|
+
return `Verify a safe version of ${finding.pkg.name} before upgrading.`;
|
|
185
|
+
}
|
|
179
186
|
if (finding.relationship === "direct" && directTarget) {
|
|
180
187
|
return `Upgrade ${finding.pkg.name} toward ${directTarget}.`;
|
|
181
188
|
}
|
|
@@ -244,6 +251,7 @@ export function serializeFinding(finding, plan) {
|
|
|
244
251
|
cves: finding.cveAliases,
|
|
245
252
|
epssScores: finding.epssScores ?? null,
|
|
246
253
|
prioritySignal: computePrioritySignal(finding.severity, finding.epssScores) ?? null,
|
|
254
|
+
contextualSignals: computeContextualSignals(finding),
|
|
247
255
|
dependencyPaths: finding.dependencyPaths,
|
|
248
256
|
usage: finding.usage ?? null,
|
|
249
257
|
maliciousUnverifiable: finding.maliciousUnverifiable ?? false,
|
|
@@ -14,6 +14,7 @@ import { PRIORITY_SIGNAL_LABELS, PRIORITY_SIGNAL_DESCRIPTIONS, PRIORITY_SIGNAL_L
|
|
|
14
14
|
import { UNVERIFIED_PARENT_UPGRADE_NOTE } from "../remediation/fix-commands.js";
|
|
15
15
|
import { formatParentUpdateChildNote } from "../remediation/parent-update-child-note.js";
|
|
16
16
|
import { getCompletenessImpact } from "../scan/completeness.js";
|
|
17
|
+
import { isUnconfirmedFix } from "../utils/finding.js";
|
|
17
18
|
export function serializeHtmlFinding(finding, plan) {
|
|
18
19
|
return {
|
|
19
20
|
...serializeFinding(finding, plan),
|
|
@@ -35,6 +36,7 @@ export function buildReportData(params) {
|
|
|
35
36
|
warnings: params.warnings,
|
|
36
37
|
skippedDependencies: params.skippedDependencies,
|
|
37
38
|
overrideFindings: params.overrideFindings,
|
|
39
|
+
skippedOverrideRules: params.skippedOverrideRules,
|
|
38
40
|
maintenanceFindings: params.maintenanceFindings,
|
|
39
41
|
licenseFindings: params.licenseFindings,
|
|
40
42
|
licenseLimitedToDirectOnly: params.licenseLimitedToDirectOnly,
|
|
@@ -206,6 +208,11 @@ button.header-link:hover{color:var(--link);border-color:var(--link)}
|
|
|
206
208
|
.override-hygiene table tbody tr:last-child{border-bottom:none}
|
|
207
209
|
.override-hygiene table tbody tr:hover{background:var(--surface)}
|
|
208
210
|
.override-hygiene table tbody td{padding:11px 14px;font-size:13px;color:var(--text);vertical-align:middle}
|
|
211
|
+
.override-skipped{margin-top:14px;background:#e3b34111;border:1px solid #e3b34144;border-radius:8px;padding:12px 16px}
|
|
212
|
+
.override-skipped p{font-size:12px;color:var(--text);margin:0}
|
|
213
|
+
.override-skipped ul{margin:6px 0 0;padding:0 0 0 18px;display:flex;flex-direction:column;gap:3px}
|
|
214
|
+
.override-skipped li{font-size:11px;color:var(--text-2);line-height:1.5}
|
|
215
|
+
.override-skipped code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;color:var(--text)}
|
|
209
216
|
.maintenance-risk{margin:0 32px 32px}
|
|
210
217
|
.maintenance-risk h2{font-size:13px;font-weight:600;color:var(--text);margin-bottom:12px}
|
|
211
218
|
.maintenance-risk p{font-size:13px;color:var(--text-2)}
|
|
@@ -228,7 +235,15 @@ button.header-link:hover{color:var(--link);border-color:var(--link)}
|
|
|
228
235
|
.priority-legend-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:10px}
|
|
229
236
|
.priority-legend-item{display:flex;align-items:flex-start;gap:10px;font-size:12px;color:var(--text-2);line-height:1.5}
|
|
230
237
|
.sev-dev-note{text-align:center;font-size:12px;color:var(--text-2);margin:-12px 0 16px;padding:0 32px}`;
|
|
231
|
-
|
|
238
|
+
function embedJson(value) {
|
|
239
|
+
return JSON.stringify(value)
|
|
240
|
+
.replace(/</g, "\\u003c")
|
|
241
|
+
.replace(/>/g, "\\u003e")
|
|
242
|
+
.replace(/&/g, "\\u0026")
|
|
243
|
+
.replace(/\u2028/g, "\\u2028")
|
|
244
|
+
.replace(/\u2029/g, "\\u2029");
|
|
245
|
+
}
|
|
246
|
+
export function renderHtmlReport(data, jsonPayload) {
|
|
232
247
|
const projectName = path.basename(data.projectPath);
|
|
233
248
|
const scanDate = new Date(data.scannedAt).toLocaleString();
|
|
234
249
|
const counts = { critical: 0, high: 0, medium: 0, low: 0, unknown: 0, none: 0 };
|
|
@@ -250,12 +265,7 @@ export function renderHtmlReport(data) {
|
|
|
250
265
|
const skippedDepsHtml = renderSkippedDependenciesSection(data.skippedDependencies);
|
|
251
266
|
const duplicatePackagesHtml = renderDuplicatePackagesSection(data.findings);
|
|
252
267
|
const findingRowsHtml = data.findings.map((f, i) => renderFindingRow(f, i, skippedKeys)).join("\n");
|
|
253
|
-
const dataJson =
|
|
254
|
-
.replace(/</g, "\\u003c")
|
|
255
|
-
.replace(/>/g, "\\u003e")
|
|
256
|
-
.replace(/&/g, "\\u0026")
|
|
257
|
-
.replace(/\u2028/g, "\\u2028")
|
|
258
|
-
.replace(/\u2029/g, "\\u2029");
|
|
268
|
+
const dataJson = embedJson(jsonPayload ?? data);
|
|
259
269
|
return `<!DOCTYPE html>
|
|
260
270
|
<html lang="en">
|
|
261
271
|
<head>
|
|
@@ -361,7 +371,7 @@ ${findingRowsHtml}
|
|
|
361
371
|
</table>
|
|
362
372
|
${renderPriorityLegendHtml(data.findings)}
|
|
363
373
|
</div>
|
|
364
|
-
${renderOverrideFindingsHtml(data.overrideFindings, data.projectPath)}
|
|
374
|
+
${renderOverrideFindingsHtml(data.overrideFindings, data.projectPath, data.skippedOverrideRules)}
|
|
365
375
|
${renderMaintenanceFindingsHtml(data.maintenanceFindings)}
|
|
366
376
|
${renderLicenseFindingsHtml(data.licenseFindings, { limitedToDirectOnly: data.licenseLimitedToDirectOnly })}
|
|
367
377
|
${skippedDepsHtml}
|
|
@@ -605,9 +615,10 @@ export function renderFindingRow(finding, idx, skippedKeys) {
|
|
|
605
615
|
: finding.vulnerabilities.map(v => advisoryLink(v.id)).join(", ");
|
|
606
616
|
const isMalicious = hasMaliciousAdvisory(finding.vulnerabilities);
|
|
607
617
|
const isSkipped = skippedKeys?.has(`${finding.package}@${finding.version}`);
|
|
618
|
+
const unconfirmed = isUnconfirmedFix(finding);
|
|
608
619
|
const fixVersion = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
609
|
-
const fixHtml = isSkipped && fixVersion
|
|
610
|
-
? `<span class="fix-hint hint-only" title="Advisory hint only —
|
|
620
|
+
const fixHtml = (isSkipped || unconfirmed) && fixVersion
|
|
621
|
+
? `<span class="fix-hint hint-only" title="Advisory hint only — a safe fix has not been confirmed.">${escapeHtml(fixVersion)} ⊘</span>`
|
|
611
622
|
: fixVersion
|
|
612
623
|
? `<span class="fix-hint">${escapeHtml(fixVersion)}</span>`
|
|
613
624
|
: isMalicious && finding.maliciousUnverifiable
|
|
@@ -682,6 +693,7 @@ export function renderFindingRow(finding, idx, skippedKeys) {
|
|
|
682
693
|
<div class="detail-col">
|
|
683
694
|
<h4>Recommended action</h4>
|
|
684
695
|
${recommendedActionHtml}
|
|
696
|
+
${finding.fixVersionValidationNote ? `<p class="fix-cmd-note">${escapeHtml(finding.fixVersionValidationNote)}</p>` : ""}
|
|
685
697
|
<h4 class="detail-subheading">Risk summary</h4>
|
|
686
698
|
<p>${escapeHtml(finding.riskSummary)}</p>
|
|
687
699
|
<h4 class="detail-subheading">Next action</h4>
|
|
@@ -931,8 +943,8 @@ export async function writeHtmlReport(params) {
|
|
|
931
943
|
const indexPath = path.join(params.outputDir, "index.html");
|
|
932
944
|
const jsonPath = path.join(params.outputDir, "report.json");
|
|
933
945
|
try {
|
|
934
|
-
fs.writeFileSync(jsonPath, JSON.stringify(params.
|
|
935
|
-
fs.writeFileSync(indexPath, renderHtmlReport(params.data), "utf8");
|
|
946
|
+
fs.writeFileSync(jsonPath, JSON.stringify(params.jsonPayload, null, 2), "utf8");
|
|
947
|
+
fs.writeFileSync(indexPath, renderHtmlReport(params.data, params.jsonPayload), "utf8");
|
|
936
948
|
}
|
|
937
949
|
catch (err) {
|
|
938
950
|
if (!dirExisted) {
|
|
@@ -6,6 +6,7 @@ import { renderOverrideFindingsHtml } from "./override-findings-html.js";
|
|
|
6
6
|
import { renderMaintenanceFindingsHtml } from "./maintenance-findings-html.js";
|
|
7
7
|
import { renderLicenseFindingsHtml } from "./license-findings-html.js";
|
|
8
8
|
import { loadLogoDataUri } from "./logos.js";
|
|
9
|
+
import { buildMultiFolderScanJson } from "./scan-json.js";
|
|
9
10
|
import { pluralize } from "../utils/string.js";
|
|
10
11
|
export function buildMultiFolderReportData(params) {
|
|
11
12
|
const findings = params.results.flatMap((r, i) => params.serializedByFolder[i].map(f => ({
|
|
@@ -42,12 +43,16 @@ function summaryCounts(results) {
|
|
|
42
43
|
}
|
|
43
44
|
return counts;
|
|
44
45
|
}
|
|
45
|
-
function renderFolderNotices(coverage) {
|
|
46
|
-
if (coverage.length === 0)
|
|
46
|
+
function renderFolderNotices(coverage, warnings) {
|
|
47
|
+
if (coverage.length === 0 && warnings.length === 0)
|
|
47
48
|
return "";
|
|
48
|
-
const
|
|
49
|
+
const total = coverage.length + warnings.length;
|
|
50
|
+
const items = [
|
|
51
|
+
...coverage.map(n => `<li>${escapeHtml(n)}</li>`),
|
|
52
|
+
...warnings.map(w => `<li class="warning">${escapeHtml(w)}</li>`),
|
|
53
|
+
].join("\n");
|
|
49
54
|
return `<div class="scan-notes" style="margin:16px 32px">
|
|
50
|
-
<button class="scan-notes-toggle" onclick="toggleNotes(this)"><span class="arrow">▶</span> Scan notes (${
|
|
55
|
+
<button class="scan-notes-toggle" onclick="toggleNotes(this)"><span class="arrow">▶</span> Scan notes (${total})</button>
|
|
51
56
|
<div class="scan-notes-body"><ul>${items}</ul></div>
|
|
52
57
|
</div>`;
|
|
53
58
|
}
|
|
@@ -67,10 +72,10 @@ function renderFolderSection(result, folderIdx, idxOffset, serialized, projectRo
|
|
|
67
72
|
const fi = folderIdx;
|
|
68
73
|
const findingRowsHtml = serialized.map((f, i) => renderFindingRow(f, idxOffset + i)).join("\n");
|
|
69
74
|
const fixPlanHtml = renderFixPlan(result.suggestedFixCommands);
|
|
70
|
-
const noticesHtml = renderFolderNotices(result.coverage);
|
|
75
|
+
const noticesHtml = renderFolderNotices(result.coverage, result.scanInput.warnings);
|
|
71
76
|
const folderAbs = path.join(projectRoot, result.subfolder);
|
|
72
77
|
const overrideHtml = includeOverrides
|
|
73
|
-
? renderOverrideFindingsHtml(result.overrideFindings, folderAbs)
|
|
78
|
+
? renderOverrideFindingsHtml(result.overrideFindings, folderAbs, result.overrideSkipped)
|
|
74
79
|
: "";
|
|
75
80
|
const maintenanceHtml = includeMaintenance
|
|
76
81
|
? renderMaintenanceFindingsHtml(result.maintenanceFindings)
|
|
@@ -382,9 +387,23 @@ document.addEventListener('click', function(e) {
|
|
|
382
387
|
</script>
|
|
383
388
|
</body>
|
|
384
389
|
</html>`;
|
|
390
|
+
// Same --json multi-folder shape, plus cliVersion for saved-artifact provenance
|
|
391
|
+
// (scannedAt is already on the multi-folder payload) and per-finding
|
|
392
|
+
// riskSummary/nextAction from serializeHtmlFinding.
|
|
393
|
+
const jsonPayload = {
|
|
394
|
+
...buildMultiFolderScanJson({
|
|
395
|
+
results: params.results,
|
|
396
|
+
projectPath: params.projectPath,
|
|
397
|
+
includeOverrides: params.includeOverrides,
|
|
398
|
+
includeMaintenance: params.includeMaintenance,
|
|
399
|
+
includeLicenses: params.includeLicenses,
|
|
400
|
+
}),
|
|
401
|
+
cliVersion: params.cliVersion,
|
|
402
|
+
findings: reportData.findings,
|
|
403
|
+
};
|
|
385
404
|
const indexPath = path.join(params.outputDir, "index.html");
|
|
386
405
|
const jsonPath = path.join(params.outputDir, "report.json");
|
|
387
|
-
fs.writeFileSync(jsonPath, JSON.stringify(
|
|
406
|
+
fs.writeFileSync(jsonPath, JSON.stringify(jsonPayload, null, 2), "utf8");
|
|
388
407
|
fs.writeFileSync(indexPath, html, "utf8");
|
|
389
408
|
if (params.autoOpen)
|
|
390
409
|
openInBrowser(indexPath);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { relative } from "node:path";
|
|
2
|
+
import { groupSkippedByReason, skippedHeadline, skippedRuleCount } from "./skipped-override-rules.js";
|
|
2
3
|
import { SEVERITY_ORDER } from "../utils/severity.js";
|
|
3
4
|
import { OVERRIDES_COMMAND } from "../constants.js";
|
|
4
5
|
function esc(s) {
|
|
@@ -8,7 +9,27 @@ function esc(s) {
|
|
|
8
9
|
.replace(/>/g, ">")
|
|
9
10
|
.replace(/"/g, """);
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The rules that could not run, rendered inside the panel. Without this the panel can say
|
|
14
|
+
* "No override hygiene findings" while a rule never ran, which is the same false all-clear
|
|
15
|
+
* the terminal output had (#1222). Reasons embed upstream error text, so they are escaped.
|
|
16
|
+
*/
|
|
17
|
+
function skippedNoticeHtml(skipped) {
|
|
18
|
+
if (!skipped || skipped.length === 0)
|
|
19
|
+
return "";
|
|
20
|
+
const items = groupSkippedByReason(skipped)
|
|
21
|
+
.map(({ reason, ruleIds }) => ` <li><code>${esc(ruleIds.join(", "))}</code> - ${esc(reason)}</li>`)
|
|
22
|
+
.join("\n");
|
|
23
|
+
return `
|
|
24
|
+
<div class="override-skipped">
|
|
25
|
+
<p><strong>\u26a0 ${esc(skippedHeadline(skippedRuleCount(skipped)))}</strong></p>
|
|
26
|
+
<ul>
|
|
27
|
+
${items}
|
|
28
|
+
</ul>
|
|
29
|
+
</div>
|
|
30
|
+
`;
|
|
31
|
+
}
|
|
32
|
+
export function renderOverrideFindingsHtml(findings, projectPath, skipped) {
|
|
12
33
|
// undefined = override hygiene was never requested -> render nothing, so a plain
|
|
13
34
|
// `cve-lite .` report shows no Override hygiene panel at all. An empty array =
|
|
14
35
|
// it ran and found nothing -> render the "no findings" reassurance.
|
|
@@ -20,7 +41,7 @@ export function renderOverrideFindingsHtml(findings, projectPath) {
|
|
|
20
41
|
<section class="override-hygiene">
|
|
21
42
|
<h2>Override hygiene</h2>
|
|
22
43
|
<p>No override hygiene findings.</p>
|
|
23
|
-
</section>
|
|
44
|
+
${skippedNoticeHtml(skipped)}</section>
|
|
24
45
|
`;
|
|
25
46
|
}
|
|
26
47
|
const sorted = [...findings].sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity));
|
|
@@ -55,6 +76,6 @@ export function renderOverrideFindingsHtml(findings, projectPath) {
|
|
|
55
76
|
${rows.join("\n")}
|
|
56
77
|
</tbody>
|
|
57
78
|
</table>
|
|
58
|
-
</section>
|
|
79
|
+
${skippedNoticeHtml(skipped)}</section>
|
|
59
80
|
`;
|
|
60
81
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export function overrideFindingsToJson(findings) {
|
|
2
|
-
return {
|
|
1
|
+
export function overrideFindingsToJson(findings, skipped) {
|
|
2
|
+
return {
|
|
3
|
+
overrideFindings: [...findings],
|
|
4
|
+
...(skipped ? { skippedOverrideRules: [...skipped] } : {}),
|
|
5
|
+
};
|
|
3
6
|
}
|
|
@@ -12,6 +12,7 @@ const OA_RULES = [
|
|
|
12
12
|
{ id: "OA008", name: "MaterializedVulnerable", shortDescription: "Vulnerable copy still on disk", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA008.md" },
|
|
13
13
|
{ id: "OA009", name: "StaleFloor", shortDescription: "Override floor already met by all parent declarations", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA009.md" },
|
|
14
14
|
{ id: "OA010", name: "VulnerableFloor", shortDescription: "Override floor admits a known-vulnerable version", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA010.md" },
|
|
15
|
+
{ id: "OA011", name: "OverReachingFloor", shortDescription: "Override floor exceeds every declaring package's range", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA011.md" },
|
|
15
16
|
{ id: "PD001", name: "OverrideOnlyPhantom", shortDescription: "Package imported in source but only present via override pin - declare it as a dependency", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/PD001.md" },
|
|
16
17
|
{ id: "PD002", name: "TransitiveOnlyPhantom", shortDescription: "Package imported in source but only present as a transitive dependency - declare it explicitly", helpUri: "https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/PD002.md" },
|
|
17
18
|
];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { relative } from "node:path";
|
|
2
|
+
import { groupSkippedByReason, skippedHeadline, skippedRuleCount } from "./skipped-override-rules.js";
|
|
2
3
|
import { chalk, stripAnsi } from "../utils/chalk.js";
|
|
3
4
|
import { formatSeverityLabel, SEVERITY_ORDER } from "../utils/severity.js";
|
|
4
5
|
import { pluralize } from "../utils/string.js";
|
|
@@ -18,7 +19,12 @@ export function renderOverrideFindings(findings, options) {
|
|
|
18
19
|
}
|
|
19
20
|
lines.push("");
|
|
20
21
|
if (findings.length === 0) {
|
|
21
|
-
|
|
22
|
+
// Qualified when rules were skipped. An unqualified tick is the line a skimming reader
|
|
23
|
+
// takes away, and this whole feature exists because a clean bill of health from an
|
|
24
|
+
// incomplete audit is worse than no audit.
|
|
25
|
+
lines.push(chalk.greenBright(options?.rulesSkipped
|
|
26
|
+
? "✔ No override hygiene issues found in the rules that ran."
|
|
27
|
+
: "✔ No override hygiene issues found."));
|
|
22
28
|
return lines.join("\n");
|
|
23
29
|
}
|
|
24
30
|
const grouped = new Map();
|
|
@@ -122,3 +128,17 @@ function wrapText(text, width) {
|
|
|
122
128
|
lines.push(remaining);
|
|
123
129
|
return lines.length > 0 ? lines : [text];
|
|
124
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Renders the rules that could not run. Printed whether or not there are findings,
|
|
133
|
+
* because the case this exists for is a scan that reports nothing: a clean bill of
|
|
134
|
+
* health from an audit that skipped a rule is worse than no audit at all (#1222).
|
|
135
|
+
*/
|
|
136
|
+
export function renderSkippedOverrideRules(skipped) {
|
|
137
|
+
if (skipped.length === 0)
|
|
138
|
+
return "";
|
|
139
|
+
const lines = [chalk.yellow(`\u26a0 ${skippedHeadline(skippedRuleCount(skipped))}`)];
|
|
140
|
+
for (const { reason, ruleIds } of groupSkippedByReason(skipped)) {
|
|
141
|
+
lines.push(` ${ruleIds.join(", ")} - ${reason}`);
|
|
142
|
+
}
|
|
143
|
+
return lines.join("\n");
|
|
144
|
+
}
|