vigievuln 1.2.0 → 1.3.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/CHANGELOG.md +23 -2
- package/README.md +13 -7
- package/lib/advisory-freshness.js +2 -0
- package/lib/airgap-project.js +35 -7
- package/lib/applicability-evidence.js +12 -0
- package/lib/artifacts/applications.js +54 -0
- package/lib/artifacts/cve-view.js +108 -0
- package/lib/artifacts/enrichment.js +86 -0
- package/lib/artifacts/go-main-identity.js +45 -0
- package/lib/artifacts/go-publisher-advisories.js +24 -0
- package/lib/artifacts/index.js +272 -0
- package/lib/artifacts/publisher-advisories.js +12 -0
- package/lib/artifacts/remediation-report.js +48 -0
- package/lib/artifacts/report-inventory.js +26 -0
- package/lib/artifacts/report.js +191 -0
- package/lib/artifacts/risk-report.js +120 -0
- package/lib/artifacts/sbom.js +68 -0
- package/lib/artifacts/scan.js +401 -0
- package/lib/cache-archive-sqlite.js +41 -25
- package/lib/certs/analyze.js +49 -13
- package/lib/charts.js +124 -32
- package/lib/cli-command-routing.js +20 -6
- package/lib/cli-groups.js +2 -1
- package/lib/cli-image.js +206 -0
- package/lib/codecs/binary/elf-metadata.js +42 -0
- package/lib/codecs/binary/go-buildinfo.js +37 -0
- package/lib/codecs/binary/metadata.js +7 -0
- package/lib/codecs/binary/pe-metadata.js +27 -1
- package/lib/codecs/binary/scan.js +44 -26
- package/lib/codecs/binary/sniff.js +16 -15
- package/lib/codecs/binary.codec.js +27 -4
- package/lib/codecs/go/parse.js +10 -4
- package/lib/codecs/go.codec.js +23 -6
- package/lib/codecs/gradle/parse.js +63 -2
- package/lib/codecs/gradle/versionless.js +175 -0
- package/lib/codecs/gradle.codec.js +20 -3
- package/lib/codecs/index.js +2 -2
- package/lib/codecs/maven.codec.js +9 -4
- package/lib/codecs/npm/collect.js +6 -11
- package/lib/codecs/nuget/parse.js +16 -5
- package/lib/codecs/nuget.codec.js +2 -1
- package/lib/codecs/pypi/parse.js +56 -15
- package/lib/codecs/pypi.codec.js +2 -0
- package/lib/csaf-export.js +46 -11
- package/lib/cve-download.js +33 -29
- package/lib/cve-match.js +10 -0
- package/lib/cve-packages-proxy.js +19 -0
- package/lib/cve-report.js +273 -165
- package/lib/deps-descriptor.js +25 -3
- package/lib/diagnostics.js +12 -0
- package/lib/diff.js +0 -0
- package/lib/epss.js +6 -6
- package/lib/euvd.js +34 -4
- package/lib/finding-enrichment.js +165 -0
- package/lib/finding-summary.js +4 -3
- package/lib/i18n.js +35 -9
- package/lib/image-network.js +54 -0
- package/lib/image-references.js +203 -0
- package/lib/image-registry.js +385 -0
- package/lib/image-update.js +39 -0
- package/lib/json-export.js +100 -10
- package/lib/kev.js +6 -6
- package/lib/maven-bom.js +2 -1
- package/lib/merge-sources.js +3 -0
- package/lib/native-advisories.js +9 -7
- package/lib/native-cna-identities.js +12 -0
- package/lib/native-package-match.js +159 -0
- package/lib/native-source-prepare.js +60 -0
- package/lib/nvd.js +34 -23
- package/lib/osv.js +33 -14
- package/lib/project-descriptor.js +3 -2
- package/lib/provenance.js +8 -2
- package/lib/providers/alpine.js +8 -0
- package/lib/providers/common.js +11 -3
- package/lib/providers/debian.js +11 -0
- package/lib/providers/euvd.js +2 -1
- package/lib/providers/freexian.js +13 -0
- package/lib/providers/github.js +1 -0
- package/lib/providers/go.js +2 -1
- package/lib/providers/index.js +18 -14
- package/lib/providers/nginx.js +5 -0
- package/lib/providers/nvd.js +1 -1
- package/lib/providers/osv.js +1 -1
- package/lib/providers/osvdb.js +2 -2
- package/lib/proxy-throttle.js +89 -29
- package/lib/purl.js +10 -2
- package/lib/record-freshness.js +22 -0
- package/lib/report-notices.js +47 -0
- package/lib/report-time.js +45 -0
- package/lib/request-failure.js +22 -0
- package/lib/resource-cache/engine.js +130 -26
- package/lib/resource-cache/snapshot-projection.js +33 -0
- package/lib/resource-cache/validate.js +22 -5
- package/lib/risk-evidence.js +18 -0
- package/lib/sarif-export.js +17 -9
- package/lib/sbom-export.js +38 -12
- package/lib/source-health.js +25 -8
- package/lib/source-image-scan.js +57 -0
- package/lib/source-profile.js +6 -3
- package/lib/sqlite-driver.js +15 -1
- package/lib/suppress.js +34 -13
- package/lib/system-inventory/advisories.js +169 -0
- package/lib/system-inventory/alpine-tracker.js +47 -0
- package/lib/system-inventory/collect.js +118 -0
- package/lib/system-inventory/current-debian.js +99 -0
- package/lib/system-inventory/distribution-sources.js +132 -0
- package/lib/system-inventory/freexian-ela.js +32 -0
- package/lib/system-inventory/freexian-release-evidence.js +35 -0
- package/lib/system-inventory/freexian-tracker.js +72 -0
- package/lib/system-inventory/historical-debian.js +196 -0
- package/lib/system-inventory/index.js +2 -0
- package/lib/system-inventory/nginx-advisories.js +39 -0
- package/lib/system-inventory/rpm-storage.js +86 -0
- package/lib/system-inventory/targeted.js +70 -0
- package/lib/system-inventory/versions.js +59 -0
- package/lib/transitive.js +11 -2
- package/lib/ui.js +8 -5
- package/lib/unmanaged.js +1 -1
- package/lib/xlsx-export.js +8 -2
- package/package.json +12 -3
- package/vigievuln.js +279 -127
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* @author: N.BRAUN
|
|
21
21
|
* @email: pp9ping@gmail.com
|
|
22
22
|
*/
|
|
23
|
-
const { resolveLibraryAccessor, findCatalogVersion } = require("./catalog");
|
|
23
|
+
const { resolveLibraryAccessor, findCatalogVersion, normKey } = require("./catalog");
|
|
24
24
|
const { compareMavenVersions } = require("../../maven-version");
|
|
25
25
|
|
|
26
26
|
const COORD = "[A-Za-z0-9_.\\-]+";
|
|
@@ -79,6 +79,8 @@ function resolveVer(raw, ctx) {
|
|
|
79
79
|
m = v.match(/\$\{?([\w.]+)\}?/);
|
|
80
80
|
if (m) {
|
|
81
81
|
const k = m[1];
|
|
82
|
+
if (ctx.ambiguousVars?.has(k)) return null;
|
|
83
|
+
if (ctx.extVars?.has(k) && m[0] !== v) return null;
|
|
82
84
|
if (ctx.localVars && ctx.localVars[k] != null) return ctx.localVars[k];
|
|
83
85
|
if (ctx.properties && ctx.properties[k] != null) return ctx.properties[k];
|
|
84
86
|
}
|
|
@@ -338,6 +340,38 @@ function findExcludes(clean, mask, from, to) {
|
|
|
338
340
|
return out;
|
|
339
341
|
}
|
|
340
342
|
|
|
343
|
+
// Spring Boot imports its matching BOM only when BOTH plugins are applied. Limit
|
|
344
|
+
// inference to a top-level plugins block: pluginManagement, apply false, comments
|
|
345
|
+
// and strings do not establish that either plugin runs in this project.
|
|
346
|
+
function springBootBom(clean, mask, blocks, ctx) {
|
|
347
|
+
const applied = new Map();
|
|
348
|
+
for (const block of blocks) {
|
|
349
|
+
if (block.header !== "plugins" || enclosingBlocks(blocks, block.open).length) continue;
|
|
350
|
+
const declarations = [...clean.slice(block.open + 1, block.close).matchAll(
|
|
351
|
+
/\b(?:id\s*(?:\(\s*)?(["'])([^"']+)\1\s*\)?|alias\s*\(\s*libs\.plugins\.([\w.]+)\s*\))/g
|
|
352
|
+
)].filter(m => mask[block.open + 1 + m.index] !== " ");
|
|
353
|
+
for (let i = 0; i < declarations.length; i++) {
|
|
354
|
+
const m = declarations[i];
|
|
355
|
+
const start = block.open + 1 + m.index + m[0].length;
|
|
356
|
+
const end = i + 1 < declarations.length ? block.open + 1 + declarations[i + 1].index : block.close;
|
|
357
|
+
const suffix = clean.slice(start, end);
|
|
358
|
+
if (/\bapply\s*(?:\(\s*)?false\b/.test(mask.slice(start, end))) continue;
|
|
359
|
+
const plugin = m[3] && Object.entries(ctx.catalog?.plugins || {}).find(([alias]) => normKey(alias) === normKey(m[3]))?.[1];
|
|
360
|
+
const id = m[2] || plugin?.id;
|
|
361
|
+
const versionExpr = suffix.match(/^\s*\.?\s*version\s*(?:\(\s*)?(["'])(.*?)\1/s);
|
|
362
|
+
let version = versionExpr ? versionExpr[2] : plugin?.version;
|
|
363
|
+
// Only resolve a whole variable here; resolveVer's best-effort dependency
|
|
364
|
+
// parsing would turn "4.${patch}" into just the value of patch.
|
|
365
|
+
if (version?.includes("$")) version = /^\$(?:[\w.]+|\{[\w.]+\})$/.test(version) ? resolveVer(version, ctx) : null;
|
|
366
|
+
if (id) applied.set(id, version || null);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const version = applied.get("org.springframework.boot");
|
|
370
|
+
// Unknown and dynamic versions cannot identify a concrete BOM safely.
|
|
371
|
+
if (!applied.has("io.spring.dependency-management") || !version || !/^\d[\w.\-]*$/.test(version)) return null;
|
|
372
|
+
return { group: "org.springframework.boot", name: "spring-boot-dependencies", version, inferred: true };
|
|
373
|
+
}
|
|
374
|
+
|
|
341
375
|
/**
|
|
342
376
|
* Best-effort parse of a build.gradle / build.gradle.kts.
|
|
343
377
|
* @param opts { catalog, properties, kotlin, extraExcludes } — catalog from
|
|
@@ -359,6 +393,28 @@ function parseBuildScript(text, opts = {}) {
|
|
|
359
393
|
const { clean, mask } = lexScript(src);
|
|
360
394
|
for (const m of clean.matchAll(/\b(?:val|def)\s+(\w+)\s*=\s*["']([^"']*)["']/g)) ctx.localVars[m[1]] = m[2];
|
|
361
395
|
const blocks = scriptBlocks(clean, mask);
|
|
396
|
+
if (!opts.kotlin) {
|
|
397
|
+
// Recognize only literal assignments directly in a top-level Groovy ext
|
|
398
|
+
// block. Any other assignment to the same name makes its value uncertain.
|
|
399
|
+
const assignments = [...mask.matchAll(/\b([A-Za-z_]\w*)\s*(?:\*\*=|<<=|>>>=|>>=|\+=|-=|\*=|\/=|%=|&=|\|=|\^=|=(?!=))/g)];
|
|
400
|
+
const extAssignments = assignments.filter(m => {
|
|
401
|
+
const parents = enclosingBlocks(blocks, m.index);
|
|
402
|
+
return parents.length === 1 && parents[0].header === "ext" && !/[\w.]/.test(mask[m.index - 1] || "");
|
|
403
|
+
});
|
|
404
|
+
// Indexed or method-based writes may compute the property name at runtime.
|
|
405
|
+
const indirectWrite = /\b(?:ext|(?:project\s*\.\s*)?ext)\s*(?:\[|\.\s*(?:set|setProperty)\s*\()|\b(?:setProperty|setExtProperty)\s*\(/.test(mask);
|
|
406
|
+
ctx.ambiguousVars = new Set();
|
|
407
|
+
ctx.extVars = new Set();
|
|
408
|
+
for (const m of extAssignments) {
|
|
409
|
+
const name = m[1];
|
|
410
|
+
const literal = clean.slice(m.index + m[0].length).match(/^[ \t]*(["'])(\d[\w.\-]*)\1(?=[ \t]*(?:;|\n|}|$))/);
|
|
411
|
+
const mutated = new RegExp(`(?:\\b${name}\\s*(?:\\+\\+|--)|(?:\\+\\+|--)\\s*(?:[A-Za-z_]\\w*\\s*\\.\\s*)*${name}\\b)`).test(mask);
|
|
412
|
+
if (!literal || indirectWrite || mutated || assignments.filter(a => a[1] === name).length !== 1 || !/^\w+\s*=$/.test(m[0])) {
|
|
413
|
+
ctx.ambiguousVars.add(name);
|
|
414
|
+
delete ctx.localVars[name];
|
|
415
|
+
} else { ctx.localVars[name] = literal[2]; ctx.extVars.add(name); }
|
|
416
|
+
}
|
|
417
|
+
}
|
|
362
418
|
const blockAt = new Map(blocks.map(b => [b.open, b]));
|
|
363
419
|
const isGlobal = idx => enclosingBlocks(blocks, idx).some(b => GLOBAL_HEADER.test(b.header));
|
|
364
420
|
|
|
@@ -380,6 +436,9 @@ function parseBuildScript(text, opts = {}) {
|
|
|
380
436
|
if (coord && coord.group && coord.name && !platformBoms.some(b => b.group === coord.group && b.name === coord.name)) platformBoms.push(coord);
|
|
381
437
|
blankSpans.push([pm.index, end + 1]);
|
|
382
438
|
}
|
|
439
|
+
// Keep an explicit platform declaration authoritative when it names this BOM.
|
|
440
|
+
const bootBom = springBootBom(clean, mask, blocks, ctx);
|
|
441
|
+
if (bootBom && !platformBoms.some(b => b.group === bootBom.group && b.name === bootBom.name)) platformBoms.push(bootBom);
|
|
383
442
|
|
|
384
443
|
// 2. force(…) / forcedModules = [ … ] — a FORCE is a version constraint that wins over
|
|
385
444
|
// every other requirement, not a dependency: it only applies if something brings the
|
|
@@ -507,10 +566,12 @@ function parseBuildScript(text, opts = {}) {
|
|
|
507
566
|
const scope = depScope(d.config);
|
|
508
567
|
const existing = byKey.get(key);
|
|
509
568
|
if (!existing) {
|
|
510
|
-
byKey.set(key, { group: d.group, name: d.name, version, configuration: d.config, ...scope, exclusionSets: [exclusions] });
|
|
569
|
+
byKey.set(key, { group: d.group, name: d.name, version, configuration: d.config, configurations: [d.config], ...scope, exclusionSets: [exclusions], gradleDeclarations: [{ configuration: d.config, exclusions }] });
|
|
511
570
|
continue;
|
|
512
571
|
}
|
|
513
572
|
existing.exclusionSets.push(exclusions);
|
|
573
|
+
existing.gradleDeclarations.push({ configuration: d.config, exclusions });
|
|
574
|
+
if (!existing.configurations.includes(d.config)) existing.configurations.push(d.config);
|
|
514
575
|
// The WIDEST scope wins (a production declaration beats a test one, whatever the
|
|
515
576
|
// order): `testImplementation` listed above `implementation` used to file the dep as
|
|
516
577
|
// test-only — out of the production count and the CI gate. The version follows the
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Recover an unversioned Gradle declaration from requests made elsewhere in the
|
|
2
|
+
// same project's classpaths. This is deliberately separate from Maven mediation.
|
|
3
|
+
const { resolveTransitiveDeps } = require("../../transitive");
|
|
4
|
+
|
|
5
|
+
const CLASSPATHS = {
|
|
6
|
+
api: ["compile", "runtime", "testCompile", "testRuntime"],
|
|
7
|
+
implementation: ["compile", "runtime", "testCompile", "testRuntime"],
|
|
8
|
+
compileOnly: ["compile"],
|
|
9
|
+
compileOnlyApi: ["compile"],
|
|
10
|
+
runtimeOnly: ["runtime", "testRuntime"],
|
|
11
|
+
providedCompile: ["compile", "runtime", "testCompile", "testRuntime"],
|
|
12
|
+
providedRuntime: ["runtime", "testRuntime"],
|
|
13
|
+
testImplementation: ["testCompile", "testRuntime"],
|
|
14
|
+
testCompileOnly: ["testCompile"],
|
|
15
|
+
testRuntimeOnly: ["testRuntime"],
|
|
16
|
+
};
|
|
17
|
+
function classpaths(dep) {
|
|
18
|
+
return [...new Set((dep.gradleConfigurations || []).flatMap(c => CLASSPATHS[c] || [`custom:${c}`]))];
|
|
19
|
+
}
|
|
20
|
+
function ownClasspaths(dep) {
|
|
21
|
+
const all = classpaths(dep);
|
|
22
|
+
// Production dependencies also reach test classpaths, but test-only requests
|
|
23
|
+
// cannot supply the version of a production declaration.
|
|
24
|
+
return dep.isDev ? all : all.filter(c => !c.startsWith("test"));
|
|
25
|
+
}
|
|
26
|
+
function exclusions(sets) {
|
|
27
|
+
if (!sets?.length) return [];
|
|
28
|
+
return [...new Set(sets[0])].filter(x => sets.every(s => s.includes(x))).map(x => {
|
|
29
|
+
const i = x.indexOf(":");
|
|
30
|
+
return { groupId: x.slice(0, i), artifactId: x.slice(i + 1) };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function exclusionsForClasspath(dep, cp) {
|
|
34
|
+
if (!dep.gradleDeclarations) return exclusions(dep.exclusionSets);
|
|
35
|
+
return exclusions(dep.gradleDeclarations.filter(d => (CLASSPATHS[d.configuration] || [`custom:${d.configuration}`]).includes(cp)).map(d => d.exclusions));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Gradle compares numeric parts numerically; an extra numeric part is higher,
|
|
39
|
+
// including a trailing zero. Do not apply Maven's qualifier/range ordering.
|
|
40
|
+
function highestRelease(versions) {
|
|
41
|
+
const values = [...new Set(versions)];
|
|
42
|
+
if (values.includes(null)) return null;
|
|
43
|
+
if (values.length === 1) return values[0];
|
|
44
|
+
if (!values.length || values.some(v => !/^\d+(?:\.\d+)*$/.test(v))) return null;
|
|
45
|
+
return values.sort((a, b) => {
|
|
46
|
+
const x = a.split(".").map(BigInt), y = b.split(".").map(BigInt);
|
|
47
|
+
for (let i = 0; i < Math.min(x.length, y.length); i++) {
|
|
48
|
+
if (x[i] !== y[i]) return x[i] < y[i] ? -1 : 1;
|
|
49
|
+
}
|
|
50
|
+
return x.length - y.length;
|
|
51
|
+
}).at(-1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function recoverVersionlessGradle(deps, opts = {}) {
|
|
55
|
+
const pick = opts.only || (() => true);
|
|
56
|
+
const records = [...deps.values()].filter(d => pick(d) && d.ecosystemType === "gradle"
|
|
57
|
+
&& d.provenance === "manifest" && !d.fromLockfile && !d.versionUnresolved
|
|
58
|
+
&& d.manifestPaths?.length === 1 && (d.versions || []).length <= 1);
|
|
59
|
+
const usableRecords = new Set(records);
|
|
60
|
+
const targets = records.filter(d => !d.version && !d.managedOnly
|
|
61
|
+
&& (opts.includeTestDeps || !d.isDev) && ownClasspaths(d).length);
|
|
62
|
+
if (!targets.length) return 0;
|
|
63
|
+
const groups = new Map();
|
|
64
|
+
for (const target of targets) for (const cp of ownClasspaths(target)) {
|
|
65
|
+
const manifest = target.manifestPaths[0];
|
|
66
|
+
const key = JSON.stringify([manifest, cp]);
|
|
67
|
+
if (!groups.has(key)) groups.set(key, { manifest, cp, targets: [] });
|
|
68
|
+
groups.get(key).targets.push(target);
|
|
69
|
+
}
|
|
70
|
+
const evidence = new Map(targets.map(d => [d.coordKey, []]));
|
|
71
|
+
for (const { manifest, cp, targets: localTargets } of groups.values()) {
|
|
72
|
+
// An omitted root can contribute any version on this classpath. Do not
|
|
73
|
+
// infer from a graph that silently dropped an unresolved or merged record.
|
|
74
|
+
const omittedRoot = [...deps.values()].some(d => d.ecosystemType === "gradle"
|
|
75
|
+
&& d.provenance === "manifest" && !d.fromLockfile && !usableRecords.has(d)
|
|
76
|
+
&& d.manifestPaths?.includes(manifest) && (d.managedOnly || classpaths(d).includes(cp)));
|
|
77
|
+
if (omittedRoot) continue;
|
|
78
|
+
// A cached effective POM may have been built while its parent was unavailable.
|
|
79
|
+
// Keep recovery's cache local to this classpath so missing-parent evidence is not lost.
|
|
80
|
+
const effCache = new Map();
|
|
81
|
+
const local = records.filter(d => d.manifestPaths[0] === manifest && (d.managedOnly || classpaths(d).includes(cp)));
|
|
82
|
+
const keys = new Set(local.filter(d => !d.managedOnly && !d.version).map(d => d.coordKey));
|
|
83
|
+
const rootDepMgmt = new Map(opts.bomDepMgmt || []);
|
|
84
|
+
for (const [key, m] of (opts.gradleBomDepMgmt || [])) if (m.manifestPath === manifest) rootDepMgmt.set(key, m);
|
|
85
|
+
// An ordinary direct version is a request, not a Gradle force. Keep the
|
|
86
|
+
// provenance of actual pins separate from the Maven traversal overrides.
|
|
87
|
+
const provenPins = new Map(rootDepMgmt);
|
|
88
|
+
for (const d of local) if (d.version) rootDepMgmt.set(d.coordKey, {
|
|
89
|
+
version: d.version, exclusions: exclusions(d.mgmtExclusionSets), ...(d.pinMinimum ? { minimum: true } : {}),
|
|
90
|
+
});
|
|
91
|
+
for (const d of local) if (d.version) {
|
|
92
|
+
if (d.managedOnly) provenPins.set(d.coordKey, { version: d.version, minimum: !!d.pinMinimum });
|
|
93
|
+
else {
|
|
94
|
+
const pin = provenPins.get(d.coordKey);
|
|
95
|
+
if ((typeof pin === "string" ? pin : pin?.version) !== d.version) provenPins.delete(d.coordKey);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
let selected = new Map(), finalRequests = null;
|
|
99
|
+
// Re-walk after selecting versions so children belonging only to a discarded
|
|
100
|
+
// version cannot supply another declaration. A cycle/unstable graph stays unknown.
|
|
101
|
+
for (let pass = 0; pass < 8; pass++) {
|
|
102
|
+
const requests = new Map([...keys].map(k => [k, []]));
|
|
103
|
+
const graphRequests = new Map();
|
|
104
|
+
let incomplete = false;
|
|
105
|
+
const roots = local.filter(d => !d.managedOnly && (d.version || selected.get(d.coordKey))).map(d => ({
|
|
106
|
+
...d, version: d.version || selected.get(d.coordKey), exclusions: exclusionsForClasspath(d, cp),
|
|
107
|
+
}));
|
|
108
|
+
const pins = new Map(rootDepMgmt);
|
|
109
|
+
for (const [key, version] of selected) pins.set(key, { version });
|
|
110
|
+
const resolved = await resolveTransitiveDeps(roots, {
|
|
111
|
+
...opts, effCache, rootDepMgmt: pins,
|
|
112
|
+
runtimeDependencies: cp !== "compile" && cp !== "testCompile",
|
|
113
|
+
includedScopes: cp.startsWith("test") ? ["compile", "runtime", "provided", "test"] : ["compile", "runtime", "provided"],
|
|
114
|
+
versionRequestKeys: keys,
|
|
115
|
+
onVersionRequest: r => requests.get(r.key).push(r),
|
|
116
|
+
onGraphRequest: ({ key, version }) => {
|
|
117
|
+
if (!graphRequests.has(key)) graphRequests.set(key, new Set());
|
|
118
|
+
graphRequests.get(key).add(version);
|
|
119
|
+
},
|
|
120
|
+
onMissingPom: info => { incomplete = true; opts.onMissingPom?.(info); },
|
|
121
|
+
onPomCycle: info => { incomplete = true; opts.onPomCycle?.(info); },
|
|
122
|
+
onResolutionError: (...args) => { incomplete = true; opts.onResolutionError?.(...args); },
|
|
123
|
+
onDepthLimit: (...args) => { incomplete = true; opts.onDepthLimit?.(...args); },
|
|
124
|
+
});
|
|
125
|
+
// Maven mediates intermediate conflicts differently from Gradle. Do not
|
|
126
|
+
// infer a target through a graph whose selected intermediate is uncertain.
|
|
127
|
+
for (const [key, versions] of graphRequests) {
|
|
128
|
+
if (keys.has(key)) continue;
|
|
129
|
+
const pin = provenPins.get(key);
|
|
130
|
+
const pinnedVersion = typeof pin === "string" ? pin : pin?.version;
|
|
131
|
+
if (pinnedVersion && !pin?.minimum) continue;
|
|
132
|
+
const effective = [...versions].map(v => pinnedVersion && v && /^\d+(?:\.\d+)*$/.test(v) && /^\d+(?:\.\d+)*$/.test(pinnedVersion) ? highestRelease([v, pinnedVersion]) : v);
|
|
133
|
+
const distinct = new Set(effective);
|
|
134
|
+
if (distinct.has(null)) { incomplete = true; continue; }
|
|
135
|
+
if (distinct.size <= 1) continue;
|
|
136
|
+
const highest = highestRelease([...distinct]);
|
|
137
|
+
const chosen = roots.find(d => d.coordKey === key)?.version || resolved.get(key)?.version;
|
|
138
|
+
if (!highest || chosen !== highest) incomplete = true;
|
|
139
|
+
}
|
|
140
|
+
if (incomplete) break;
|
|
141
|
+
const next = new Map();
|
|
142
|
+
for (const [key, rs] of requests) {
|
|
143
|
+
const version = highestRelease(rs.map(r => r.version));
|
|
144
|
+
if (version) next.set(key, version);
|
|
145
|
+
}
|
|
146
|
+
if (next.size === selected.size && [...next].every(([k, v]) => selected.get(k) === v)) {
|
|
147
|
+
// An unresolved root could itself request a higher version elsewhere.
|
|
148
|
+
if (next.size === keys.size) finalRequests = requests;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
selected = next;
|
|
152
|
+
}
|
|
153
|
+
if (!finalRequests) continue;
|
|
154
|
+
for (const { coordKey: key } of localTargets) {
|
|
155
|
+
const version = selected.get(key);
|
|
156
|
+
evidence.get(key).push({
|
|
157
|
+
version, paths: finalRequests.get(key).filter(r => r.version === version).map(r => r.via),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let filled = 0;
|
|
162
|
+
for (const target of targets) {
|
|
163
|
+
const hits = evidence.get(target.coordKey);
|
|
164
|
+
if (hits.length !== ownClasspaths(target).length || new Set(hits.map(h => h.version)).size !== 1) continue;
|
|
165
|
+
const version = hits[0].version;
|
|
166
|
+
target.version = version;
|
|
167
|
+
target.versions = [version];
|
|
168
|
+
target.versionPaths = { [version]: [...target.manifestPaths] };
|
|
169
|
+
target.versionSource = { via: "gradle-graph", paths: [...new Map(hits.flatMap(h => h.paths).map(p => [JSON.stringify(p), p])).values()] };
|
|
170
|
+
filled++;
|
|
171
|
+
}
|
|
172
|
+
return filled;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
module.exports = { recoverVersionlessGradle };
|
|
@@ -129,6 +129,9 @@ module.exports = {
|
|
|
129
129
|
// -e is a groupId regex everywhere else (Maven collector, cleaned-POM rewrite).
|
|
130
130
|
if (deps2Exclude && deps2Exclude.test(d.group)) return;
|
|
131
131
|
const rec = makeDepRecord({ ecosystem: "maven", ecosystemType: "gradle", namespace: d.group, name: d.name, version: d.version, manifestPath, scope: d.scope, isDev: d.isDev });
|
|
132
|
+
if (d.configurations) rec.gradleConfigurations = [...d.configurations];
|
|
133
|
+
if (d.gradleDeclarations) rec.gradleDeclarations = d.gradleDeclarations.map(x => ({ configuration: x.configuration, exclusions: [...x.exclusions] }));
|
|
134
|
+
if (extra.versionUnresolved) rec.versionUnresolved = true;
|
|
132
135
|
if (d.exclusionSets) rec.exclusionSets = d.exclusionSets.map(x => [...x]);
|
|
133
136
|
if (extra.managedOnly) rec.managedOnly = true;
|
|
134
137
|
// A constraint (not a force/strictly) is a FLOOR for transitives: Gradle keeps the
|
|
@@ -152,6 +155,9 @@ module.exports = {
|
|
|
152
155
|
// the first module walked kept scope "test" with isDev false.
|
|
153
156
|
if (rec.isDev === false && existing.isDev !== false) { existing.isDev = false; existing.scope = rec.scope; }
|
|
154
157
|
if (rec.exclusionSets) existing.exclusionSets = (existing.exclusionSets || []).concat(rec.exclusionSets);
|
|
158
|
+
if (rec.gradleConfigurations) existing.gradleConfigurations = [...new Set([...(existing.gradleConfigurations || []), ...rec.gradleConfigurations])];
|
|
159
|
+
if (rec.gradleDeclarations) existing.gradleDeclarations = (existing.gradleDeclarations || []).concat(rec.gradleDeclarations);
|
|
160
|
+
if (rec.versionUnresolved) existing.versionUnresolved = true;
|
|
155
161
|
if (!extra.managedOnly && existing.managedOnly) delete existing.managedOnly;
|
|
156
162
|
};
|
|
157
163
|
|
|
@@ -172,7 +178,16 @@ module.exports = {
|
|
|
172
178
|
const globalExcludes = [];
|
|
173
179
|
for (const s of scripts) {
|
|
174
180
|
const r = parseBuildScript(s.text, { catalog, properties, kotlin: s.kotlin });
|
|
175
|
-
for (const b of r.platformBoms)
|
|
181
|
+
for (const b of r.platformBoms) {
|
|
182
|
+
if (b.inferred && buildFiles.length !== 1) {
|
|
183
|
+
// The current collector merges coordinates across scripts, losing which
|
|
184
|
+
// module owns a versionless occurrence. Do not apply one module's implicit
|
|
185
|
+
// Boot BOM to its neighbours until per-module Gradle resolution exists.
|
|
186
|
+
warnings.push({ type: "dependency-coverage", manifestPath: s.fp, message: "Implicit Spring Boot BOM not applied: multiple Gradle scripts require module-scoped resolution. Use a resolved Gradle lockfile or scan this module separately." });
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (b.group && b.name && !platformBoms.some(x => x.group === b.group && x.name === b.name)) platformBoms.push(b.inferred ? { ...b, manifestPath: s.fp } : b);
|
|
190
|
+
}
|
|
176
191
|
const everything = isConventionPlugin(s.fp);
|
|
177
192
|
for (const c of r.constraints) if (everything || c.global) globalPins.push({ ...c, fp: s.fp });
|
|
178
193
|
for (const e of r.configExcludes) if (everything || e.global) globalExcludes.push({ ...e, fp: s.fp });
|
|
@@ -189,8 +204,10 @@ module.exports = {
|
|
|
189
204
|
const r = parseBuildScript(s.text, { catalog, properties, kotlin: s.kotlin, extraExcludes: globalExcludes.filter(e => e.fp !== fp) });
|
|
190
205
|
const applicable = r.constraints.map(c => ({ ...c, fp })).concat(globalPins.filter(p => p.fp !== fp));
|
|
191
206
|
pins.push(...r.constraints.map(c => ({ ...c, fp })));
|
|
192
|
-
for (const dep of r.deps) addRec({ ...dep, version: pinnedVersion(dep, applicable) }, fp
|
|
193
|
-
|
|
207
|
+
for (const dep of r.deps) addRec({ ...dep, version: pinnedVersion(dep, applicable) }, fp, {
|
|
208
|
+
versionUnresolved: r.unresolved.some(u => u.group === dep.group && u.name === dep.name),
|
|
209
|
+
});
|
|
210
|
+
if (!inBuildSrc(fp)) warnings.push({ type: "no-lockfile", manifestPath: fp, message: `no gradle.lockfile next to ${path.relative(dir, fp) || path.basename(fp)} — versions are resolved best-effort from the build script and version catalog. Without native Gradle resolution or a lockfile, POM-based transitive resolution can choose different versions than Gradle, causing incorrect alerts and omissions. Enable Gradle dependency locking for the configurations you need to audit.` });
|
|
194
211
|
for (const u of r.unresolved) {
|
|
195
212
|
if (pinnedVersion({ group: u.group, name: u.name, version: null }, applicable)) continue; // a constraint supplies it
|
|
196
213
|
warnings.push({ type: "unresolved-versions", manifestPath: fp, message: `could not resolve the version variable for ${u.group}:${u.name} (${u.raw}) — excluded from CVE matching` });
|
package/lib/codecs/index.js
CHANGED
|
@@ -87,7 +87,7 @@ async function detectCodecs(dir, opts = {}) {
|
|
|
87
87
|
while (active < DETECT_CONCURRENCY && queue.length && remaining > 0) {
|
|
88
88
|
const cur = queue.pop();
|
|
89
89
|
active++;
|
|
90
|
-
fs.promises.readdir(cur, { withFileTypes: true }).then(entries => {
|
|
90
|
+
fs.promises.readdir(cur, { withFileTypes: true }).then(async entries => {
|
|
91
91
|
for (const e of entries) {
|
|
92
92
|
if (e.isDirectory()) {
|
|
93
93
|
const child = path.join(cur, e.name);
|
|
@@ -98,7 +98,7 @@ async function detectCodecs(dir, opts = {}) {
|
|
|
98
98
|
const name = e.name;
|
|
99
99
|
for (const m of matchers) {
|
|
100
100
|
if (m.found) continue;
|
|
101
|
-
if (m.exact.has(name) || m.exts.some(ext => name.endsWith(ext))) { m.found = true; remaining--; }
|
|
101
|
+
if (m.exact.has(name) || m.exts.some(ext => name.endsWith(ext)) || (m.codec.detectFile && await m.codec.detectFile(path.join(cur, name)))) { if (!m.found) { m.found = true; remaining--; } }
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}).catch(() => { /* unreadable dir → skip */ }).finally(() => { active--; pump(); });
|
|
@@ -129,14 +129,18 @@ module.exports = {
|
|
|
129
129
|
const pomFiles = await core.findPomFilesAsync(dir, skipDir);
|
|
130
130
|
const store = core.newMetadataStore();
|
|
131
131
|
const propsByPom = {};
|
|
132
|
+
const warnings = [];
|
|
132
133
|
for (const pom of pomFiles) {
|
|
133
|
-
try { await core.parsePom(pom, store); }
|
|
134
|
+
try { await core.parsePom(pom, store); }
|
|
135
|
+
catch (error) { warnings.push({ type: "dependency-coverage", reason: "pom-parse-error", ecosystem: "maven", manifestPath: pom,
|
|
136
|
+
message: `pom.xml parse failed (${pom}): ${error.message}; dependency inventory is incomplete.` }); }
|
|
134
137
|
}
|
|
135
138
|
for (const pom of Object.keys(store.byPath)) {
|
|
136
|
-
try { await core.getAllInheritedProps(pom, store, propsByPom); }
|
|
139
|
+
try { await core.getAllInheritedProps(pom, store, propsByPom); }
|
|
140
|
+
catch (error) { warnings.push({ type: "dependency-coverage", reason: "pom-inheritance-error", ecosystem: "maven", manifestPath: pom,
|
|
141
|
+
message: `pom.xml inheritance failed (${pom}): ${error.message}; dependency inventory is incomplete.` }); }
|
|
137
142
|
}
|
|
138
143
|
const deps = collectResolvedDeps(store, propsByPom, { ignoreTest: opts.ignoreTest, deps2Exclude: opts.deps2Exclude });
|
|
139
|
-
const warnings = [];
|
|
140
144
|
// Embedded binaries: discover Maven coordinates inside committed .jar/.war/.ear
|
|
141
145
|
// archives (vendored libs, fat-jars). Keyed by physical location so they don't
|
|
142
146
|
// merge with declared deps (they get their own report chapter). Default on;
|
|
@@ -149,7 +153,8 @@ module.exports = {
|
|
|
149
153
|
warnings.push(...jarWarnings);
|
|
150
154
|
} catch (e) { warnings.push({ type: "embedded-jar", message: `embedded-jar scan failed: ${e.message}` }); }
|
|
151
155
|
}
|
|
152
|
-
|
|
156
|
+
const parsedPoms = pomFiles.filter(pom => Object.hasOwn(store.byPath, pom));
|
|
157
|
+
return { deps, warnings, parsedManifests: parsedPoms, _maven: { store, propsByPom, pomFiles: parsedPoms } };
|
|
153
158
|
},
|
|
154
159
|
|
|
155
160
|
coordKey(d) { return coordKeyFor("maven", d.namespace || d.groupId, d.name || d.artifactId); },
|
|
@@ -29,17 +29,12 @@ const SCOPE_RANK = { prod: 4, peer: 3, optional: 2, dev: 1, transitive: 0 };
|
|
|
29
29
|
function rankScope(s) { return SCOPE_RANK[s] || 0; }
|
|
30
30
|
|
|
31
31
|
function semverCompare(a, b) {
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
for (let i = 0; i < n; i++) {
|
|
39
|
-
const d = (ax[i] || 0) - (bx[i] || 0);
|
|
40
|
-
if (d !== 0) return d > 0 ? 1 : -1;
|
|
41
|
-
}
|
|
42
|
-
return 0;
|
|
32
|
+
// Use the same SemVer precedence as advisory matching: prereleases are below
|
|
33
|
+
// their release, numeric identifiers compare numerically, builds do not rank.
|
|
34
|
+
// Non-semver inputs are incomparable, never guessed as a newer release.
|
|
35
|
+
const left = String(a ?? ""), right = String(b ?? "");
|
|
36
|
+
if (left.length > 256 || right.length > 256) return null;
|
|
37
|
+
return require("../../osv-db").compareSemver(left, right);
|
|
43
38
|
}
|
|
44
39
|
|
|
45
40
|
function isResolvedVersion(v) {
|
|
@@ -74,13 +74,21 @@ async function parseDirectoryPackagesProps(filePath) {
|
|
|
74
74
|
for (const ig of xml.Project?.ItemGroup || []) {
|
|
75
75
|
for (const pv of ig.PackageVersion || []) {
|
|
76
76
|
const id = pv.$?.Include; const v = pv.$?.Version;
|
|
77
|
-
if (id && v)
|
|
77
|
+
if (id && v) {
|
|
78
|
+
const key = id.toLowerCase(), previous = map[key];
|
|
79
|
+
// Conditions cannot be selected without evaluating MSBuild. Keep all
|
|
80
|
+
// alternatives (including a single conditional pin) and label them.
|
|
81
|
+
map[key] = previous !== undefined || pv.$?.Condition || ig.$?.Condition
|
|
82
|
+
? [...new Set([...(previous === undefined ? [] : Array.isArray(previous) ? previous : [previous]), v])]
|
|
83
|
+
: v;
|
|
84
|
+
}
|
|
78
85
|
}
|
|
79
86
|
}
|
|
80
87
|
return map;
|
|
81
88
|
}
|
|
82
89
|
|
|
83
90
|
async function parseCsproj(filePath, cpm = {}) {
|
|
91
|
+
const warnings = [];
|
|
84
92
|
const xml = await xml2js.parseStringPromise(fs.readFileSync(filePath, "utf8"));
|
|
85
93
|
const deps = [];
|
|
86
94
|
let skipped = 0;
|
|
@@ -94,12 +102,15 @@ async function parseCsproj(filePath, cpm = {}) {
|
|
|
94
102
|
|| pr.$?.Version
|
|
95
103
|
|| (Array.isArray(pr.Version) ? pr.Version[0] : null)
|
|
96
104
|
|| cpm[name.toLowerCase()] || null;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
if (Array.isArray(raw)) warnings.push({ type: "dependency-coverage", reason: "conditional-versions", message: `${name}: all central package version alternatives are scanned; MSBuild conditions were not evaluated.` });
|
|
106
|
+
for (const candidate of Array.isArray(raw) ? raw : [raw]) {
|
|
107
|
+
const version = concreteVersion(candidate);
|
|
108
|
+
if (version) deps.push({ name, version, scope: "prod", isDev: false });
|
|
109
|
+
else skipped++;
|
|
110
|
+
}
|
|
100
111
|
}
|
|
101
112
|
}
|
|
102
|
-
return { manifestPath: filePath, manifestType: "csproj", deps, skipped };
|
|
113
|
+
return { manifestPath: filePath, manifestType: "csproj", deps, skipped, warnings };
|
|
103
114
|
}
|
|
104
115
|
|
|
105
116
|
async function parsePackagesConfig(filePath) {
|
|
@@ -100,7 +100,8 @@ module.exports = {
|
|
|
100
100
|
const fp = path.join(g.dir, cs);
|
|
101
101
|
parsedManifests.push(fp);
|
|
102
102
|
try {
|
|
103
|
-
const { deps, skipped: sk } = await N.parseCsproj(fp, cpm);
|
|
103
|
+
const { deps, skipped: sk, warnings: notices } = await N.parseCsproj(fp, cpm);
|
|
104
|
+
for (const warning of notices || []) warnings.push({ ...warning, manifestPath: fp });
|
|
104
105
|
for (const d of deps) { add(d, fp); pinned++; }
|
|
105
106
|
skipped += sk;
|
|
106
107
|
} catch { /* ignore unparsable csproj */ }
|
package/lib/codecs/pypi/parse.js
CHANGED
|
@@ -78,12 +78,17 @@ function parsePyprojectToml(filePath) {
|
|
|
78
78
|
const data = TOML.parse(fs.readFileSync(filePath, "utf8"));
|
|
79
79
|
const deps = [];
|
|
80
80
|
let skipped = 0;
|
|
81
|
+
const warnings = [];
|
|
81
82
|
const seen = new Set();
|
|
82
83
|
const push = (rawName, version, scope) => {
|
|
83
84
|
const name = pep503(rawName);
|
|
84
85
|
if (!name || name === "python") return;
|
|
85
86
|
const k = `${name}@${version}`;
|
|
86
|
-
if (seen.has(k))
|
|
87
|
+
if (seen.has(k)) {
|
|
88
|
+
if (scope !== "dev") { const prev = deps.find(d => d.name === name && d.version === version); prev.scope = scope; prev.isDev = false; }
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
seen.add(k);
|
|
87
92
|
deps.push({ name, version, scope, isDev: scope === "dev" });
|
|
88
93
|
};
|
|
89
94
|
// PEP 508 specs ("requests==2.31.0") — exact "==" pins only.
|
|
@@ -110,6 +115,32 @@ function parsePyprojectToml(filePath) {
|
|
|
110
115
|
const isDev = /^(dev|test|tests|lint|docs|typing|type|check)$/i.test(group);
|
|
111
116
|
for (const req of (Array.isArray(arr) ? arr : [])) addSpec(req, isDev ? "dev" : "prod");
|
|
112
117
|
}
|
|
118
|
+
// PEP 735 groups may be the entire inventory of a scripts-only project.
|
|
119
|
+
// Resolve includes by normalized name; preserve all variants without selecting
|
|
120
|
+
// a local execution environment. Arbitrary group names are not proof of dev scope.
|
|
121
|
+
const groups = new Map();
|
|
122
|
+
for (const [name, entries] of Object.entries(data["dependency-groups"] || {})) {
|
|
123
|
+
const key = pep503(name);
|
|
124
|
+
if (groups.has(key)) warnings.push({ type: "parse-error", message: `duplicate dependency group: ${name}` });
|
|
125
|
+
groups.set(key, [...(groups.get(key) || []), ...(Array.isArray(entries) ? entries : [])]);
|
|
126
|
+
if (!Array.isArray(entries)) warnings.push({ type: "parse-error", message: `invalid dependency group: ${name}` });
|
|
127
|
+
}
|
|
128
|
+
const expanded = new Set();
|
|
129
|
+
const visit = (name, scope, trail = new Set()) => {
|
|
130
|
+
if (trail.has(name) || !groups.has(name)) {
|
|
131
|
+
warnings.push({ type: "parse-error", message: `cyclic or missing dependency group: ${name}` }); return;
|
|
132
|
+
}
|
|
133
|
+
const key = `${name}:${scope}`;
|
|
134
|
+
if (expanded.has(key)) return;
|
|
135
|
+
expanded.add(key);
|
|
136
|
+
const next = new Set([...trail, name]);
|
|
137
|
+
for (const entry of groups.get(name)) {
|
|
138
|
+
if (typeof entry === "string") addSpec(entry, scope);
|
|
139
|
+
else if (entry && Object.keys(entry).length === 1 && typeof entry["include-group"] === "string") visit(pep503(entry["include-group"]), scope, next);
|
|
140
|
+
else warnings.push({ type: "parse-error", message: `unsupported entry in dependency group: ${name}` });
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
for (const name of groups.keys()) visit(name, /^(dev|test|tests|lint|docs|typing|type|check)$/.test(name) ? "dev" : "prod");
|
|
113
144
|
// Poetry [tool.poetry]
|
|
114
145
|
const poetry = (data.tool && data.tool.poetry) || {};
|
|
115
146
|
for (const [name, v] of Object.entries(poetry.dependencies || {})) addPoetry(name, v, "prod");
|
|
@@ -117,7 +148,7 @@ function parsePyprojectToml(filePath) {
|
|
|
117
148
|
for (const grp of Object.values(poetry.group || {})) {
|
|
118
149
|
for (const [name, v] of Object.entries((grp && grp.dependencies) || {})) addPoetry(name, v, "dev");
|
|
119
150
|
}
|
|
120
|
-
return { manifestPath: filePath, manifestType: "pyproject.toml", deps, skipped };
|
|
151
|
+
return { manifestPath: filePath, manifestType: "pyproject.toml", deps, skipped, warnings };
|
|
121
152
|
}
|
|
122
153
|
|
|
123
154
|
// Walk a requirements.txt graph, following -r/--requirement (deps) and
|
|
@@ -132,8 +163,9 @@ function collectReqGraph(filePath, seen, kind, acc, root) {
|
|
|
132
163
|
if (relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) {
|
|
133
164
|
acc.missing.push(`${real} (outside scan root; ignored)`); return;
|
|
134
165
|
}
|
|
135
|
-
|
|
136
|
-
seen.
|
|
166
|
+
const visitKey = `${kind}:${resolved}`;
|
|
167
|
+
if (seen.has(visitKey)) return; // same file may be both constraint and requirement
|
|
168
|
+
seen.add(visitKey);
|
|
137
169
|
if (seen.size > 200) return; // sanity bound
|
|
138
170
|
let lines;
|
|
139
171
|
try { lines = fs.readFileSync(resolved, "utf8").split(/\r?\n/); }
|
|
@@ -156,29 +188,38 @@ function collectReqGraph(filePath, seen, kind, acc, root) {
|
|
|
156
188
|
const { name, spec } = splitPep508(line.split(/\s+--/)[0].trim());
|
|
157
189
|
if (!name) continue;
|
|
158
190
|
const n = pep503(name);
|
|
159
|
-
if (kind === "constraint")
|
|
191
|
+
if (kind === "constraint") {
|
|
192
|
+
if (!acc.constraints.has(n)) acc.constraints.set(n, []);
|
|
193
|
+
acc.constraints.get(n).push(spec);
|
|
194
|
+
if (line.includes(";")) acc.conditional.add(n);
|
|
195
|
+
}
|
|
160
196
|
else acc.reqs.push({ name: n, spec });
|
|
161
197
|
}
|
|
162
198
|
}
|
|
163
199
|
|
|
164
200
|
function parseRequirementsTxt(filePath, scanRoot = path.dirname(filePath)) {
|
|
165
|
-
const acc = { reqs: [], constraints: new Map(), missing: [] };
|
|
201
|
+
const acc = { reqs: [], constraints: new Map(), missing: [], conditional: new Set() };
|
|
166
202
|
collectReqGraph(filePath, new Set(), "req", acc, fs.realpathSync(scanRoot));
|
|
167
203
|
const deps = [];
|
|
168
204
|
let skipped = 0;
|
|
169
205
|
const seen = new Set();
|
|
206
|
+
const warnings = [];
|
|
207
|
+
const warned = new Set();
|
|
170
208
|
for (const r of acc.reqs) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
209
|
+
const constraints = acc.constraints.get(r.name) || [];
|
|
210
|
+
const versions = isPinned(r.spec) ? [stripOp(r.spec)] : constraints.filter(isPinned).map(stripOp);
|
|
211
|
+
if (!versions.length) { skipped++; continue; }
|
|
212
|
+
if (!isPinned(r.spec) && (acc.conditional.has(r.name) || constraints.length > 1) && !warned.has(r.name)) {
|
|
213
|
+
warned.add(r.name);
|
|
214
|
+
warnings.push({ type: "dependency-coverage", reason: "conditional-versions", message: `${r.name}: all pinned constraint alternatives are scanned; environment markers and constraint intersection were not resolved.` });
|
|
215
|
+
}
|
|
216
|
+
for (const version of new Set(versions)) {
|
|
217
|
+
const k = `${r.name}@${version}`;
|
|
218
|
+
if (seen.has(k)) continue; seen.add(k);
|
|
219
|
+
deps.push({ name: r.name, version, scope: "prod", isDev: false });
|
|
175
220
|
}
|
|
176
|
-
if (!version) { skipped++; continue; }
|
|
177
|
-
const k = `${r.name}@${version}`;
|
|
178
|
-
if (seen.has(k)) continue; seen.add(k);
|
|
179
|
-
deps.push({ name: r.name, version, scope: "prod", isDev: false });
|
|
180
221
|
}
|
|
181
|
-
return { manifestPath: filePath, manifestType: "requirements.txt", deps, skipped, missing: acc.missing };
|
|
222
|
+
return { manifestPath: filePath, manifestType: "requirements.txt", deps, skipped, missing: acc.missing, warnings };
|
|
182
223
|
}
|
|
183
224
|
|
|
184
225
|
module.exports = { pep503, isConcrete, splitPep508, parsePoetryLock, parseUvLock, parsePdmLock, parsePipfileLock, parsePyprojectToml, parseRequirementsTxt };
|
package/lib/codecs/pypi.codec.js
CHANGED
|
@@ -97,6 +97,7 @@ module.exports = {
|
|
|
97
97
|
const r = P.parsePyprojectToml(fp);
|
|
98
98
|
for (const d of r.deps) add(d, fp);
|
|
99
99
|
skipped += r.skipped;
|
|
100
|
+
for (const warning of r.warnings || []) warnings.push({ ...warning, manifestPath: fp });
|
|
100
101
|
if (r.deps.length || r.skipped) sources.push("pyproject.toml");
|
|
101
102
|
} catch (e) { warnings.push({ type: "parse-error", manifestPath: fp, message: `pyproject.toml parse failed: ${e.message}` }); }
|
|
102
103
|
}
|
|
@@ -108,6 +109,7 @@ module.exports = {
|
|
|
108
109
|
const r = P.parseRequirementsTxt(fp, dir);
|
|
109
110
|
for (const d of r.deps) add(devFile ? { ...d, isDev: true, scope: "dev" } : d, fp);
|
|
110
111
|
skipped += r.skipped;
|
|
112
|
+
for (const warning of r.warnings || []) warnings.push({ ...warning, manifestPath: fp });
|
|
111
113
|
sources.push(rf);
|
|
112
114
|
for (const miss of (r.missing || [])) warnings.push({ type: "missing-include", manifestPath: fp, message: `referenced requirements file not found: ${miss}` });
|
|
113
115
|
} catch (e) { warnings.push({ type: "parse-error", manifestPath: fp, message: `${rf} parse failed: ${e.message}` }); }
|