cve-lite-cli 1.26.0 → 1.28.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 +147 -398
- package/dist/advisory/osv-advisory-source.js +5 -3
- package/dist/cli/advisories-init.js +24 -0
- package/dist/cli/args.js +36 -0
- package/dist/cli/help.js +9 -5
- package/dist/cli/overrides.js +20 -16
- package/dist/constants.js +1 -0
- package/dist/index.js +61 -39
- package/dist/maintenance/dm001-maintenance-risk.js +63 -0
- package/dist/maintenance/types.js +1 -0
- package/dist/osv/cache.js +49 -50
- package/dist/output/debug.js +2 -1
- package/dist/output/formatters.js +17 -3
- package/dist/output/html-reporter.js +156 -102
- package/dist/output/logos.js +1 -1
- package/dist/output/maintenance-findings-html.js +56 -0
- package/dist/output/maintenance-findings-json.js +3 -0
- package/dist/output/maintenance-terminal.js +80 -0
- package/dist/output/override-findings-html.js +24 -28
- package/dist/output/override-findings-sarif.js +34 -24
- package/dist/output/override-findings-terminal.js +19 -2
- package/dist/output/printers.js +19 -6
- package/dist/output/sarif.js +14 -6
- package/dist/output/spinner.js +5 -0
- package/dist/output/write-outputs.js +3 -1
- package/dist/overrides/context-builder.js +29 -0
- package/dist/overrides/detectors/index.js +6 -0
- package/dist/overrides/detectors/oa009-stale-floor.js +80 -0
- package/dist/overrides/detectors/pd001-override-only-phantom.js +32 -0
- package/dist/overrides/detectors/pd002-transitive-only-phantom.js +34 -0
- package/dist/overrides/detectors/phantom-utils.js +21 -0
- package/dist/overrides/fixer.js +21 -1
- package/dist/remediation/cooldown.js +74 -0
- package/dist/remediation/fix-commands.js +42 -2
- package/dist/remediation/npm-registry.js +11 -0
- package/dist/remediation/parent-upgrade.js +114 -18
- package/dist/scan/multi-folder-scan.js +35 -10
- package/dist/scanner.js +86 -22
- package/dist/usage/scanner.js +60 -1
- package/dist/utils/network.js +77 -0
- package/dist/utils/sarif.js +4 -0
- package/dist/utils/severity.js +6 -0
- package/package.json +2 -1
|
@@ -2,9 +2,11 @@ import { extractErrorMessage } from "../utils/network.js";
|
|
|
2
2
|
export class OsvAdvisorySource {
|
|
3
3
|
baseUrl;
|
|
4
4
|
debugLog;
|
|
5
|
-
|
|
5
|
+
fetchImpl;
|
|
6
|
+
constructor(baseUrl = "https://api.osv.dev", debugLog, fetchImpl) {
|
|
6
7
|
this.baseUrl = baseUrl;
|
|
7
8
|
this.debugLog = debugLog;
|
|
9
|
+
this.fetchImpl = fetchImpl ?? fetch;
|
|
8
10
|
}
|
|
9
11
|
async queryBatch(packages, meta) {
|
|
10
12
|
const requestUrl = `${this.baseUrl}/v1/querybatch`;
|
|
@@ -35,7 +37,7 @@ export class OsvAdvisorySource {
|
|
|
35
37
|
})),
|
|
36
38
|
});
|
|
37
39
|
}
|
|
38
|
-
const response = await
|
|
40
|
+
const response = await this.fetchImpl(requestUrl, {
|
|
39
41
|
method: "POST",
|
|
40
42
|
headers: {
|
|
41
43
|
"Content-Type": "application/json",
|
|
@@ -90,7 +92,7 @@ export class OsvAdvisorySource {
|
|
|
90
92
|
headers: {},
|
|
91
93
|
});
|
|
92
94
|
}
|
|
93
|
-
const response = await
|
|
95
|
+
const response = await this.fetchImpl(requestUrl, { redirect: "error" });
|
|
94
96
|
if (this.debugLog) {
|
|
95
97
|
this.debugLog("OSV response", {
|
|
96
98
|
method: "GET",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { LocalAdvisoryDatabase } from "../advisory/local-db.js";
|
|
3
|
+
import { getDefaultAdvisoryDbPath } from "../advisory/osv-sync.js";
|
|
4
|
+
/**
|
|
5
|
+
* Creates an empty local advisory database with the current schema and no data.
|
|
6
|
+
* This is for air-gapped users who cannot run `advisories sync`: they run
|
|
7
|
+
* `advisories init`, populate the database from their own sources, and then scan
|
|
8
|
+
* with `--offline-db`.
|
|
9
|
+
*
|
|
10
|
+
* Returns the resolved path of the database that was created. Throws if a file
|
|
11
|
+
* already exists at that path, so an existing (possibly populated) database is
|
|
12
|
+
* never silently reused.
|
|
13
|
+
*/
|
|
14
|
+
export function initAdvisoryDatabase(outputPath) {
|
|
15
|
+
const dbPath = getDefaultAdvisoryDbPath(outputPath);
|
|
16
|
+
if (existsSync(dbPath)) {
|
|
17
|
+
throw new Error(`${dbPath} already exists. Delete it or choose a different --output path before running init.`);
|
|
18
|
+
}
|
|
19
|
+
// Opening a writable database runs the schema (CREATE TABLE IF NOT EXISTS),
|
|
20
|
+
// which is exactly an empty, correctly-shaped database.
|
|
21
|
+
const db = new LocalAdvisoryDatabase(dbPath);
|
|
22
|
+
db.close();
|
|
23
|
+
return dbPath;
|
|
24
|
+
}
|
package/dist/cli/args.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { ConfigAction, ConfigKey } from "./config.js";
|
|
2
2
|
export function parseArgs(argv) {
|
|
3
|
+
// Normalize "cve-lite <path> overrides [flags]" to "cve-lite overrides <path> [flags]"
|
|
4
|
+
// so both orderings work. Only reorder when "overrides" is a bare positional (not argv[0]).
|
|
5
|
+
const overridesIdx = argv.indexOf("overrides");
|
|
6
|
+
if (overridesIdx > 0 && !argv[overridesIdx - 1].startsWith("-")) {
|
|
7
|
+
argv = ["overrides", ...argv.slice(0, overridesIdx), ...argv.slice(overridesIdx + 1)];
|
|
8
|
+
}
|
|
3
9
|
const options = {
|
|
4
10
|
failOn: "critical",
|
|
5
11
|
batchSize: "100",
|
|
@@ -46,6 +52,32 @@ export function parseArgs(argv) {
|
|
|
46
52
|
}
|
|
47
53
|
return { command: "advisories-sync", options };
|
|
48
54
|
}
|
|
55
|
+
if (argv[0] === "advisories" && argv[1] === "init") {
|
|
56
|
+
for (let i = 2; i < argv.length; i++) {
|
|
57
|
+
const arg = argv[i];
|
|
58
|
+
if (arg === "-h" || arg === "--help") {
|
|
59
|
+
options.help = true;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (arg === "-v" || arg === "--version") {
|
|
63
|
+
options.version = true;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (arg === "--output") {
|
|
67
|
+
options.output = argv[++i];
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (arg.startsWith("--output=")) {
|
|
71
|
+
options.output = arg.slice("--output=".length);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (arg.startsWith("-")) {
|
|
75
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Unexpected argument: ${arg}`);
|
|
78
|
+
}
|
|
79
|
+
return { command: "advisories-init", options };
|
|
80
|
+
}
|
|
49
81
|
if (argv[0] === "install-skill") {
|
|
50
82
|
for (let i = 1; i < argv.length; i++) {
|
|
51
83
|
const arg = argv[i];
|
|
@@ -333,6 +365,10 @@ export function parseArgs(argv) {
|
|
|
333
365
|
options.checkOverrides = true;
|
|
334
366
|
continue;
|
|
335
367
|
}
|
|
368
|
+
if (arg === "--check-maintenance") {
|
|
369
|
+
options.checkMaintenance = true;
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
336
372
|
if (arg.startsWith("-")) {
|
|
337
373
|
throw new Error(`Unknown option: ${arg}`);
|
|
338
374
|
}
|
package/dist/cli/help.js
CHANGED
|
@@ -24,6 +24,7 @@ export function printHelp() {
|
|
|
24
24
|
"Usage:",
|
|
25
25
|
" cve-lite [projectPath] [options]",
|
|
26
26
|
" cve-lite advisories sync [options]",
|
|
27
|
+
" cve-lite advisories init [options]",
|
|
27
28
|
" cve-lite install-skill",
|
|
28
29
|
" cve-lite config <set|unset|show> [key] [value]",
|
|
29
30
|
" cve-lite overrides [path] [flags]",
|
|
@@ -44,8 +45,10 @@ export function printHelp() {
|
|
|
44
45
|
" --debug Write verbose runtime/network diagnostics to a timestamped log file",
|
|
45
46
|
" --verbose Show detailed output with fix plan, paths, and full table",
|
|
46
47
|
" --prod-only Exclude dev dependencies where available",
|
|
47
|
-
" --check-overrides Also audit package.json overrides (OA001-
|
|
48
|
+
" --check-overrides Also audit package.json overrides (OA001-OA009, PD001-PD002); findings",
|
|
48
49
|
" print, thread to JSON/SARIF/HTML, and count toward --fail-on",
|
|
50
|
+
" --check-maintenance Also flag direct deps that block a transitive CVE fix via a major-version",
|
|
51
|
+
" drag, or are marked deprecated on npm (DM001); counts toward --fail-on",
|
|
49
52
|
" --fail-on <severity> Exit non-zero at or above severity (default: critical)",
|
|
50
53
|
" --batch-size <number> OSV batch size (default: 100)",
|
|
51
54
|
" --usage Scan project source files to check if vulnerable dependencies are imported",
|
|
@@ -58,7 +61,7 @@ export function printHelp() {
|
|
|
58
61
|
" --all Show all findings in the main table",
|
|
59
62
|
" --min-severity <level> Minimum severity shown in table (default: medium)",
|
|
60
63
|
"",
|
|
61
|
-
"Advisory sync options:",
|
|
64
|
+
"Advisory sync/init options:",
|
|
62
65
|
" --output <path> Write the local advisory database to this path",
|
|
63
66
|
"",
|
|
64
67
|
"Other commands:",
|
|
@@ -80,7 +83,8 @@ export function printHelp() {
|
|
|
80
83
|
" cve-lite . --report Generate an interactive HTML report",
|
|
81
84
|
" cve-lite . --fix Apply validated direct dependency fixes and rescan",
|
|
82
85
|
" cve-lite . --offline Scan using the local advisory database (no network)",
|
|
83
|
-
" cve-lite advisories sync Sync the local advisory database"
|
|
86
|
+
" cve-lite advisories sync Sync the local advisory database",
|
|
87
|
+
" cve-lite advisories init Create an empty advisory database to populate yourself"
|
|
84
88
|
];
|
|
85
89
|
console.log(lines.join("\n"));
|
|
86
90
|
}
|
|
@@ -89,12 +93,12 @@ export function printOverridesHelp() {
|
|
|
89
93
|
const lines = [
|
|
90
94
|
"cve-lite overrides [path] [flags]",
|
|
91
95
|
"",
|
|
92
|
-
"Audit package.json overrides
|
|
96
|
+
"Audit package.json overrides and phantom dependency imports (OA001-OA009, PD001-PD002).",
|
|
93
97
|
"",
|
|
94
98
|
"Flags:",
|
|
95
99
|
" --json Emit findings as JSON",
|
|
96
100
|
" --fix Apply RFC 6902 patches for findings with auto-fix",
|
|
97
|
-
" --rule <id> Only run a specific rule (OA001-
|
|
101
|
+
" --rule <id> Only run a specific rule (OA001-OA009, PD001-PD002)",
|
|
98
102
|
" --check-network Enable OA007 registry drift check (opt-in network)",
|
|
99
103
|
" --audit-log <path> Stream NDJSON change-control to <path>",
|
|
100
104
|
" --fail-on <severity> Exit non-zero at or above this severity (default: critical)",
|
package/dist/cli/overrides.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path, { resolve } from "node:path";
|
|
2
3
|
import { buildOverrideContext, audit, applyFix } from "../overrides/index.js";
|
|
3
4
|
import { createAuditLog } from "../audit-log/index.js";
|
|
4
5
|
import { EXIT_OK, EXIT_FINDINGS, EXIT_ERROR } from "../types.js";
|
|
5
6
|
import { renderOverrideFindings } from "../output/override-findings-terminal.js";
|
|
7
|
+
import { reachesFailOn } from "../utils/severity.js";
|
|
8
|
+
import { chalk } from "../utils/chalk.js";
|
|
6
9
|
export async function runOverrides({ projectArg, options, logger, auditLog: injectedAuditLog }) {
|
|
7
10
|
const projectPath = resolve(projectArg ?? ".");
|
|
8
11
|
const ownsAuditLog = !injectedAuditLog;
|
|
@@ -29,27 +32,33 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
|
|
|
29
32
|
auditLog,
|
|
30
33
|
dryRun: false,
|
|
31
34
|
});
|
|
35
|
+
const appliedKeys = new Set(report.appliedPatches.map((p) => `${p.ruleId}:${p.package}`));
|
|
36
|
+
const remaining = findings.filter((f) => !appliedKeys.has(`${f.ruleId}:${f.package.name}`));
|
|
32
37
|
if (options.json) {
|
|
33
|
-
|
|
38
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
39
|
+
const jsonFilename = `cve-lite-overrides-${ts}.json`;
|
|
40
|
+
fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings: remaining, fixReport: report }, null, 2));
|
|
41
|
+
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
|
|
34
42
|
}
|
|
35
43
|
else {
|
|
36
44
|
logger.info(`Applied ${report.appliedPatches.length} fix${report.appliedPatches.length === 1 ? "" : "es"}; skipped ${report.skipped.length}.`);
|
|
37
|
-
|
|
45
|
+
if (remaining.length > 0) {
|
|
46
|
+
process.stdout.write(renderOverrideFindings(remaining, { projectPath }) + "\n");
|
|
47
|
+
}
|
|
38
48
|
}
|
|
39
|
-
return
|
|
40
|
-
? EXIT_FINDINGS
|
|
41
|
-
: EXIT_OK;
|
|
49
|
+
return reachesFailOn(remaining, options.failOn) ? EXIT_FINDINGS : EXIT_OK;
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
if (options.json) {
|
|
45
|
-
|
|
53
|
+
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
54
|
+
const jsonFilename = `cve-lite-overrides-${ts}.json`;
|
|
55
|
+
fs.writeFileSync(path.join(process.cwd(), jsonFilename), JSON.stringify({ findings }, null, 2));
|
|
56
|
+
console.log(`${chalk.gray("JSON saved to")} ${chalk.cyan(jsonFilename)}`);
|
|
46
57
|
}
|
|
47
58
|
else {
|
|
48
|
-
process.stdout.write(renderOverrideFindings(findings) + "\n");
|
|
59
|
+
process.stdout.write(renderOverrideFindings(findings, { projectPath }) + "\n");
|
|
49
60
|
}
|
|
50
|
-
return
|
|
51
|
-
? EXIT_FINDINGS
|
|
52
|
-
: EXIT_OK;
|
|
61
|
+
return reachesFailOn(findings, options.failOn) ? EXIT_FINDINGS : EXIT_OK;
|
|
53
62
|
}
|
|
54
63
|
catch (err) {
|
|
55
64
|
logger.error(`overrides: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -60,8 +69,3 @@ export async function runOverrides({ projectArg, options, logger, auditLog: inje
|
|
|
60
69
|
auditLog.close();
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
|
-
function reachedFailOn(findings, failOn) {
|
|
64
|
-
const rank = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
65
|
-
const threshold = rank[failOn] ?? rank.critical;
|
|
66
|
-
return findings.some((f) => (rank[f.severity] ?? 0) >= threshold);
|
|
67
|
-
}
|
package/dist/constants.js
CHANGED
|
@@ -8,6 +8,7 @@ export const severityOrder = {
|
|
|
8
8
|
};
|
|
9
9
|
export const DEFAULT_BATCH_SIZE = 100;
|
|
10
10
|
export const DEFAULT_SEARCH_DEPTH = 4;
|
|
11
|
+
export const CACHE_TTL_MS = 30 * 60 * 1000; // 30 minutes
|
|
11
12
|
export const NPM_PUBLIC_REGISTRY = "https://registry.npmjs.org/";
|
|
12
13
|
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.";
|
|
13
14
|
export const MAL_PRIVATE_REGISTRY_COMPACT_MESSAGE = "MAL- advisory could not be confirmed for this artifact.";
|
package/dist/index.js
CHANGED
|
@@ -9,24 +9,26 @@ import { loadPackages, buildNoPackagesMessage } from "./parsers/index.js";
|
|
|
9
9
|
import { scanPackages, buildCoverageNotes, createAdvisorySource } from "./scanner.js";
|
|
10
10
|
import { syncOsvAdvisories } from "./advisory/osv-sync.js";
|
|
11
11
|
import { normalizeSeverity } from "./osv/severity.js";
|
|
12
|
-
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH
|
|
12
|
+
import { DEFAULT_BATCH_SIZE, DEFAULT_SEARCH_DEPTH } from "./constants.js";
|
|
13
13
|
import { chalk } from "./utils/chalk.js";
|
|
14
14
|
import { createSpinner } from "./output/spinner.js";
|
|
15
15
|
import { createDebugLogger } from "./output/debug.js";
|
|
16
16
|
import { buildSuggestedFixCommandPlan } from "./remediation/fix-commands.js";
|
|
17
17
|
import { scanProjectForPackageUsage } from "./usage/scanner.js";
|
|
18
18
|
import { getCliVersion } from "./utils/version-info.js";
|
|
19
|
-
import {
|
|
19
|
+
import { getNetworkErrorHint, offlineDbSyncHint, createCertAwareFetch } from "./utils/network.js";
|
|
20
20
|
import { formatAdvisoryDbFreshness } from "./utils/time.js";
|
|
21
21
|
import { pluralize, nearestCommand } from "./utils/string.js";
|
|
22
22
|
import { EXIT_ERROR } from "./types.js";
|
|
23
|
-
import { formatAdvisorySourceLine, logInfo, logWarn, printCacheSummary, sortFindingsForOutput } from "./output/formatters.js";
|
|
24
|
-
import { countBySeverity } from "./utils/severity.js";
|
|
23
|
+
import { formatAdvisorySourceLine, formatHintLines, logInfo, logWarn, printCacheSummary, sortFindingsForOutput } from "./output/formatters.js";
|
|
24
|
+
import { countBySeverity, reachesFailOn } from "./utils/severity.js";
|
|
25
25
|
import { buildReportData, writeHtmlReport } from "./output/html-reporter.js";
|
|
26
26
|
import { writeOutputs } from "./output/write-outputs.js";
|
|
27
27
|
import { selectFindingsForTable } from "./output/finding-display.js";
|
|
28
28
|
import { printActionSummary, printCompactOutput, printCoverage, printFinalStatus, printOverrideHint, printSkippedDependencies, printSuggestedFixCommands, printSuggestedFixCommandSkips, printSummary, printTable, } from "./output/printers.js";
|
|
29
29
|
import { renderOverrideFindings } from "./output/override-findings-terminal.js";
|
|
30
|
+
import { detectDM001 } from "./maintenance/dm001-maintenance-risk.js";
|
|
31
|
+
import { renderMaintenanceFindings } from "./output/maintenance-terminal.js";
|
|
30
32
|
import { installSkill } from "./skills/install.js";
|
|
31
33
|
import { readConfig, validateCaCertFile } from "./cli/config.js";
|
|
32
34
|
import { runConfigCommand } from "./cli/config-command.js";
|
|
@@ -125,6 +127,7 @@ if (parsedArgs) {
|
|
|
125
127
|
}
|
|
126
128
|
process.env.NODE_EXTRA_CA_CERTS = resolvedCaCert;
|
|
127
129
|
}
|
|
130
|
+
const certFetch = resolvedCaCert ? createCertAwareFetch(resolvedCaCert) : undefined;
|
|
128
131
|
debugLog("Config loaded", {
|
|
129
132
|
caCert: resolvedCaCert ?? null,
|
|
130
133
|
nodeExtraCaCerts: process.env.NODE_EXTRA_CA_CERTS ?? null,
|
|
@@ -134,6 +137,7 @@ if (parsedArgs) {
|
|
|
134
137
|
const usePlainProgressLogs = !process.stdout.isTTY || !!options.json;
|
|
135
138
|
const result = await syncOsvAdvisories({
|
|
136
139
|
outputPath: options.output,
|
|
140
|
+
fetchImpl: certFetch,
|
|
137
141
|
onProgress: event => {
|
|
138
142
|
if (event.phase === "complete") {
|
|
139
143
|
return;
|
|
@@ -155,6 +159,20 @@ if (parsedArgs) {
|
|
|
155
159
|
process.exit(0);
|
|
156
160
|
return;
|
|
157
161
|
}
|
|
162
|
+
if (command === "advisories-init") {
|
|
163
|
+
try {
|
|
164
|
+
const { initAdvisoryDatabase } = await import("./cli/advisories-init.js");
|
|
165
|
+
const dbPath = initAdvisoryDatabase(options.output);
|
|
166
|
+
console.log(`${chalk.gray("Advisory database:")} created an empty advisory database at ${chalk.cyan(dbPath)}`);
|
|
167
|
+
console.log(chalk.gray(`Populate it from your own sources, then scan with \`--offline-db ${dbPath}\`.`));
|
|
168
|
+
process.exit(0);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
158
176
|
if (command === "install-skill") {
|
|
159
177
|
installSkill(process.cwd());
|
|
160
178
|
process.exit(0);
|
|
@@ -184,8 +202,9 @@ if (parsedArgs) {
|
|
|
184
202
|
// route to dedicated multi-folder handler instead of single-lockfile scan
|
|
185
203
|
const nestedLockfiles = findNestedLockfiles(projectPath, searchDepth);
|
|
186
204
|
if (!hasRootLockfile(projectPath) && nestedLockfiles.length >= 2) {
|
|
187
|
-
await handleMultiFolderScan({ projectRoot: projectPath, batchSize, options });
|
|
188
|
-
|
|
205
|
+
const exitCode = await handleMultiFolderScan({ projectRoot: projectPath, batchSize, options, fetchImpl: certFetch });
|
|
206
|
+
auditLogHandle.close();
|
|
207
|
+
process.exit(exitCode);
|
|
189
208
|
}
|
|
190
209
|
let advisorySourceLine = "";
|
|
191
210
|
let advisoryDbFreshnessLine = null;
|
|
@@ -196,6 +215,7 @@ if (parsedArgs) {
|
|
|
196
215
|
offline: options.offline,
|
|
197
216
|
offlineDb: options.offlineDb,
|
|
198
217
|
debugLog,
|
|
218
|
+
fetchImpl: certFetch,
|
|
199
219
|
});
|
|
200
220
|
advisorySourceLine = advisorySource.sourceLabel;
|
|
201
221
|
debugLog("Advisory source", {
|
|
@@ -296,6 +316,7 @@ if (parsedArgs) {
|
|
|
296
316
|
options,
|
|
297
317
|
projectPath,
|
|
298
318
|
debugLog,
|
|
319
|
+
fetchImpl: certFetch,
|
|
299
320
|
});
|
|
300
321
|
const findingsBeforeFixList = scanState.sorted;
|
|
301
322
|
const findingsBeforeFix = findingsBeforeFixList.length;
|
|
@@ -322,6 +343,7 @@ if (parsedArgs) {
|
|
|
322
343
|
const auditResult = await audit(overrideCtx, { checkNetwork: !!options.checkNetwork });
|
|
323
344
|
overrideFindings = auditResult.findings;
|
|
324
345
|
}
|
|
346
|
+
let maintenanceFindings = [];
|
|
325
347
|
// Emit cve.detected for each CVE finding
|
|
326
348
|
for (const f of scanState.sorted) {
|
|
327
349
|
auditLogHandle.emit({
|
|
@@ -367,6 +389,7 @@ if (parsedArgs) {
|
|
|
367
389
|
options,
|
|
368
390
|
projectPath,
|
|
369
391
|
debugLog,
|
|
392
|
+
fetchImpl: certFetch,
|
|
370
393
|
});
|
|
371
394
|
}
|
|
372
395
|
}
|
|
@@ -548,6 +571,17 @@ if (parsedArgs) {
|
|
|
548
571
|
scanState.tableFindings = scanState.tableFindings.filter(f => filtered.newFindings.some(nf => nf.pkg.name === f.pkg.name && nf.pkg.version === f.pkg.version));
|
|
549
572
|
suppressedCount = filtered.suppressedCount;
|
|
550
573
|
}
|
|
574
|
+
// Maintenance risk findings are derived from CVE findings (via
|
|
575
|
+
// recommendedParentUpgrade), so they must be computed from the same
|
|
576
|
+
// baseline-filtered set everything below uses (JSON, rendering,
|
|
577
|
+
// --fail-on). Computing this earlier - before the baseline filter above -
|
|
578
|
+
// let a DM001 finding on an already-baselined CVE keep failing
|
|
579
|
+
// --fail-on forever, even as printFinalStatus reported a clean scan.
|
|
580
|
+
// This point is unreached in --ratchet mode (which always exits above
|
|
581
|
+
// via process.exit), so packument fetches never run wastefully there.
|
|
582
|
+
if (options.checkMaintenance) {
|
|
583
|
+
maintenanceFindings = await detectDM001(scanState.sorted, !!options.offline || !!options.offlineDb);
|
|
584
|
+
}
|
|
551
585
|
await writeOutputs(options, {
|
|
552
586
|
sorted: scanState.sorted,
|
|
553
587
|
allPackages: scanState.allPackages,
|
|
@@ -556,6 +590,7 @@ if (parsedArgs) {
|
|
|
556
590
|
minSeverity: scanState.minSeverity,
|
|
557
591
|
tableFindings: scanState.tableFindings,
|
|
558
592
|
overrideFindings,
|
|
593
|
+
maintenanceFindings,
|
|
559
594
|
}, scanInput, projectPath);
|
|
560
595
|
if (!(options.json || options.sarif || options.cdx) || options.verbose) {
|
|
561
596
|
const offline = !!options.offline || !!options.offlineDb;
|
|
@@ -582,7 +617,10 @@ if (parsedArgs) {
|
|
|
582
617
|
}
|
|
583
618
|
}
|
|
584
619
|
if (options.checkOverrides && overrideFindings.length > 0) {
|
|
585
|
-
console.log(renderOverrideFindings(overrideFindings, { verbose: true }));
|
|
620
|
+
console.log("\n" + renderOverrideFindings(overrideFindings, { verbose: true, projectPath }));
|
|
621
|
+
}
|
|
622
|
+
if (options.checkMaintenance && maintenanceFindings.length > 0) {
|
|
623
|
+
console.log("\n" + renderMaintenanceFindings(maintenanceFindings, { verbose: true }));
|
|
586
624
|
}
|
|
587
625
|
printCoverage([...scanInput.notes, ...scanState.coverage]);
|
|
588
626
|
printFinalStatus(scanState.sorted, overrideCount);
|
|
@@ -595,7 +633,10 @@ if (parsedArgs) {
|
|
|
595
633
|
: undefined;
|
|
596
634
|
printCompactOutput(scanState.sorted, scanInput, { offline, all: !!options.all, packageManager: compactPmLabel });
|
|
597
635
|
if (options.checkOverrides) {
|
|
598
|
-
console.log(renderOverrideFindings(overrideFindings, { verbose: false }));
|
|
636
|
+
console.log("\n" + renderOverrideFindings(overrideFindings, { verbose: false, projectPath }));
|
|
637
|
+
}
|
|
638
|
+
if (options.checkMaintenance && maintenanceFindings.length > 0) {
|
|
639
|
+
console.log("\n" + renderMaintenanceFindings(maintenanceFindings, { verbose: false }));
|
|
599
640
|
}
|
|
600
641
|
if (showOverrideHint)
|
|
601
642
|
printOverrideHint();
|
|
@@ -614,9 +655,12 @@ if (parsedArgs) {
|
|
|
614
655
|
suggestedFixCommands: scanState.suggestedFixCommands,
|
|
615
656
|
notes: [...scanInput.notes, ...scanState.coverage],
|
|
616
657
|
warnings: scanInput.warnings,
|
|
658
|
+
skippedDependencies: scanInput.skippedDependencies,
|
|
617
659
|
// undefined (not []) when override checking was not requested, so the HTML
|
|
618
660
|
// report omits the Override hygiene panel entirely on a plain scan.
|
|
619
661
|
overrideFindings: options.checkOverrides ? overrideFindings : undefined,
|
|
662
|
+
// Same undefined-vs-[] convention as overrideFindings above.
|
|
663
|
+
maintenanceFindings: options.checkMaintenance ? maintenanceFindings : undefined,
|
|
620
664
|
});
|
|
621
665
|
const { reportPath } = await writeHtmlReport({
|
|
622
666
|
outputDir,
|
|
@@ -638,14 +682,15 @@ if (parsedArgs) {
|
|
|
638
682
|
console.log(chalk.yellow(`${scanState.sorted.length} new ${scanState.sorted.length === 1 ? "finding" : "findings"} above baseline - ${suppressedCount} existing ${suppressedCount === 1 ? "finding" : "findings"} suppressed`));
|
|
639
683
|
}
|
|
640
684
|
}
|
|
641
|
-
|
|
642
|
-
//
|
|
643
|
-
// `overrides` command
|
|
685
|
+
// Override hygiene findings count toward --fail-on too, using the shared
|
|
686
|
+
// reachesFailOn helper from src/utils/severity.ts, the same logic used by
|
|
687
|
+
// the standalone `overrides` command. Without this, a CI run
|
|
644
688
|
// of `cve-lite . --check-overrides --fail-on high` would exit 0 despite high-severity
|
|
645
689
|
// override findings, giving a false sense of protection. overrideFindings is empty
|
|
646
690
|
// unless --check-overrides (and non-ratchet), so this is a no-op otherwise.
|
|
647
|
-
const
|
|
648
|
-
|
|
691
|
+
const shouldFail = reachesFailOn(scanState.sorted, options.failOn) ||
|
|
692
|
+
reachesFailOn(overrideFindings, options.failOn) ||
|
|
693
|
+
reachesFailOn(maintenanceFindings, options.failOn);
|
|
649
694
|
// In fix mode, remaining transitive findings cannot be auto-fixed.
|
|
650
695
|
// Exiting non-zero would prevent the Action PR step from running.
|
|
651
696
|
const exitCode = shouldFail && !options.fix ? 1 : 0;
|
|
@@ -678,31 +723,8 @@ if (parsedArgs) {
|
|
|
678
723
|
stack: error instanceof Error ? error.stack : undefined,
|
|
679
724
|
});
|
|
680
725
|
auditLogHandle.close();
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
console.error(chalk.yellow(hint));
|
|
684
|
-
rest.forEach(line => console.error(chalk.gray(line)));
|
|
685
|
-
}
|
|
686
|
-
else if (isRateLimitError(errorMessage)) {
|
|
687
|
-
const [hint, ...rest] = rateLimitAdvisoryRequestHint();
|
|
688
|
-
console.error(chalk.yellow(hint));
|
|
689
|
-
rest.forEach(line => console.error(chalk.gray(line)));
|
|
690
|
-
}
|
|
691
|
-
else if (isServerError(errorMessage)) {
|
|
692
|
-
const [hint, ...rest] = serverAdvisoryRequestHint();
|
|
693
|
-
console.error(chalk.yellow(hint));
|
|
694
|
-
rest.forEach(line => console.error(chalk.gray(line)));
|
|
695
|
-
}
|
|
696
|
-
else if (isLikelyBlockedAdvisoryRequestError(errorMessage)) {
|
|
697
|
-
const [hint, ...rest] = blockedAdvisoryRequestHint();
|
|
698
|
-
console.error(chalk.yellow(hint));
|
|
699
|
-
rest.forEach(line => console.error(chalk.gray(line)));
|
|
700
|
-
}
|
|
701
|
-
else {
|
|
702
|
-
const [hint, ...rest] = fetchErrorCaCertHint();
|
|
703
|
-
console.error(chalk.yellow(hint));
|
|
704
|
-
rest.forEach(line => console.error(chalk.gray(line)));
|
|
705
|
-
}
|
|
726
|
+
formatHintLines(getNetworkErrorHint(error, errorMessage))
|
|
727
|
+
.forEach(line => console.error(line));
|
|
706
728
|
process.exit(1);
|
|
707
729
|
});
|
|
708
730
|
}
|
|
@@ -713,7 +735,7 @@ async function scanProject(params) {
|
|
|
713
735
|
directDependencyNames,
|
|
714
736
|
scanSource: params.scanInput.source,
|
|
715
737
|
scanFilePath: params.scanInput.filePath,
|
|
716
|
-
}, params.debugLog);
|
|
738
|
+
}, params.debugLog, params.fetchImpl);
|
|
717
739
|
if (params.options.usage) {
|
|
718
740
|
logInfo(`Scanning project source for usage hints...`, params.options);
|
|
719
741
|
const usageStartedAt = Date.now();
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { fetchPackument } from "../remediation/npm-registry.js";
|
|
2
|
+
const SEVERITY_ORDER_MAP = { high: 0 };
|
|
3
|
+
function majorOf(version) {
|
|
4
|
+
return parseInt(version.split(".")[0] ?? "0", 10);
|
|
5
|
+
}
|
|
6
|
+
export async function detectDM001(findings, isOffline) {
|
|
7
|
+
// Step 1: Collect drag candidates (transitive findings requiring a major-version parent bump)
|
|
8
|
+
const candidates = new Map();
|
|
9
|
+
for (const finding of findings) {
|
|
10
|
+
if (finding.relationship !== "transitive" || finding.recommendedParentUpgrade == null)
|
|
11
|
+
continue;
|
|
12
|
+
const { package: parentName, currentVersion, targetVersion } = finding.recommendedParentUpgrade;
|
|
13
|
+
if (majorOf(targetVersion) === majorOf(currentVersion))
|
|
14
|
+
continue;
|
|
15
|
+
if (!candidates.has(parentName)) {
|
|
16
|
+
candidates.set(parentName, { parentVersion: currentVersion, dragSignals: [] });
|
|
17
|
+
}
|
|
18
|
+
candidates.get(parentName).dragSignals.push({
|
|
19
|
+
constrainedPackage: finding.pkg.name,
|
|
20
|
+
installedVersion: finding.pkg.version,
|
|
21
|
+
fixVersion: finding.firstFixedVersion ?? finding.recommendedParentUpgrade.targetVersion,
|
|
22
|
+
parentTargetVersion: finding.recommendedParentUpgrade.targetVersion,
|
|
23
|
+
cveId: finding.cveAliases[0] ?? finding.vulnerabilities[0]?.id ?? "",
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (candidates.size === 0)
|
|
27
|
+
return [];
|
|
28
|
+
// Step 2: Check deprecated status for each candidate (skip when offline)
|
|
29
|
+
const results = [];
|
|
30
|
+
for (const [parentName, candidate] of candidates) {
|
|
31
|
+
let deprecated;
|
|
32
|
+
if (!isOffline) {
|
|
33
|
+
try {
|
|
34
|
+
const packument = await fetchPackument(parentName);
|
|
35
|
+
if (packument) {
|
|
36
|
+
const latestVersion = packument["dist-tags"]?.latest ?? "";
|
|
37
|
+
const deprecatedMsg = latestVersion
|
|
38
|
+
? (packument.versions?.[latestVersion]?.deprecated ?? "")
|
|
39
|
+
: "";
|
|
40
|
+
if (deprecatedMsg)
|
|
41
|
+
deprecated = { message: deprecatedMsg };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Network error - emit drag finding without deprecated signal
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const pkgList = candidate.dragSignals.map(d => d.constrainedPackage).join(", ");
|
|
49
|
+
const message = `Constrains ${pkgList} - blocks CVE fix requiring major upgrade`;
|
|
50
|
+
results.push({
|
|
51
|
+
ruleId: "DM001",
|
|
52
|
+
severity: "high",
|
|
53
|
+
package: { name: parentName, version: candidate.parentVersion },
|
|
54
|
+
drag: candidate.dragSignals,
|
|
55
|
+
deprecated,
|
|
56
|
+
message,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return results.sort((a, b) => {
|
|
60
|
+
const sDiff = (SEVERITY_ORDER_MAP[a.severity] ?? 4) - (SEVERITY_ORDER_MAP[b.severity] ?? 4);
|
|
61
|
+
return sDiff !== 0 ? sDiff : a.package.name.localeCompare(b.package.name);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|