cve-lite-cli 1.27.0 → 1.29.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 +45 -3
- package/dist/advisory/osv-advisory-source.js +5 -3
- package/dist/cli/advisories-init.js +24 -0
- package/dist/cli/args.js +30 -0
- package/dist/cli/help.js +6 -2
- package/dist/cli/validate.js +6 -0
- package/dist/constants.js +1 -0
- package/dist/index.js +67 -7
- package/dist/maintenance/dm001-maintenance-risk.js +122 -0
- package/dist/maintenance/score.js +51 -0
- package/dist/maintenance/types.js +1 -0
- package/dist/osv/cache.js +49 -50
- package/dist/output/formatters.js +10 -4
- package/dist/output/html-reporter.js +163 -14
- package/dist/output/maintenance-findings-html.js +60 -0
- package/dist/output/maintenance-findings-json.js +3 -0
- package/dist/output/maintenance-findings-sarif.js +58 -0
- package/dist/output/maintenance-terminal.js +138 -0
- package/dist/output/multi-folder-html-reporter.js +61 -5
- package/dist/output/multi-folder-printer.js +11 -2
- package/dist/output/override-findings-html.js +22 -32
- package/dist/output/printers.js +95 -22
- package/dist/output/sarif.js +23 -7
- package/dist/output/spinner.js +5 -0
- package/dist/output/write-outputs.js +7 -2
- package/dist/parsers/bun-lock.js +47 -7
- package/dist/parsers/npm-lock-graph.js +90 -12
- package/dist/parsers/pnpm-lock.js +42 -6
- package/dist/parsers/utils.js +0 -15
- package/dist/parsers/yarn-lock.js +140 -58
- package/dist/remediation/cooldown.js +74 -0
- package/dist/remediation/fix-commands.js +42 -2
- package/dist/remediation/npm-registry.js +70 -42
- package/dist/remediation/parent-upgrade.js +114 -18
- package/dist/scan/completeness.js +49 -0
- package/dist/scan/multi-folder-scan.js +193 -13
- package/dist/scanner.js +284 -165
- package/dist/usage/scanner.js +12 -2
- package/dist/utils/network.js +66 -0
- package/dist/utils/vuln.js +16 -0
- package/package.json +2 -2
|
@@ -1,26 +1,98 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { parse as parseYarnLock } from "yarn-lockfile";
|
|
4
|
-
import { uniquePathArrays } from "../utils/array.js";
|
|
5
4
|
import { normalizeRawVersion } from "../utils/version.js";
|
|
6
|
-
import { upsertPackage
|
|
5
|
+
import { upsertPackage } from "./utils.js";
|
|
7
6
|
const MAX_PATHS_PER_PACKAGE = 5;
|
|
8
7
|
const MAX_PATH_DEPTH = 10;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
// Record a display path for a package, matching the existing de-dup + cap behavior (keep the
|
|
9
|
+
// first MAX_PATHS_PER_PACKAGE unique paths, in insertion order).
|
|
10
|
+
function addTaggedPath(taggedPathsByKey, key, path) {
|
|
11
|
+
const list = taggedPathsByKey.get(key) ?? [];
|
|
12
|
+
taggedPathsByKey.set(key, list);
|
|
13
|
+
const serialized = path.join(">");
|
|
14
|
+
if (list.some(entry => entry.path.join(">") === serialized))
|
|
15
|
+
return;
|
|
16
|
+
if (list.length >= MAX_PATHS_PER_PACKAGE)
|
|
17
|
+
return;
|
|
18
|
+
list.push({ path });
|
|
19
|
+
}
|
|
20
|
+
// Write the collected display paths onto each package. Dev/prod is set separately.
|
|
21
|
+
function applyTaggedPaths(map, taggedPathsByKey) {
|
|
22
|
+
for (const [key, tagged] of taggedPathsByKey) {
|
|
23
|
+
const pkg = map.get(key);
|
|
24
|
+
if (!pkg)
|
|
25
|
+
continue;
|
|
26
|
+
pkg.paths = tagged.map(entry => entry.path);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Classify dev vs prod by production reachability, mirroring the pnpm and Bun loaders: a
|
|
30
|
+
// package that has recorded paths is dev only when it is not reachable from any production
|
|
31
|
+
// root (a root or workspace dependency/optionalDependency). Reachability is computed over the
|
|
32
|
+
// full graph, so it is independent of the per-package display-path cap - a production path
|
|
33
|
+
// beyond the cap still keeps the package production. Unresolved fallback production deps are
|
|
34
|
+
// seeded directly, since they are not graph nodes.
|
|
35
|
+
function markYarnDevByProdReachability(map, graph, prodRootKeys, prodFallbackKeys) {
|
|
36
|
+
const prodReachable = new Set(prodFallbackKeys);
|
|
37
|
+
const visited = new Set();
|
|
38
|
+
const stack = [...prodRootKeys];
|
|
39
|
+
while (stack.length > 0) {
|
|
40
|
+
const key = stack.pop();
|
|
41
|
+
if (visited.has(key))
|
|
42
|
+
continue;
|
|
43
|
+
visited.add(key);
|
|
44
|
+
prodReachable.add(key);
|
|
45
|
+
for (const child of graph.get(key) ?? []) {
|
|
46
|
+
if (!visited.has(child))
|
|
47
|
+
stack.push(child);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const [key, pkg] of map) {
|
|
51
|
+
if ((pkg.paths?.length ?? 0) === 0)
|
|
52
|
+
continue;
|
|
53
|
+
if (!prodReachable.has(key))
|
|
54
|
+
pkg.dev = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function readRootPackageJson(filePath) {
|
|
13
58
|
try {
|
|
14
|
-
|
|
59
|
+
return JSON.parse(fs.readFileSync(path.join(path.dirname(filePath), "package.json"), "utf8"));
|
|
15
60
|
}
|
|
16
61
|
catch {
|
|
17
|
-
return
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function buildYarnWorkspaceMap(filePath) {
|
|
66
|
+
const map = new Map();
|
|
67
|
+
for (const { name: wsName, pkg: wsPkg } of readWorkspacePackages(filePath)) {
|
|
68
|
+
for (const depSection of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
69
|
+
const deps = wsPkg[depSection];
|
|
70
|
+
if (!deps || typeof deps !== "object")
|
|
71
|
+
continue;
|
|
72
|
+
for (const depName of Object.keys(deps)) {
|
|
73
|
+
const existing = map.get(depName) ?? [];
|
|
74
|
+
if (!existing.includes(wsName))
|
|
75
|
+
map.set(depName, [...existing, wsName]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
18
78
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
79
|
+
return map;
|
|
80
|
+
}
|
|
81
|
+
// Enumerate a project's Yarn workspace packages (name + parsed package.json) by
|
|
82
|
+
// resolving the root package.json's `workspaces` globs. Shared by the workspace-map
|
|
83
|
+
// builder and by dependency-path seeding, so a transitive pulled in only by a
|
|
84
|
+
// workspace package can be attributed back to that workspace instead of orphaning.
|
|
85
|
+
function readWorkspacePackages(filePath, rootPkg) {
|
|
86
|
+
const dir = path.dirname(filePath);
|
|
87
|
+
const root = rootPkg ?? readRootPackageJson(filePath);
|
|
88
|
+
if (!root)
|
|
89
|
+
return [];
|
|
90
|
+
const patterns = Array.isArray(root.workspaces)
|
|
91
|
+
? root.workspaces
|
|
92
|
+
: root.workspaces?.packages ?? [];
|
|
22
93
|
if (!patterns.length)
|
|
23
|
-
return
|
|
94
|
+
return [];
|
|
95
|
+
const result = [];
|
|
24
96
|
for (const pattern of patterns) {
|
|
25
97
|
const parts = pattern.split("/");
|
|
26
98
|
const lastPart = parts[parts.length - 1];
|
|
@@ -48,22 +120,12 @@ export function buildYarnWorkspaceMap(filePath) {
|
|
|
48
120
|
catch {
|
|
49
121
|
continue;
|
|
50
122
|
}
|
|
51
|
-
|
|
52
|
-
if (!wsName)
|
|
123
|
+
if (!wsPkg.name)
|
|
53
124
|
continue;
|
|
54
|
-
|
|
55
|
-
const deps = wsPkg[depSection];
|
|
56
|
-
if (!deps || typeof deps !== "object")
|
|
57
|
-
continue;
|
|
58
|
-
for (const depName of Object.keys(deps)) {
|
|
59
|
-
const existing = map.get(depName) ?? [];
|
|
60
|
-
if (!existing.includes(wsName))
|
|
61
|
-
map.set(depName, [...existing, wsName]);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
125
|
+
result.push({ name: wsPkg.name, pkg: wsPkg });
|
|
64
126
|
}
|
|
65
127
|
}
|
|
66
|
-
return
|
|
128
|
+
return result;
|
|
67
129
|
}
|
|
68
130
|
function isYarnBerry(content) {
|
|
69
131
|
return content.startsWith('__metadata:') || content.includes('\n__metadata:');
|
|
@@ -83,8 +145,8 @@ function parseYarnPackageKey(key) {
|
|
|
83
145
|
return null;
|
|
84
146
|
return { key, name, version };
|
|
85
147
|
}
|
|
86
|
-
function collectYarnPaths(
|
|
87
|
-
const queue =
|
|
148
|
+
function collectYarnPaths(seeds, graph, map, taggedPathsByKey) {
|
|
149
|
+
const queue = seeds.map(seed => ({ key: seed.key, path: seed.path }));
|
|
88
150
|
const visitedStates = new Set();
|
|
89
151
|
let head = 0;
|
|
90
152
|
while (head < queue.length) {
|
|
@@ -97,13 +159,13 @@ function collectYarnPaths(rootDepKeys, graph, map) {
|
|
|
97
159
|
if (visitedStates.has(stateKey))
|
|
98
160
|
continue;
|
|
99
161
|
visitedStates.add(stateKey);
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
}
|
|
162
|
+
// Only record paths for packages that exist in the lockfile map, matching prior behavior.
|
|
163
|
+
if (map.has(ref.key))
|
|
164
|
+
addTaggedPath(taggedPathsByKey, ref.key, nextPath);
|
|
104
165
|
if (nextPath.length >= MAX_PATH_DEPTH)
|
|
105
166
|
continue;
|
|
106
|
-
|
|
167
|
+
const recorded = taggedPathsByKey.get(ref.key) ?? [];
|
|
168
|
+
if (recorded.length >= MAX_PATHS_PER_PACKAGE && !recorded.some(entry => pathsEqual(entry.path, nextPath))) {
|
|
107
169
|
continue;
|
|
108
170
|
}
|
|
109
171
|
for (const child of graph.get(ref.key) ?? []) {
|
|
@@ -111,40 +173,54 @@ function collectYarnPaths(rootDepKeys, graph, map) {
|
|
|
111
173
|
}
|
|
112
174
|
}
|
|
113
175
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
catch {
|
|
121
|
-
return { keys: [], devDepNames: new Set() };
|
|
122
|
-
}
|
|
123
|
-
const devDepNames = new Set(Object.keys(rootPkg.devDependencies ?? {}));
|
|
124
|
-
const rootDepKeys = [];
|
|
176
|
+
// Resolve one package.json's dependency declarations into BFS seeds. The pathPrefix is
|
|
177
|
+
// the parent chain the seed hangs off: ["project"] for the root, ["project", <workspace>]
|
|
178
|
+
// for a workspace package. Unresolved direct deps (present in package.json but not the
|
|
179
|
+
// lockfile) fall back to a shallow path so they are still attributed.
|
|
180
|
+
function resolveDepSeeds(pkgJson, pathPrefix, selectorToKey, map, taggedPathsByKey, prodFallbackKeys) {
|
|
181
|
+
const seeds = [];
|
|
125
182
|
for (const depSection of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
126
|
-
const deps =
|
|
183
|
+
const deps = pkgJson?.[depSection];
|
|
127
184
|
if (!deps || typeof deps !== "object")
|
|
128
185
|
continue;
|
|
186
|
+
const dev = depSection === "devDependencies";
|
|
129
187
|
for (const [depName, depRange] of Object.entries(deps)) {
|
|
130
188
|
const resolved = selectorToKey.get(`${depName}@${depRange}`) ??
|
|
131
189
|
selectorToKey.get(`${depName}@npm:${depRange}`);
|
|
132
190
|
if (resolved) {
|
|
133
|
-
|
|
191
|
+
seeds.push({ key: resolved, path: pathPrefix, dev });
|
|
134
192
|
continue;
|
|
135
193
|
}
|
|
136
194
|
const fallbackVersion = normalizeRawVersion(depRange);
|
|
137
195
|
if (fallbackVersion) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
196
|
+
const name = String(depName);
|
|
197
|
+
const key = `${name}@${fallbackVersion}`;
|
|
198
|
+
upsertPackage(map, { name, version: fallbackVersion, ecosystem: "npm", paths: [] });
|
|
199
|
+
addTaggedPath(taggedPathsByKey, key, [...pathPrefix, name]);
|
|
200
|
+
// Unresolved fallback prod deps are not graph nodes, so record their key as
|
|
201
|
+
// production-reachable directly (mirrors the resolved production roots).
|
|
202
|
+
if (!dev)
|
|
203
|
+
prodFallbackKeys.add(key);
|
|
144
204
|
}
|
|
145
205
|
}
|
|
146
206
|
}
|
|
147
|
-
return
|
|
207
|
+
return seeds;
|
|
208
|
+
}
|
|
209
|
+
// Build the BFS seeds for a project. Seeds come from the root package.json (parent chain
|
|
210
|
+
// ["project"]) and from every workspace package (parent chain ["project", <workspace>]),
|
|
211
|
+
// so transitives reachable only through a workspace resolve back to that workspace instead
|
|
212
|
+
// of reporting "No parent identified". Each seed carries whether its declaring edge is a
|
|
213
|
+
// devDependency (used to pick the production roots for reachability-based classification);
|
|
214
|
+
// prodFallbackKeys collects unresolved production direct deps that are not graph nodes.
|
|
215
|
+
function loadSeeds(filePath, selectorToKey, map, taggedPathsByKey, prodFallbackKeys) {
|
|
216
|
+
const rootPkg = readRootPackageJson(filePath);
|
|
217
|
+
if (!rootPkg)
|
|
218
|
+
return [];
|
|
219
|
+
const seeds = resolveDepSeeds(rootPkg, ["project"], selectorToKey, map, taggedPathsByKey, prodFallbackKeys);
|
|
220
|
+
for (const { name: wsName, pkg: wsPkg } of readWorkspacePackages(filePath, rootPkg)) {
|
|
221
|
+
seeds.push(...resolveDepSeeds(wsPkg, ["project", wsName], selectorToKey, map, taggedPathsByKey, prodFallbackKeys));
|
|
222
|
+
}
|
|
223
|
+
return seeds;
|
|
148
224
|
}
|
|
149
225
|
function parseBerryDependencies(block) {
|
|
150
226
|
const dependencies = {};
|
|
@@ -214,9 +290,12 @@ function loadFromYarnBerryLock(content, filePath) {
|
|
|
214
290
|
}
|
|
215
291
|
graph.set(canonicalKey, [...depKeys]);
|
|
216
292
|
}
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
293
|
+
const taggedPathsByKey = new Map();
|
|
294
|
+
const prodFallbackKeys = new Set();
|
|
295
|
+
const seeds = loadSeeds(filePath, selectorToKey, map, taggedPathsByKey, prodFallbackKeys);
|
|
296
|
+
collectYarnPaths(seeds, graph, map, taggedPathsByKey);
|
|
297
|
+
applyTaggedPaths(map, taggedPathsByKey);
|
|
298
|
+
markYarnDevByProdReachability(map, graph, seeds.filter(seed => !seed.dev).map(seed => seed.key), prodFallbackKeys);
|
|
220
299
|
return [...map.values()];
|
|
221
300
|
}
|
|
222
301
|
function loadFromYarnClassicLock(parsed, filePath) {
|
|
@@ -261,9 +340,12 @@ function loadFromYarnClassicLock(parsed, filePath) {
|
|
|
261
340
|
}
|
|
262
341
|
graph.set(canonicalKey, [...depKeys]);
|
|
263
342
|
}
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
343
|
+
const taggedPathsByKey = new Map();
|
|
344
|
+
const prodFallbackKeys = new Set();
|
|
345
|
+
const seeds = loadSeeds(filePath, selectorToKey, map, taggedPathsByKey, prodFallbackKeys);
|
|
346
|
+
collectYarnPaths(seeds, graph, map, taggedPathsByKey);
|
|
347
|
+
applyTaggedPaths(map, taggedPathsByKey);
|
|
348
|
+
markYarnDevByProdReachability(map, graph, seeds.filter(seed => !seed.dev).map(seed => seed.key), prodFallbackKeys);
|
|
267
349
|
return [...map.values()];
|
|
268
350
|
}
|
|
269
351
|
export function loadFromYarnLock(filePath) {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parse as parseYaml } from "yaml";
|
|
4
|
+
// Design basis - verified against current PM docs. npm: days; pnpm/yarn: minutes.
|
|
5
|
+
const PM_CONFIG = {
|
|
6
|
+
npm: { file: ".npmrc", key: "min-release-age", unitMs: 86_400_000, unitLabel: "day", format: "ini" },
|
|
7
|
+
pnpm: { file: "pnpm-workspace.yaml", key: "minimumReleaseAge", unitMs: 60_000, unitLabel: "min", format: "yaml" },
|
|
8
|
+
yarn: { file: ".yarnrc.yml", key: "npmMinimalAgeGate", unitMs: 60_000, unitLabel: "min", format: "yaml" },
|
|
9
|
+
};
|
|
10
|
+
function readIniValue(contents, key) {
|
|
11
|
+
for (const rawLine of contents.split(/\r?\n/)) {
|
|
12
|
+
const line = rawLine.trim();
|
|
13
|
+
if (!line || line.startsWith("#") || line.startsWith(";"))
|
|
14
|
+
continue;
|
|
15
|
+
const eq = line.indexOf("=");
|
|
16
|
+
if (eq === -1)
|
|
17
|
+
continue;
|
|
18
|
+
if (line.slice(0, eq).trim() === key)
|
|
19
|
+
return line.slice(eq + 1).trim();
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
function readYamlValue(contents, key) {
|
|
24
|
+
try {
|
|
25
|
+
const doc = parseYaml(contents);
|
|
26
|
+
if (doc && typeof doc === "object" && key in doc) {
|
|
27
|
+
return doc[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// fall through to null
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reads the project-level release cooldown configured for the detected package
|
|
37
|
+
* manager and normalizes it to milliseconds. Returns null when no usable
|
|
38
|
+
* cooldown is configured (absent file/key, value 0, or malformed). Never throws.
|
|
39
|
+
* CVE Lite never invents a cooldown - this only surfaces what the team set.
|
|
40
|
+
*/
|
|
41
|
+
export function readConfiguredCooldown(projectPath, pm) {
|
|
42
|
+
const cfg = PM_CONFIG[pm];
|
|
43
|
+
const filePath = path.join(projectPath, cfg.file);
|
|
44
|
+
let contents;
|
|
45
|
+
try {
|
|
46
|
+
contents = fs.readFileSync(filePath, "utf-8");
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const raw = cfg.format === "ini" ? readIniValue(contents, cfg.key) : readYamlValue(contents, cfg.key);
|
|
52
|
+
const value = typeof raw === "number" ? raw : typeof raw === "string" ? Number(raw) : NaN;
|
|
53
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
54
|
+
return null;
|
|
55
|
+
return {
|
|
56
|
+
windowMs: value * cfg.unitMs,
|
|
57
|
+
windowLabel: `${value} ${cfg.unitLabel}`,
|
|
58
|
+
sourceFile: cfg.file,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns a cooldown warning when a recommended fix version was published within
|
|
63
|
+
* the configured window, else null. Pure comparison - all inputs injected.
|
|
64
|
+
*/
|
|
65
|
+
export function cooldownWarningFor(publishedAtIso, cooldown, nowMs) {
|
|
66
|
+
if (!cooldown || !publishedAtIso)
|
|
67
|
+
return null;
|
|
68
|
+
const publishedMs = Date.parse(publishedAtIso);
|
|
69
|
+
if (!Number.isFinite(publishedMs))
|
|
70
|
+
return null;
|
|
71
|
+
if (nowMs - publishedMs >= cooldown.windowMs)
|
|
72
|
+
return null;
|
|
73
|
+
return { publishedAt: publishedAtIso, windowLabel: cooldown.windowLabel, sourceFile: cooldown.sourceFile };
|
|
74
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { severityOrder } from "../constants.js";
|
|
2
3
|
import { compareVersions, looksLikeVersion } from "../utils/version.js";
|
|
3
4
|
import { getPrimaryParent } from "../utils/finding.js";
|
|
@@ -7,6 +8,12 @@ import { buildNpmWorkspaceMap } from "../parsers/package-lock.js";
|
|
|
7
8
|
import { buildPnpmWorkspaceMap } from "../parsers/pnpm-lock.js";
|
|
8
9
|
import { buildYarnWorkspaceMap } from "../parsers/yarn-lock.js";
|
|
9
10
|
import { buildBunWorkspaceMap } from "../parsers/bun-lock.js";
|
|
11
|
+
import { readConfiguredCooldown, cooldownWarningFor } from "./cooldown.js";
|
|
12
|
+
import { isVerifiedUpgrade } from "./parent-upgrade.js";
|
|
13
|
+
// Rendered next to a parent-upgrade fix target whose recommendedParentUpgrade
|
|
14
|
+
// could not be verified end-to-end (parent-upgrade.ts confidence: "unverified").
|
|
15
|
+
// Shared across terminal and HTML output so the wording stays in sync.
|
|
16
|
+
export const UNVERIFIED_PARENT_UPGRADE_NOTE = "⚠ unverified - rescan after upgrading to confirm this resolves the finding";
|
|
10
17
|
export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
11
18
|
const packageManager = inferPackageManager(scanInput);
|
|
12
19
|
if (!packageManager)
|
|
@@ -241,6 +248,7 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
241
248
|
chainProof: chainForParentUpgrade?.chain,
|
|
242
249
|
chainSafeVersion: chainForParentUpgrade?.safeVersion,
|
|
243
250
|
chainVulnerablePackage: chainForParentUpgrade ? finding.pkg.name : undefined,
|
|
251
|
+
confidence: finding.recommendedParentUpgrade.confidence,
|
|
244
252
|
});
|
|
245
253
|
continue;
|
|
246
254
|
}
|
|
@@ -336,6 +344,15 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
336
344
|
return kindDelta;
|
|
337
345
|
return a.package.localeCompare(b.package);
|
|
338
346
|
});
|
|
347
|
+
const nowMs = options?.nowMs ?? Date.now();
|
|
348
|
+
if (scanInput.filePath && (packageManager === "npm" || packageManager === "pnpm" || packageManager === "yarn")) {
|
|
349
|
+
const cooldown = readConfiguredCooldown(path.dirname(scanInput.filePath), packageManager);
|
|
350
|
+
if (cooldown) {
|
|
351
|
+
for (const target of targets) {
|
|
352
|
+
target.cooldownWarning = cooldownWarningFor(target.fixVersionPublishedAt, cooldown, nowMs);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
339
356
|
const skipped = [...skippedByKey.values()].sort((a, b) => a.package.localeCompare(b.package));
|
|
340
357
|
const sections = buildSections(targets, packageManager);
|
|
341
358
|
const command = targets.length > 0
|
|
@@ -351,7 +368,21 @@ export function buildSuggestedFixCommandPlan(findings, scanInput, options) {
|
|
|
351
368
|
coveredFindingCount: 0,
|
|
352
369
|
totalFindingCount: findings.length,
|
|
353
370
|
};
|
|
354
|
-
|
|
371
|
+
// A finding only counts as covered when it has a matching fix target AND that
|
|
372
|
+
// target isn't an unverified parent upgrade - an unverified recommendation may
|
|
373
|
+
// not actually resolve the finding, so it must not inflate the "fix all" claim.
|
|
374
|
+
plan.coveredFindingCount = findings.filter(f => {
|
|
375
|
+
const target = findFixTargetForFinding(plan, f);
|
|
376
|
+
if (!target)
|
|
377
|
+
return false;
|
|
378
|
+
// Coverage is a per-finding property, not a per-target one: two unrelated
|
|
379
|
+
// findings can merge into the same target (same package upgrade), so a
|
|
380
|
+
// finding's own recommendedParentUpgrade confidence - not the blended
|
|
381
|
+
// target confidence - decides whether it is genuinely covered.
|
|
382
|
+
if (f.recommendedParentUpgrade)
|
|
383
|
+
return isVerifiedUpgrade(f.recommendedParentUpgrade.confidence);
|
|
384
|
+
return true;
|
|
385
|
+
}).length;
|
|
355
386
|
if (options?.subfolder) {
|
|
356
387
|
const prefix = `cd ${options.subfolder} && `;
|
|
357
388
|
if (plan.command)
|
|
@@ -405,7 +436,7 @@ export function commandPrefix(packageManager) {
|
|
|
405
436
|
function devFlag(packageManager) {
|
|
406
437
|
return packageManager === "bun" ? "--dev" : "-D";
|
|
407
438
|
}
|
|
408
|
-
export function
|
|
439
|
+
export function findFixTargetForFinding(plan, finding) {
|
|
409
440
|
const target = plan.targets.find(item => {
|
|
410
441
|
if (finding.recommendedNpmTransitiveRemediation?.kind === "update-parent-within-range") {
|
|
411
442
|
return (item.kind === "parent-update" &&
|
|
@@ -429,6 +460,10 @@ export function findSuggestedCommandForFinding(plan, finding) {
|
|
|
429
460
|
const directTarget = finding.validatedFirstFixedVersion ?? finding.firstFixedVersion;
|
|
430
461
|
return item.package === finding.pkg.name && item.targetVersion === directTarget;
|
|
431
462
|
});
|
|
463
|
+
return target ?? null;
|
|
464
|
+
}
|
|
465
|
+
export function findSuggestedCommandForFinding(plan, finding) {
|
|
466
|
+
const target = findFixTargetForFinding(plan, finding);
|
|
432
467
|
if (!target)
|
|
433
468
|
return null;
|
|
434
469
|
if (target.command)
|
|
@@ -485,6 +520,11 @@ function upsertTarget(targetsByPackage, next) {
|
|
|
485
520
|
chainProof: existing.chainProof ?? next.chainProof,
|
|
486
521
|
chainSafeVersion: existing.chainSafeVersion ?? next.chainSafeVersion,
|
|
487
522
|
chainVulnerablePackage: existing.chainVulnerablePackage ?? next.chainVulnerablePackage,
|
|
523
|
+
// Conservative: if either contributing finding's recommendation is unverified,
|
|
524
|
+
// keep the merged target unverified rather than overstate coverage.
|
|
525
|
+
confidence: existing.confidence === "unverified" || next.confidence === "unverified"
|
|
526
|
+
? "unverified"
|
|
527
|
+
: existing.confidence ?? next.confidence,
|
|
488
528
|
};
|
|
489
529
|
if (looksLikeVersion(existing.targetVersion) && looksLikeVersion(next.targetVersion)) {
|
|
490
530
|
if (compareVersions(next.targetVersion, existing.targetVersion) > 0) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compareVersions, isPreReleaseVersion, looksLikeVersion } from "../utils/version.js";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
3
|
const packumentCache = new Map();
|
|
3
4
|
const DEFAULT_NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
4
5
|
let registryDebugLog;
|
|
@@ -11,64 +12,91 @@ function nextRegistryBatchId() {
|
|
|
11
12
|
registryBatchCounter += 1;
|
|
12
13
|
return `r-${String(registryBatchCounter).padStart(2, "0")}`;
|
|
13
14
|
}
|
|
15
|
+
const observerStorage = new AsyncLocalStorage();
|
|
16
|
+
export async function runWithObserver(observer, fn) {
|
|
17
|
+
return observerStorage.run(observer, fn);
|
|
18
|
+
}
|
|
14
19
|
export function clearPackumentCache() {
|
|
15
20
|
packumentCache.clear();
|
|
16
21
|
}
|
|
22
|
+
function notifyPackumentObserver(result, packageName) {
|
|
23
|
+
const observer = observerStorage.getStore();
|
|
24
|
+
if (result.status === "transient-failure") {
|
|
25
|
+
observer?.onTransientFailure?.(packageName);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
observer?.onResolved?.(packageName);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
17
31
|
export async function fetchPackument(packageName) {
|
|
18
32
|
const cached = packumentCache.get(packageName);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
33
|
+
let result;
|
|
34
|
+
if (cached) {
|
|
35
|
+
result = await cached;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const promise = doFetchPackument(packageName);
|
|
39
|
+
packumentCache.set(packageName, promise);
|
|
40
|
+
result = await promise;
|
|
41
|
+
if (result.status === "transient-failure") {
|
|
42
|
+
// A later call retries the fetch instead of reusing a cached failure.
|
|
43
|
+
packumentCache.delete(packageName);
|
|
29
44
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
}
|
|
46
|
+
notifyPackumentObserver(result, packageName);
|
|
47
|
+
return result.packument;
|
|
48
|
+
}
|
|
49
|
+
async function doFetchPackument(packageName) {
|
|
50
|
+
const url = `${DEFAULT_NPM_REGISTRY_URL}/${encodeURIComponent(packageName)
|
|
51
|
+
.replace(/%40/g, "@")
|
|
52
|
+
.replace(/%2F/g, "/")}`;
|
|
53
|
+
const batchId = registryDebugLog ? nextRegistryBatchId() : "";
|
|
54
|
+
const startedAt = registryDebugLog ? Date.now() : 0;
|
|
55
|
+
if (registryDebugLog) {
|
|
56
|
+
registryDebugLog("Registry fetch", { batchId, package: packageName, url });
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const response = await fetch(url);
|
|
60
|
+
if (!response.ok) {
|
|
45
61
|
if (registryDebugLog) {
|
|
46
62
|
registryDebugLog("Registry response", {
|
|
47
63
|
batchId,
|
|
48
64
|
package: packageName,
|
|
49
65
|
status: response.status,
|
|
50
66
|
durationMs: Date.now() - startedAt,
|
|
51
|
-
versionsCount:
|
|
67
|
+
versionsCount: 0,
|
|
52
68
|
});
|
|
53
69
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
catch (error) {
|
|
57
|
-
if (registryDebugLog) {
|
|
58
|
-
registryDebugLog("Registry fetch failed", {
|
|
59
|
-
batchId,
|
|
60
|
-
package: packageName,
|
|
61
|
-
durationMs: Date.now() - startedAt,
|
|
62
|
-
error: error instanceof Error
|
|
63
|
-
? { message: error.message, stack: error.stack }
|
|
64
|
-
: String(error),
|
|
65
|
-
});
|
|
70
|
+
if (response.status === 404) {
|
|
71
|
+
return { status: "not-found", packument: null };
|
|
66
72
|
}
|
|
67
|
-
return null;
|
|
73
|
+
return { status: "transient-failure", packument: null };
|
|
68
74
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
const json = (await response.json());
|
|
76
|
+
if (registryDebugLog) {
|
|
77
|
+
registryDebugLog("Registry response", {
|
|
78
|
+
batchId,
|
|
79
|
+
package: packageName,
|
|
80
|
+
status: response.status,
|
|
81
|
+
durationMs: Date.now() - startedAt,
|
|
82
|
+
versionsCount: Object.keys(json.versions ?? {}).length,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return { status: "resolved", packument: json };
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (registryDebugLog) {
|
|
89
|
+
registryDebugLog("Registry fetch failed", {
|
|
90
|
+
batchId,
|
|
91
|
+
package: packageName,
|
|
92
|
+
durationMs: Date.now() - startedAt,
|
|
93
|
+
error: error instanceof Error
|
|
94
|
+
? { message: error.message, stack: error.stack }
|
|
95
|
+
: String(error),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return { status: "transient-failure", packument: null };
|
|
99
|
+
}
|
|
72
100
|
}
|
|
73
101
|
export async function packageVersionExists(packageName, version) {
|
|
74
102
|
const packument = await fetchPackument(packageName);
|