cve-lite-cli 1.41.4 → 1.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -19
- package/dist/advisory/detail-resolution.js +62 -0
- package/dist/advisory/local-db.js +90 -15
- package/dist/advisory/osv-advisory-source.js +113 -62
- package/dist/advisory/osv-sync.js +18 -16
- package/dist/advisory/sqlite.js +50 -0
- package/dist/audit-log/ndjson-writer.js +6 -3
- package/dist/audit-log/open-error.js +22 -0
- package/dist/cli/args.js +145 -87
- package/dist/cli/flags.js +2 -0
- package/dist/cli/help.js +6 -2
- package/dist/cli/overrides.js +5 -2
- package/dist/cli/validate.js +45 -5
- package/dist/constants.js +10 -0
- package/dist/index.js +15 -6
- package/dist/licenses/license-check.js +17 -4
- package/dist/osv/cache.js +7 -13
- package/dist/output/cyclonedx.js +57 -18
- package/dist/output/finding-display.js +8 -1
- package/dist/output/formatters.js +52 -11
- package/dist/output/html-reporter.js +40 -8
- package/dist/output/override-findings-terminal.js +21 -13
- package/dist/output/printers.js +185 -76
- package/dist/output/sarif.js +182 -16
- package/dist/output/spdx.js +15 -1
- package/dist/output/write-outputs.js +29 -20
- package/dist/overrides/context-builder.js +1 -7
- package/dist/overrides/detectors/oa005-nested-ineffective.js +6 -1
- package/dist/overrides/detectors/oa008-materialized.js +33 -10
- package/dist/overrides/detectors/oa009-stale-floor.js +2 -2
- package/dist/overrides/detectors/oa010-vulnerable-floor.js +19 -13
- package/dist/overrides/detectors/phantom-utils.js +2 -10
- package/dist/overrides/fixer.js +13 -2
- package/dist/overrides/index.js +1 -0
- package/dist/overrides/types.js +15 -1
- package/dist/parsers/bun-lock.js +6 -0
- package/dist/parsers/index.js +177 -40
- package/dist/parsers/multi-package.js +4 -0
- package/dist/parsers/package-lock.js +6 -2
- package/dist/parsers/pnpm-lock.js +4 -7
- package/dist/parsers/requirements-txt.js +185 -0
- package/dist/parsers/utils.js +11 -6
- package/dist/parsers/yarn-lock.js +1 -5
- package/dist/remediation/fix-commands.js +60 -36
- package/dist/remediation/parent-update-child-note.js +3 -2
- package/dist/scan/completeness.js +57 -4
- package/dist/scan/multi-folder-scan.js +27 -13
- package/dist/scan/single-scan.js +118 -37
- package/dist/scanner.js +59 -36
- package/dist/types.js +1 -1
- package/dist/usage/scanner.js +345 -45
- package/dist/utils/array.js +5 -0
- package/dist/utils/baseline.js +8 -2
- package/dist/utils/chalk.js +1 -3
- package/dist/utils/create-pr.js +2 -2
- package/dist/utils/debug-bundle.js +37 -22
- package/dist/utils/debug-project.js +6 -5
- package/dist/utils/debug-redaction.js +1 -1
- package/dist/utils/effective-options.js +5 -1
- package/dist/utils/finding.js +4 -0
- package/dist/utils/fix-runner.js +110 -36
- package/dist/utils/import-type-queries.js +5 -1
- package/dist/utils/install-command.js +6 -0
- package/dist/utils/malicious.js +11 -0
- package/dist/utils/package-identity.js +12 -2
- package/dist/utils/path-coverage.js +1 -5
- package/dist/utils/sanitize.js +59 -0
- package/dist/utils/sbom-format.js +17 -8
- package/dist/utils/severity.js +61 -7
- package/dist/utils/url.js +175 -0
- package/dist/utils/version.js +44 -0
- package/dist/utils/vuln.js +11 -14
- package/package.json +2 -4
package/dist/overrides/fixer.js
CHANGED
|
@@ -107,8 +107,19 @@ function detectIndent(raw) {
|
|
|
107
107
|
}
|
|
108
108
|
function applyOp(doc, op) {
|
|
109
109
|
switch (op.op) {
|
|
110
|
-
case "remove":
|
|
111
|
-
|
|
110
|
+
case "remove": {
|
|
111
|
+
let next = mutate(doc, op.path, () => undefined);
|
|
112
|
+
// Drop nested override objects this removal left empty.
|
|
113
|
+
const parts = splitPointer(op.path);
|
|
114
|
+
const containerDepth = parts[0] === "pnpm" ? 2 : 1;
|
|
115
|
+
for (let depth = parts.length - 1; depth > containerDepth; depth--) {
|
|
116
|
+
const parent = jsonPointer(parts.slice(0, depth));
|
|
117
|
+
if (!isEmpty(read(next, parent)))
|
|
118
|
+
break;
|
|
119
|
+
next = mutate(next, parent, () => undefined);
|
|
120
|
+
}
|
|
121
|
+
return next;
|
|
122
|
+
}
|
|
112
123
|
case "replace":
|
|
113
124
|
return mutate(doc, op.path, () => op.value);
|
|
114
125
|
case "move": {
|
package/dist/overrides/index.js
CHANGED
package/dist/overrides/types.js
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
// Override-audit rule identifiers. Spec: docs/merge/2026-05-28-cve-lite-merge-design.md
|
|
2
|
-
export
|
|
2
|
+
export const OVERRIDE_RULE_IDS = [
|
|
3
|
+
"OA001",
|
|
4
|
+
"OA002",
|
|
5
|
+
"OA003",
|
|
6
|
+
"OA004",
|
|
7
|
+
"OA005",
|
|
8
|
+
"OA006",
|
|
9
|
+
"OA007",
|
|
10
|
+
"OA008",
|
|
11
|
+
"OA009",
|
|
12
|
+
"OA010",
|
|
13
|
+
"OA011",
|
|
14
|
+
"PD001",
|
|
15
|
+
"PD002",
|
|
16
|
+
];
|
package/dist/parsers/bun-lock.js
CHANGED
|
@@ -49,6 +49,7 @@ function buildBunSeeds(workspaces, keys) {
|
|
|
49
49
|
function collectBunPaths(seeds, graph, keyIndex, map) {
|
|
50
50
|
const queue = seeds.map(seed => ({ key: seed.key, path: seed.path }));
|
|
51
51
|
const visitedStates = new Set();
|
|
52
|
+
const expansions = new Map();
|
|
52
53
|
let head = 0;
|
|
53
54
|
while (head < queue.length) {
|
|
54
55
|
const current = queue[head++];
|
|
@@ -66,6 +67,11 @@ function collectBunPaths(seeds, graph, keyIndex, map) {
|
|
|
66
67
|
}
|
|
67
68
|
if (nextPath.length >= MAX_PATH_DEPTH)
|
|
68
69
|
continue;
|
|
70
|
+
// Per key, not per name@version: two nested copies of one version can have different children.
|
|
71
|
+
const expanded = expansions.get(current.key) ?? 0;
|
|
72
|
+
if (expanded >= MAX_PATHS_PER_PACKAGE)
|
|
73
|
+
continue;
|
|
74
|
+
expansions.set(current.key, expanded + 1);
|
|
69
75
|
for (const child of graph.get(current.key) ?? []) {
|
|
70
76
|
queue.push({ key: child, path: nextPath });
|
|
71
77
|
}
|
package/dist/parsers/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { LOCKFILE_NAMES, LOCKFILE_PRIORITY_ROOT } from "../constants.js";
|
|
3
|
+
import { LOCKFILE_NAMES, LOCKFILE_PRIORITY_ROOT, NPM_LOCKFILE_NAMES } from "../constants.js";
|
|
4
4
|
import { findFiles, findNearestPackageJson, chooseBestLockfile, safeReadText, relativeOrName } from "../utils/file.js";
|
|
5
5
|
import { loadFromBunLock } from "./bun-lock.js";
|
|
6
6
|
import { loadFromPackageJson } from "./package-json.js";
|
|
7
7
|
import { loadFromPackageLock } from "./package-lock.js";
|
|
8
8
|
import { loadFromPnpmLock } from "./pnpm-lock.js";
|
|
9
|
+
import { loadFromRequirementsTxt } from "./requirements-txt.js";
|
|
9
10
|
import { loadFromYarnLock } from "./yarn-lock.js";
|
|
10
11
|
const NESTED_LOCKFILE_NOTE = "No supported lockfile was found at the repo root, so a nested lockfile was used instead.";
|
|
11
12
|
const PATHS_FROM_LOCKFILE_LOCATIONS = "Dependency paths are derived from lockfile package locations.";
|
|
@@ -41,18 +42,18 @@ const LOCKFILE_HANDLERS = {
|
|
|
41
42
|
load: loadFromYarnLock,
|
|
42
43
|
pathNote: "Dependency paths are derived from yarn.lock package relationships.",
|
|
43
44
|
},
|
|
45
|
+
"requirements.txt": {
|
|
46
|
+
source: "requirements-txt",
|
|
47
|
+
load: loadFromRequirementsTxt,
|
|
48
|
+
pathNote: "Dependency paths are derived from requirements.txt pinned dependencies.",
|
|
49
|
+
},
|
|
44
50
|
};
|
|
45
|
-
/**
|
|
46
|
-
function toLockfileName(filePath) {
|
|
47
|
-
const name = path.basename(filePath);
|
|
48
|
-
return LOCKFILE_NAMES.find(candidate => candidate === name) ?? null;
|
|
49
|
-
}
|
|
50
|
-
/** The lockfile each package manager writes, for reading `packageManager`. */
|
|
51
|
+
/** Each package manager's lockfiles, in the order it prefers them. */
|
|
51
52
|
const PACKAGE_MANAGER_LOCKFILES = {
|
|
52
|
-
npm:
|
|
53
|
-
pnpm: "pnpm-lock.yaml",
|
|
54
|
-
yarn: "yarn.lock",
|
|
55
|
-
bun: "bun.lock",
|
|
53
|
+
npm: NPM_LOCKFILE_NAMES,
|
|
54
|
+
pnpm: ["pnpm-lock.yaml"],
|
|
55
|
+
yarn: ["yarn.lock"],
|
|
56
|
+
bun: ["bun.lock"],
|
|
56
57
|
};
|
|
57
58
|
/**
|
|
58
59
|
* The package manager a project declares for itself, from the `packageManager`
|
|
@@ -68,7 +69,7 @@ function readDeclaredPackageManager(projectRoot) {
|
|
|
68
69
|
if (typeof declared !== "string")
|
|
69
70
|
return null;
|
|
70
71
|
const name = declared.split("@")[0]?.trim().toLowerCase();
|
|
71
|
-
return name && name
|
|
72
|
+
return name && Object.hasOwn(PACKAGE_MANAGER_LOCKFILES, name) ? name : null;
|
|
72
73
|
}
|
|
73
74
|
catch {
|
|
74
75
|
// A manifest we cannot parse tells us nothing about the package manager.
|
|
@@ -90,29 +91,34 @@ function findRootLockfile(projectRoot) {
|
|
|
90
91
|
if (present.length === 0)
|
|
91
92
|
return null;
|
|
92
93
|
const declared = readDeclaredPackageManager(projectRoot);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const declaredLockfile = declared === "npm" && present.includes("npm-shrinkwrap.json")
|
|
98
|
-
? "npm-shrinkwrap.json"
|
|
99
|
-
: declared ? PACKAGE_MANAGER_LOCKFILES[declared] : undefined;
|
|
100
|
-
const chosen = declaredLockfile && present.includes(declaredLockfile) ? declaredLockfile : present[0];
|
|
94
|
+
const declaredLockfile = declared
|
|
95
|
+
? PACKAGE_MANAGER_LOCKFILES[declared]?.find(name => present.includes(name))
|
|
96
|
+
: undefined;
|
|
97
|
+
const chosen = declaredLockfile ?? present[0];
|
|
101
98
|
return {
|
|
102
99
|
filePath: path.join(projectRoot, chosen),
|
|
103
100
|
name: chosen,
|
|
104
101
|
skipped: present.filter(name => name !== chosen),
|
|
105
102
|
declaredBy: chosen === declaredLockfile ? declared : undefined,
|
|
103
|
+
declaredMissing: declared && !declaredLockfile ? declared : undefined,
|
|
106
104
|
};
|
|
107
105
|
}
|
|
108
|
-
/** Says which lockfile was used and why, whenever
|
|
109
|
-
function describeLockfileChoice(found) {
|
|
106
|
+
/** Says which lockfile was used and why, whenever its folder held more than one. */
|
|
107
|
+
function describeLockfileChoice(found, folder = "Root") {
|
|
110
108
|
if (found.skipped.length === 0)
|
|
111
109
|
return [];
|
|
112
110
|
const others = found.skipped.join(", ");
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
if (found.name === "npm-shrinkwrap.json" && found.skipped.length === 1 && found.skipped[0] === "package-lock.json") {
|
|
112
|
+
return [`${folder} also contains ${others}. Used npm-shrinkwrap.json because npm reads it ahead of package-lock.json.`];
|
|
113
|
+
}
|
|
114
|
+
if (found.declaredBy) {
|
|
115
|
+
return [`${folder} also contains ${others}. Used ${found.name} because package.json declares packageManager "${found.declaredBy}".`];
|
|
116
|
+
}
|
|
117
|
+
if (found.declaredMissing) {
|
|
118
|
+
const expected = PACKAGE_MANAGER_LOCKFILES[found.declaredMissing].join(" or ");
|
|
119
|
+
return [`${folder} also contains ${others}. Used ${found.name} by precedence; package.json declares packageManager "${found.declaredMissing}" but no ${expected} is present.`];
|
|
120
|
+
}
|
|
121
|
+
return [`${folder} also contains ${others}. Used ${found.name} by precedence; no packageManager field declared.`];
|
|
116
122
|
}
|
|
117
123
|
function readInput(filePath, load) {
|
|
118
124
|
try {
|
|
@@ -122,20 +128,29 @@ function readInput(filePath, load) {
|
|
|
122
128
|
throw new Error(`Failed to read ${filePath}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
123
129
|
}
|
|
124
130
|
}
|
|
125
|
-
function buildLockfileScan(
|
|
131
|
+
function buildLockfileScan(lockfile, prodOnly) {
|
|
132
|
+
const { filePath, name } = lockfile;
|
|
126
133
|
const handler = LOCKFILE_HANDLERS[name];
|
|
134
|
+
const loaded = readInput(filePath, () => handler.load(filePath, prodOnly));
|
|
135
|
+
const packages = Array.isArray(loaded) ? loaded : loaded.packages;
|
|
136
|
+
const warnings = Array.isArray(loaded) ? [] : (loaded.warnings ?? []);
|
|
137
|
+
const skippedDependencies = Array.isArray(loaded) ? [] : (loaded.skippedDependencies ?? []);
|
|
138
|
+
const extraLoadedNotes = Array.isArray(loaded) ? [] : (loaded.notes ?? []);
|
|
139
|
+
const unscannedFiles = Array.isArray(loaded) ? [] : (loaded.unscannedFiles ?? []);
|
|
127
140
|
return {
|
|
128
141
|
mode: "resolved-lockfile",
|
|
129
142
|
source: handler.source,
|
|
130
143
|
filePath,
|
|
131
|
-
packages
|
|
144
|
+
packages,
|
|
132
145
|
notes: [
|
|
133
|
-
`Scanned resolved dependency versions from ${label}.`,
|
|
146
|
+
`Scanned resolved dependency versions from ${lockfile.label}.`,
|
|
134
147
|
handler.pathNote,
|
|
135
|
-
...
|
|
148
|
+
...lockfile.notes,
|
|
149
|
+
...extraLoadedNotes,
|
|
136
150
|
],
|
|
137
|
-
warnings
|
|
138
|
-
skippedDependencies
|
|
151
|
+
warnings,
|
|
152
|
+
skippedDependencies,
|
|
153
|
+
unscannedFiles,
|
|
139
154
|
};
|
|
140
155
|
}
|
|
141
156
|
/**
|
|
@@ -149,23 +164,138 @@ export function selectRootLockfile(projectRoot) {
|
|
|
149
164
|
const root = findRootLockfile(projectRoot);
|
|
150
165
|
return root === null ? null : { filePath: root.filePath, name: root.name };
|
|
151
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* The lockfile a scan of `projectRoot` reads, root or nested. This is the one
|
|
169
|
+
* place that decides it, so anything describing the scan, such as the debug
|
|
170
|
+
* bundle, reports the file the scan actually used.
|
|
171
|
+
*
|
|
172
|
+
* With no lockfile at the root, discovery still decides which nested folder to
|
|
173
|
+
* use. Inside that folder the root rules apply, so its `packageManager` field
|
|
174
|
+
* and npm shrinkwrap precedence are honoured there too (#1514).
|
|
175
|
+
*/
|
|
176
|
+
export function selectScanLockfile(projectRoot, maxDepth) {
|
|
177
|
+
const root = findRootLockfile(projectRoot);
|
|
178
|
+
if (root !== null) {
|
|
179
|
+
return { filePath: root.filePath, name: root.name, label: root.name, notes: describeLockfileChoice(root) };
|
|
180
|
+
}
|
|
181
|
+
const discovered = findFiles(projectRoot, [...LOCKFILE_NAMES], maxDepth);
|
|
182
|
+
if (discovered.length === 0)
|
|
183
|
+
return null;
|
|
184
|
+
const folder = path.dirname(chooseBestLockfile(discovered));
|
|
185
|
+
const nested = findRootLockfile(folder);
|
|
186
|
+
if (nested === null)
|
|
187
|
+
return null;
|
|
188
|
+
return {
|
|
189
|
+
filePath: nested.filePath,
|
|
190
|
+
name: nested.name,
|
|
191
|
+
label: relativeOrName(projectRoot, nested.filePath),
|
|
192
|
+
notes: [NESTED_LOCKFILE_NOTE, ...describeLockfileChoice(nested, relativeOrName(projectRoot, folder))],
|
|
193
|
+
};
|
|
194
|
+
}
|
|
152
195
|
/** Reads every resolved package from a selected lockfile, dev dependencies included. */
|
|
153
196
|
export function readSelectedLockfile(lockfile) {
|
|
154
|
-
|
|
197
|
+
const loaded = LOCKFILE_HANDLERS[lockfile.name].load(lockfile.filePath, false);
|
|
198
|
+
return Array.isArray(loaded) ? loaded : loaded.packages;
|
|
155
199
|
}
|
|
156
|
-
|
|
200
|
+
function checkMixedRepoRefusal(projectRoot, maxDepth, prodOnly) {
|
|
157
201
|
const rootLockfile = findRootLockfile(projectRoot);
|
|
158
202
|
if (rootLockfile !== null) {
|
|
159
|
-
|
|
203
|
+
throw new Error(`Repository root contains ${rootLockfile.name} which was not scanned. Combined JavaScript and Python scanning is not supported; run without --python to scan ${rootLockfile.name}.`);
|
|
204
|
+
}
|
|
205
|
+
const rootPkgJson = path.join(projectRoot, "package.json");
|
|
206
|
+
if (fs.existsSync(rootPkgJson)) {
|
|
207
|
+
let manifestPackagesCount = 0;
|
|
208
|
+
try {
|
|
209
|
+
manifestPackagesCount = loadFromPackageJson(rootPkgJson, prodOnly).packages.length;
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
manifestPackagesCount = 0;
|
|
213
|
+
}
|
|
214
|
+
if (manifestPackagesCount > 0) {
|
|
215
|
+
throw new Error(`Repository root contains package.json which was not scanned. Combined JavaScript and Python scanning is not supported; run without --python to scan package.json.`);
|
|
216
|
+
}
|
|
160
217
|
}
|
|
161
218
|
const discoveredLockfiles = findFiles(projectRoot, [...LOCKFILE_NAMES], maxDepth);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
219
|
+
const nestedLockfiles = discoveredLockfiles.filter(f => path.resolve(f) !== path.resolve(projectRoot, path.basename(f)));
|
|
220
|
+
if (nestedLockfiles.length > 0) {
|
|
221
|
+
const chosen = chooseBestLockfile(nestedLockfiles);
|
|
222
|
+
const rel = relativeOrName(projectRoot, chosen);
|
|
223
|
+
throw new Error(`Repository contains ${rel} which was not scanned. Combined JavaScript and Python scanning is not supported; run without --python to scan ${rel}.`);
|
|
224
|
+
}
|
|
225
|
+
const discoveredPkgJsons = findFiles(projectRoot, ["package.json"], maxDepth);
|
|
226
|
+
for (const pkgPath of discoveredPkgJsons) {
|
|
227
|
+
if (path.resolve(pkgPath) === path.resolve(rootPkgJson))
|
|
228
|
+
continue;
|
|
229
|
+
let manifestPackagesCount = 0;
|
|
230
|
+
try {
|
|
231
|
+
manifestPackagesCount = loadFromPackageJson(pkgPath, prodOnly).packages.length;
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
manifestPackagesCount = 0;
|
|
235
|
+
}
|
|
236
|
+
if (manifestPackagesCount > 0) {
|
|
237
|
+
const rel = relativeOrName(projectRoot, pkgPath);
|
|
238
|
+
throw new Error(`Repository contains ${rel} which was not scanned. Combined JavaScript and Python scanning is not supported; run without --python to scan ${rel}.`);
|
|
167
239
|
}
|
|
168
240
|
}
|
|
241
|
+
}
|
|
242
|
+
export function loadPackages(projectRoot, prodOnly, maxDepth, options) {
|
|
243
|
+
if (options?.python) {
|
|
244
|
+
if (fs.existsSync(projectRoot) && fs.statSync(projectRoot).isFile()) {
|
|
245
|
+
return buildLockfileScan({
|
|
246
|
+
filePath: projectRoot,
|
|
247
|
+
name: "requirements.txt",
|
|
248
|
+
label: path.basename(projectRoot),
|
|
249
|
+
notes: [],
|
|
250
|
+
}, prodOnly);
|
|
251
|
+
}
|
|
252
|
+
checkMixedRepoRefusal(projectRoot, maxDepth, prodOnly);
|
|
253
|
+
const rootReqPath = path.join(projectRoot, "requirements.txt");
|
|
254
|
+
const discovered = findFiles(projectRoot, ["requirements.txt"], maxDepth);
|
|
255
|
+
if (fs.existsSync(rootReqPath)) {
|
|
256
|
+
const unscanned = discovered.filter(f => path.resolve(f) !== path.resolve(rootReqPath));
|
|
257
|
+
const scan = buildLockfileScan({
|
|
258
|
+
filePath: rootReqPath,
|
|
259
|
+
name: "requirements.txt",
|
|
260
|
+
label: "requirements.txt",
|
|
261
|
+
notes: [],
|
|
262
|
+
}, prodOnly);
|
|
263
|
+
if (unscanned.length > 0) {
|
|
264
|
+
const unscannedNames = unscanned.map(f => relativeOrName(projectRoot, f));
|
|
265
|
+
scan.unscannedFiles = [...(scan.unscannedFiles ?? []), ...unscannedNames];
|
|
266
|
+
scan.warnings.push(`Multiple requirements.txt files found. Scanned requirements.txt. Unscanned: ${unscannedNames.join(", ")}`);
|
|
267
|
+
}
|
|
268
|
+
return scan;
|
|
269
|
+
}
|
|
270
|
+
if (discovered.length > 0) {
|
|
271
|
+
const selected = discovered[0];
|
|
272
|
+
const unscanned = discovered.slice(1);
|
|
273
|
+
const scan = buildLockfileScan({
|
|
274
|
+
filePath: selected,
|
|
275
|
+
name: "requirements.txt",
|
|
276
|
+
label: relativeOrName(projectRoot, selected),
|
|
277
|
+
notes: [NESTED_LOCKFILE_NOTE],
|
|
278
|
+
}, prodOnly);
|
|
279
|
+
if (unscanned.length > 0) {
|
|
280
|
+
const unscannedNames = unscanned.map(f => relativeOrName(projectRoot, f));
|
|
281
|
+
scan.unscannedFiles = [...(scan.unscannedFiles ?? []), ...unscannedNames];
|
|
282
|
+
scan.warnings.push(`Multiple requirements.txt files found. Scanned ${relativeOrName(projectRoot, selected)}. Unscanned: ${unscannedNames.join(", ")}`);
|
|
283
|
+
}
|
|
284
|
+
return scan;
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
mode: "manifest-fallback",
|
|
288
|
+
source: "unknown",
|
|
289
|
+
filePath: null,
|
|
290
|
+
packages: [],
|
|
291
|
+
notes: [],
|
|
292
|
+
warnings: ["No requirements.txt found."],
|
|
293
|
+
skippedDependencies: [],
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const lockfile = selectScanLockfile(projectRoot, maxDepth);
|
|
297
|
+
if (lockfile !== null)
|
|
298
|
+
return buildLockfileScan(lockfile, prodOnly);
|
|
169
299
|
const packageJsonPath = findNearestPackageJson(projectRoot, maxDepth);
|
|
170
300
|
if (packageJsonPath) {
|
|
171
301
|
const manifestResult = readInput(packageJsonPath, () => loadFromPackageJson(packageJsonPath, prodOnly));
|
|
@@ -203,7 +333,14 @@ export function loadPackages(projectRoot, prodOnly, maxDepth) {
|
|
|
203
333
|
skippedDependencies: []
|
|
204
334
|
};
|
|
205
335
|
}
|
|
206
|
-
export function buildNoPackagesMessage(projectRoot) {
|
|
336
|
+
export function buildNoPackagesMessage(projectRoot, options) {
|
|
337
|
+
if (options?.python) {
|
|
338
|
+
return [
|
|
339
|
+
"No scannable packages were found.",
|
|
340
|
+
"Supported input with --python: requirements.txt with exact pinned versions (name==version).",
|
|
341
|
+
`Searched under: ${projectRoot}`
|
|
342
|
+
].join(" ");
|
|
343
|
+
}
|
|
207
344
|
return [
|
|
208
345
|
"No scannable packages were found.",
|
|
209
346
|
`Supported inputs: ${[...LOCKFILE_NAMES].sort().join(", ")}, or package.json with exact pinned versions.`,
|
|
@@ -5,6 +5,10 @@ import { loadPackages } from "./index.js";
|
|
|
5
5
|
export function hasRootLockfile(projectRoot) {
|
|
6
6
|
return LOCKFILE_NAMES.some(name => fs.existsSync(path.join(projectRoot, name)));
|
|
7
7
|
}
|
|
8
|
+
/** A root without a lockfile and two or more nested ones is scanned folder by folder. */
|
|
9
|
+
export function isMultiFolderScan(projectRoot, maxDepth) {
|
|
10
|
+
return !hasRootLockfile(projectRoot) && findNestedLockfiles(projectRoot, maxDepth).length >= 2;
|
|
11
|
+
}
|
|
8
12
|
export function findNestedLockfiles(projectRoot, maxDepth) {
|
|
9
13
|
const results = [];
|
|
10
14
|
function walk(dir, depth) {
|
|
@@ -42,6 +42,9 @@ export function buildNpmWorkspaceMap(filePath, options) {
|
|
|
42
42
|
function readLockfileLicense(value) {
|
|
43
43
|
return typeof value === "string" && value.trim() !== "" ? value : undefined;
|
|
44
44
|
}
|
|
45
|
+
function readLockfileResolved(value) {
|
|
46
|
+
return typeof value === "string" && value.trim() !== "" ? value : undefined;
|
|
47
|
+
}
|
|
45
48
|
export function loadFromPackageLock(filePath, prodOnly) {
|
|
46
49
|
const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
47
50
|
const map = new Map();
|
|
@@ -66,7 +69,7 @@ export function loadFromPackageLock(filePath, prodOnly) {
|
|
|
66
69
|
});
|
|
67
70
|
const graphPaths = nodeIds.flatMap(id => graph.pathsFor(id));
|
|
68
71
|
const paths = graphPaths.length > 0 ? graphPaths : [normalizeNodeModulesPath(pkgPath)];
|
|
69
|
-
const resolvedUrl = meta?.resolved;
|
|
72
|
+
const resolvedUrl = readLockfileResolved(meta?.resolved);
|
|
70
73
|
const license = readLockfileLicense(meta?.license);
|
|
71
74
|
upsertPackage(map, {
|
|
72
75
|
name, version, ecosystem: "npm", dev, paths, resolvedUrl, license,
|
|
@@ -85,9 +88,10 @@ function walkLegacyDeps(deps, map, prodOnly, currentPath) {
|
|
|
85
88
|
const version = alias?.version ?? meta?.version;
|
|
86
89
|
const dev = !!meta?.dev;
|
|
87
90
|
const nextPath = [...currentPath, name];
|
|
91
|
+
const resolvedUrl = readLockfileResolved(meta?.resolved);
|
|
88
92
|
if (name && version && !(prodOnly && dev)) {
|
|
89
93
|
upsertPackage(map, {
|
|
90
|
-
name, version, ecosystem: "npm", dev, paths: [nextPath],
|
|
94
|
+
name, version, ecosystem: "npm", dev, paths: [nextPath], resolvedUrl,
|
|
91
95
|
...(alias ? { registryName: alias.registryName } : {}),
|
|
92
96
|
});
|
|
93
97
|
}
|
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import YAML, { YAMLParseError } from "yaml";
|
|
3
3
|
import { looksLikeVersion, normalizeRawVersion } from "../utils/version.js";
|
|
4
4
|
import { upsertPackage, MAX_PATHS_PER_PACKAGE } from "./utils.js";
|
|
5
|
-
import { uniquePathArrays } from "../utils/array.js";
|
|
5
|
+
import { pathsEqual, uniquePathArrays } from "../utils/array.js";
|
|
6
6
|
const MAX_PATH_DEPTH = 10;
|
|
7
7
|
function parsePnpmLockContent(content) {
|
|
8
8
|
try {
|
|
@@ -65,7 +65,9 @@ export function readAndParsePnpmLock(filePath) {
|
|
|
65
65
|
}
|
|
66
66
|
export function buildPnpmWorkspaceMap(filePath) {
|
|
67
67
|
const parsed = readAndParsePnpmLock(filePath);
|
|
68
|
-
|
|
68
|
+
// A single-project v5/v6 lockfile has no `importers`; the root's dependency
|
|
69
|
+
// sections sit at the top level instead.
|
|
70
|
+
const importers = parsed?.importers ?? { ".": parsed ?? {} };
|
|
69
71
|
const map = new Map();
|
|
70
72
|
for (const [importerPath, importer] of Object.entries(importers)) {
|
|
71
73
|
for (const depSectionName of ["dependencies", "optionalDependencies", "devDependencies"]) {
|
|
@@ -283,11 +285,6 @@ function collectPnpmPaths(rootDeps, graph, map, parsePackageKey) {
|
|
|
283
285
|
}
|
|
284
286
|
}
|
|
285
287
|
}
|
|
286
|
-
function pathsEqual(left, right) {
|
|
287
|
-
if (left.length !== right.length)
|
|
288
|
-
return false;
|
|
289
|
-
return left.every((value, index) => value === right[index]);
|
|
290
|
-
}
|
|
291
288
|
// Pre-v9 package keys come in two shapes. Lockfile v6 (pnpm 8) writes
|
|
292
289
|
// `/name@version` with peers in parentheses: `/react-dom@16.0.0(react@16.0.0)`.
|
|
293
290
|
// Lockfile v5 (pnpm 6 and 7) writes `/name/version` with peers after an
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { looksLikeVersion, normalizePep503PackageName } from "../utils/version.js";
|
|
3
|
+
import { upsertPackage } from "./utils.js";
|
|
4
|
+
export { normalizePep503PackageName };
|
|
5
|
+
/**
|
|
6
|
+
* Pinned line regex matching:
|
|
7
|
+
* - Package name: PEP 508 identifier (letters, numbers, '.', '_', '-')
|
|
8
|
+
* - Optional extras: [extra1, extra2]
|
|
9
|
+
* - Strictly '==' (not '===', '!=', '<=', '>=')
|
|
10
|
+
* - Version: PEP 440 version string
|
|
11
|
+
*/
|
|
12
|
+
const PINNED_LINE_REGEX = /^([A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)(?:\s*\[[^\]]*\])?\s*==\s*([^\s;#]+)$/;
|
|
13
|
+
const URL_USERINFO_REGEX = /:\/\/[^\s/]*@/g;
|
|
14
|
+
function redactUrlUserinfo(value) {
|
|
15
|
+
return value.replace(URL_USERINFO_REGEX, "://");
|
|
16
|
+
}
|
|
17
|
+
function extractIncludeTargets(tokens) {
|
|
18
|
+
const targets = [];
|
|
19
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
20
|
+
const token = tokens[i];
|
|
21
|
+
if (token === "-r" || token === "--requirement" || token === "-c" || token === "--constraint") {
|
|
22
|
+
const next = tokens[i + 1];
|
|
23
|
+
if (next && !next.startsWith("-")) {
|
|
24
|
+
targets.push(next);
|
|
25
|
+
i += 1;
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const longMatch = token.match(/^(?:--requirement|--constraint)=(.+)$/);
|
|
30
|
+
if (longMatch) {
|
|
31
|
+
targets.push(longMatch[1]);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if ((token.startsWith("-r") || token.startsWith("-c")) && !token.startsWith("--")) {
|
|
35
|
+
const joined = token.slice(2).replace(/^=/, "");
|
|
36
|
+
if (joined)
|
|
37
|
+
targets.push(joined);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return targets;
|
|
41
|
+
}
|
|
42
|
+
export function parseRequirementsTxt(content, filePath) {
|
|
43
|
+
const map = new Map();
|
|
44
|
+
const skippedDependencies = [];
|
|
45
|
+
const unscannedFiles = [];
|
|
46
|
+
const warnings = [];
|
|
47
|
+
const notes = [];
|
|
48
|
+
let markerScannedCount = 0;
|
|
49
|
+
// Line continuation support: join lines ending in backslash
|
|
50
|
+
const rawLines = [];
|
|
51
|
+
let buffer = "";
|
|
52
|
+
for (const line of content.split(/\r?\n/)) {
|
|
53
|
+
const trimmed = line.trim();
|
|
54
|
+
if (trimmed.startsWith("#")) {
|
|
55
|
+
if (buffer) {
|
|
56
|
+
rawLines.push(buffer);
|
|
57
|
+
buffer = "";
|
|
58
|
+
}
|
|
59
|
+
rawLines.push(line);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const trimmedRight = line.trimEnd();
|
|
63
|
+
if (trimmedRight.endsWith("\\")) {
|
|
64
|
+
buffer += trimmedRight.slice(0, -1).trimEnd() + " ";
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
rawLines.push(buffer + line);
|
|
68
|
+
buffer = "";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (buffer)
|
|
72
|
+
rawLines.push(buffer);
|
|
73
|
+
for (const rawLine of rawLines) {
|
|
74
|
+
const trimmed = rawLine.trim();
|
|
75
|
+
// 1. Skip blanks
|
|
76
|
+
if (!trimmed)
|
|
77
|
+
continue;
|
|
78
|
+
// 2. Skip comments
|
|
79
|
+
if (trimmed.startsWith("#"))
|
|
80
|
+
continue;
|
|
81
|
+
// 3. Strip inline comments: '#' preceded by whitespace
|
|
82
|
+
const commentMatch = trimmed.match(/\s+#.*$/);
|
|
83
|
+
const lineWithoutComment = commentMatch ? trimmed.slice(0, commentMatch.index).trim() : trimmed;
|
|
84
|
+
if (!lineWithoutComment)
|
|
85
|
+
continue;
|
|
86
|
+
// 4. Editable installs
|
|
87
|
+
if (lineWithoutComment === "-e" ||
|
|
88
|
+
lineWithoutComment.startsWith("-e ") ||
|
|
89
|
+
lineWithoutComment.startsWith("-e\t") ||
|
|
90
|
+
lineWithoutComment.startsWith("--editable ") ||
|
|
91
|
+
lineWithoutComment.startsWith("--editable=")) {
|
|
92
|
+
const sanitized = redactUrlUserinfo(lineWithoutComment);
|
|
93
|
+
warnings.push(`Skipped editable install: ${sanitized}`);
|
|
94
|
+
skippedDependencies.push(sanitized);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
// 5. Included files (-r, -c, --requirement, --constraint)
|
|
98
|
+
const isRequirement = lineWithoutComment === "-r" ||
|
|
99
|
+
lineWithoutComment === "--requirement" ||
|
|
100
|
+
(lineWithoutComment.startsWith("-r") && !lineWithoutComment.startsWith("--")) ||
|
|
101
|
+
/^--requirement[=\s]/.test(lineWithoutComment);
|
|
102
|
+
const isConstraint = lineWithoutComment === "-c" ||
|
|
103
|
+
lineWithoutComment === "--constraint" ||
|
|
104
|
+
(lineWithoutComment.startsWith("-c") && !lineWithoutComment.startsWith("--")) ||
|
|
105
|
+
/^--constraint[=\s]/.test(lineWithoutComment);
|
|
106
|
+
if (isRequirement || isConstraint) {
|
|
107
|
+
const sanitized = redactUrlUserinfo(lineWithoutComment);
|
|
108
|
+
const target = redactUrlUserinfo(lineWithoutComment.replace(/^(-r|-c|--requirement|--constraint)[=\s]*/, "").trim());
|
|
109
|
+
warnings.push(`Included file was not scanned: ${target || sanitized}`);
|
|
110
|
+
unscannedFiles.push(target || sanitized);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
// 6. Option lines (e.g. --index-url, --extra-index-url, -i, -f, --find-links, etc.)
|
|
114
|
+
// Option lines must be ignored, not counted as a skipped dependency and not marking the scan partial.
|
|
115
|
+
// However, pip allows includes on the same line as other options, so scan every token before ignoring the line.
|
|
116
|
+
if (lineWithoutComment.startsWith("-")) {
|
|
117
|
+
for (const rawTarget of extractIncludeTargets(lineWithoutComment.split(/\s+/))) {
|
|
118
|
+
const target = redactUrlUserinfo(rawTarget);
|
|
119
|
+
warnings.push(`Included file was not scanned: ${target}`);
|
|
120
|
+
unscannedFiles.push(target);
|
|
121
|
+
}
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
// 7. Environment markers (`; python_version < "3.12"`). The pin before the
|
|
125
|
+
// marker is scanned whatever the marker says: reporting a package that may not
|
|
126
|
+
// apply here is safer than not looking at it. A skipped line is named in full.
|
|
127
|
+
const markerIndex = lineWithoutComment.indexOf(";");
|
|
128
|
+
const hasMarker = markerIndex !== -1;
|
|
129
|
+
const requirement = hasMarker ? lineWithoutComment.slice(0, markerIndex) : lineWithoutComment;
|
|
130
|
+
const skipLabel = (spec) => redactUrlUserinfo(hasMarker ? lineWithoutComment : spec);
|
|
131
|
+
// 8. Strip hashes if present (--hash=...)
|
|
132
|
+
const cleanSpec = requirement.replace(/--hash=\S+/g, "").trim();
|
|
133
|
+
if (!cleanSpec)
|
|
134
|
+
continue;
|
|
135
|
+
// Reject arbitrary equality '===' as unpinned/unsupported
|
|
136
|
+
if (cleanSpec.includes("===")) {
|
|
137
|
+
const sanitized = skipLabel(cleanSpec);
|
|
138
|
+
warnings.push(`Skipped unsupported equality: ${sanitized}`);
|
|
139
|
+
skippedDependencies.push(sanitized);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
// 9. Pinned line of the form name==version
|
|
143
|
+
const match = cleanSpec.match(PINNED_LINE_REGEX);
|
|
144
|
+
if (match) {
|
|
145
|
+
const name = match[1];
|
|
146
|
+
const version = match[2];
|
|
147
|
+
if (!looksLikeVersion(version, "pypi")) {
|
|
148
|
+
const sanitized = skipLabel(cleanSpec);
|
|
149
|
+
warnings.push(`Skipped invalid version: ${sanitized}`);
|
|
150
|
+
skippedDependencies.push(sanitized);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
upsertPackage(map, {
|
|
154
|
+
name,
|
|
155
|
+
version,
|
|
156
|
+
ecosystem: "pypi",
|
|
157
|
+
paths: [["project", name]],
|
|
158
|
+
});
|
|
159
|
+
if (hasMarker)
|
|
160
|
+
markerScannedCount += 1;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
// 10. All other lines (unpinned ranges >=, <=, ~=, !=, bare names, URLs)
|
|
164
|
+
const sanitized = skipLabel(cleanSpec);
|
|
165
|
+
warnings.push(`Skipped unpinned dependency: ${sanitized}`);
|
|
166
|
+
skippedDependencies.push(sanitized);
|
|
167
|
+
}
|
|
168
|
+
if (markerScannedCount > 0) {
|
|
169
|
+
notes.push(`Scanned ${markerScannedCount} pinned ${markerScannedCount === 1 ? "entry that carries" : "entries that carry"} an environment marker, whether or not the marker applies here.`);
|
|
170
|
+
}
|
|
171
|
+
if (skippedDependencies.length > 0) {
|
|
172
|
+
notes.push(`Skipped ${skippedDependencies.length} unsupported or unpinned ${skippedDependencies.length === 1 ? "entry" : "entries"}.`);
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
packages: [...map.values()],
|
|
176
|
+
skippedDependencies,
|
|
177
|
+
warnings,
|
|
178
|
+
notes,
|
|
179
|
+
unscannedFiles,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
export function loadFromRequirementsTxt(filePath) {
|
|
183
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
184
|
+
return parseRequirementsTxt(content, filePath);
|
|
185
|
+
}
|
package/dist/parsers/utils.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { uniquePathArrays } from "../utils/array.js";
|
|
2
2
|
import { packageInstanceKey } from "../utils/package-identity.js";
|
|
3
|
+
import { stripUrlCredentials } from "../utils/url.js";
|
|
3
4
|
export const MAX_PATHS_PER_PACKAGE = 5;
|
|
4
5
|
export function upsertPackage(map, candidate) {
|
|
5
|
-
const
|
|
6
|
+
const sanitized = candidate.resolvedUrl
|
|
7
|
+
? { ...candidate, resolvedUrl: stripUrlCredentials(candidate.resolvedUrl) }
|
|
8
|
+
: candidate;
|
|
9
|
+
const key = packageInstanceKey(sanitized);
|
|
6
10
|
const existing = map.get(key);
|
|
7
11
|
if (!existing) {
|
|
8
|
-
map.set(key, { ...
|
|
12
|
+
map.set(key, { ...sanitized, paths: uniquePathArrays(sanitized.paths ?? []).slice(0, MAX_PATHS_PER_PACKAGE) });
|
|
9
13
|
return;
|
|
10
14
|
}
|
|
11
|
-
existing.dev = existing.dev &&
|
|
12
|
-
existing.paths = uniquePathArrays([...(existing.paths ?? []), ...(
|
|
15
|
+
existing.dev = existing.dev && sanitized.dev;
|
|
16
|
+
existing.paths = uniquePathArrays([...(existing.paths ?? []), ...(sanitized.paths ?? [])]).slice(0, MAX_PATHS_PER_PACKAGE);
|
|
13
17
|
// The same name@version can appear at several lockfile paths; keep the first
|
|
14
|
-
// license we see rather than losing it if a later entry omits the field.
|
|
15
|
-
existing.license ??=
|
|
18
|
+
// license and resolvedUrl we see rather than losing it if a later entry omits the field.
|
|
19
|
+
existing.license ??= sanitized.license;
|
|
20
|
+
existing.resolvedUrl ??= sanitized.resolvedUrl;
|
|
16
21
|
}
|
|
17
22
|
export function normalizeNodeModulesPath(pkgPath) {
|
|
18
23
|
const parts = pkgPath.split("/").filter(Boolean);
|