vigievuln 1.1.3 → 1.2.1
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 +26 -0
- package/README.md +50 -127
- package/completions/vigievuln.bash +1 -1
- package/completions/vigievuln.zsh +1 -0
- package/lib/advisory-compression.js +25 -0
- package/lib/advisory-fixes.js +21 -0
- package/lib/advisory-freshness.js +2 -0
- package/lib/advisory-store-sqlite.js +156 -0
- package/lib/advisory-store.js +484 -0
- package/lib/airgap-project.js +117 -0
- package/lib/application-plugins/runner.js +22 -13
- package/lib/application-plugins/wordpress.js +4 -3
- package/lib/application-providers/live-snapshot.js +1 -12
- package/lib/application-providers/snapshot-cache.js +27 -0
- package/lib/application-providers/wordfence-client.js +3 -3
- package/lib/attribution.js +2 -2
- package/lib/cache-archive-sqlite.js +215 -0
- package/lib/cache-archive.js +350 -26
- package/lib/cache-db.js +142 -0
- package/lib/cache-directory.js +18 -74
- package/lib/cache-policy.js +25 -0
- package/lib/cache-repository.js +48 -0
- package/lib/cache-startup.js +54 -0
- package/lib/certfr.js +9 -9
- package/lib/certs/analyze.js +49 -13
- package/lib/cli-command-routing.js +29 -6
- package/lib/cli-groups.js +32 -3
- package/lib/cli-project-commands.js +26 -5
- package/lib/cli-setup.js +300 -0
- package/lib/codecs/binary/pe-metadata.js +105 -0
- package/lib/codecs/binary/scan.js +39 -21
- package/lib/codecs/binary.codec.js +10 -5
- package/lib/codecs/composer/registry.js +8 -6
- package/lib/codecs/go/parse.js +17 -13
- package/lib/codecs/go/registry.js +7 -5
- package/lib/codecs/go.codec.js +28 -6
- package/lib/codecs/maven.codec.js +81 -11
- package/lib/codecs/npm/collect.js +18 -16
- package/lib/codecs/npm/parse.js +12 -5
- package/lib/codecs/npm/registry.js +40 -11
- package/lib/codecs/nuget/parse.js +16 -5
- package/lib/codecs/nuget/registry.js +8 -6
- package/lib/codecs/nuget.codec.js +2 -1
- package/lib/codecs/pypi/parse.js +56 -15
- package/lib/codecs/pypi/registry.js +8 -6
- package/lib/codecs/pypi.codec.js +2 -0
- package/lib/codecs/ruby/registry.js +7 -5
- package/lib/compression-dictionary.js +5 -0
- package/lib/coverage-diagnostics.js +26 -0
- package/lib/csaf-export.js +33 -5
- package/lib/cve-download.js +157 -41
- package/lib/cve-legacy-ranges.js +59 -0
- package/lib/cve-match.js +82 -13
- package/lib/cve-npm-proxy.js +29 -0
- package/lib/cve-report.js +142 -55
- package/lib/cve-version-verdict.js +77 -0
- package/lib/deps-descriptor.js +8 -3
- package/lib/diff.js +0 -0
- package/lib/epss.js +13 -8
- package/lib/euvd.js +32 -8
- package/lib/gcve-feed.js +103 -0
- package/lib/gcve-index.js +181 -0
- package/lib/gcve.js +1 -1
- package/lib/github-publisher-maven.js +40 -0
- package/lib/hash-id.js +5 -5
- package/lib/i18n.js +32 -8
- package/lib/json-cache.js +18 -0
- package/lib/json-export.js +66 -4
- package/lib/kev.js +7 -8
- package/lib/line-stream.js +23 -0
- package/lib/maven-airgap.js +80 -0
- package/lib/maven-cache.js +21 -0
- package/lib/maven-license.js +2 -1
- package/lib/maven-presence.js +2 -2
- package/lib/maven-reactor.js +23 -14
- package/lib/merge-sources.js +25 -18
- package/lib/native-advisories.js +268 -0
- package/lib/nvd-bulk.js +145 -0
- package/lib/nvd-package-ranges.js +109 -0
- package/lib/nvd.js +42 -16
- package/lib/osv-db.js +253 -59
- package/lib/osv-legacy.js +57 -0
- package/lib/osv.js +241 -170
- package/lib/outdated.js +11 -12
- package/lib/package-metadata.js +141 -0
- package/lib/package-versions.js +52 -0
- package/lib/packagist-audit.js +6 -6
- package/lib/provenance.js +73 -19
- package/lib/providers/common.js +11 -1
- package/lib/providers/gcve.js +17 -0
- package/lib/providers/github.js +1 -0
- package/lib/providers/index.js +33 -19
- package/lib/providers/vigievuln.js +7 -0
- package/lib/proxy-cache.js +1 -1
- package/lib/proxy-scope.js +59 -0
- package/lib/resource-cache/engine.js +25 -5
- package/lib/resource-cache/sqlite-store.js +95 -0
- package/lib/resource-cache/validate.js +5 -0
- package/lib/retire.js +24 -24
- package/lib/ruby-version.js +36 -0
- package/lib/sarif-export.js +1 -1
- package/lib/sbom-export.js +17 -7
- package/lib/snyk.js +32 -20
- package/lib/source-profile.js +67 -0
- package/lib/sqlite-driver.js +60 -0
- package/lib/suppress.js +34 -13
- package/lib/transitive.js +69 -34
- package/lib/unmanaged.js +2 -1
- package/lib/vigievuln-advisories.js +47 -0
- package/lib/xlsx-export.js +8 -2
- package/package.json +7 -6
- package/vigievuln.js +433 -136
|
@@ -18,10 +18,10 @@ const { withPublic, authHeaderFor, normalise } = require("../../registries");
|
|
|
18
18
|
|
|
19
19
|
const CACHE_DIR = path.join(require("../../cache-directory").getCacheDir());
|
|
20
20
|
const CACHE_PATH = path.join(CACHE_DIR, "go-proxy-cache.json");
|
|
21
|
-
const CACHE_MAX_AGE_MS =
|
|
21
|
+
const CACHE_MAX_AGE_MS = 4 * 3600 * 1000;
|
|
22
22
|
|
|
23
|
-
function loadCache() {
|
|
24
|
-
function saveCache(d) {
|
|
23
|
+
function loadCache() { return require('../../json-cache').load(CACHE_DIR,'go-proxy',{ entries: {}, meta: {} }); }
|
|
24
|
+
function saveCache(d) { require('../../json-cache').save(CACHE_DIR,'go-proxy',d); }
|
|
25
25
|
|
|
26
26
|
// proxy.golang.org case-encoding: uppercase letters → "!" + lowercase.
|
|
27
27
|
function escapeModule(mod) {
|
|
@@ -62,7 +62,8 @@ async function checkGoRegistryDeps(deps, opts = {}) {
|
|
|
62
62
|
const result = { deprecated: [], outdated: [], licensed: [], private: [] };
|
|
63
63
|
if (!targets.length || !allLibs) return result;
|
|
64
64
|
const cache = loadCache();
|
|
65
|
-
const fresh = (offline || !require("../../providers").hasHostedProxy()) && cache.meta?.fetchedAt && (
|
|
65
|
+
const fresh = (offline || !require("../../providers").hasHostedProxy()) && cache.meta?.fetchedAt && require('../../cache-policy').fresh(cache.meta.fetchedAt, CACHE_MAX_AGE_MS);
|
|
66
|
+
const previous = !fresh && !offline ? {entries:cache.entries, fetchedAt:cache.meta?.fetchedAt} : null;
|
|
66
67
|
if (!fresh && !offline) cache.entries = {};
|
|
67
68
|
const limit = pLimit(concurrency);
|
|
68
69
|
await Promise.all(targets.map(t => limit(async () => {
|
|
@@ -85,7 +86,8 @@ async function checkGoRegistryDeps(deps, opts = {}) {
|
|
|
85
86
|
// fresh to the next ONLINE run and skip its refetch.
|
|
86
87
|
if (!offline) {
|
|
87
88
|
if (!fresh) cache.meta = { fetchedAt: Date.now() };
|
|
88
|
-
|
|
89
|
+
require('../../cache-policy').preserveEntries(cache, previous);
|
|
90
|
+
saveCache(cache);
|
|
89
91
|
}
|
|
90
92
|
return result;
|
|
91
93
|
}
|
package/lib/codecs/go.codec.js
CHANGED
|
@@ -55,18 +55,35 @@ module.exports = {
|
|
|
55
55
|
for (const g of findGoDirs(dir, dirFilter(dir, opts))) {
|
|
56
56
|
let modHadDeps = false;
|
|
57
57
|
const selectedHere = new Set();
|
|
58
|
-
//
|
|
59
|
-
let
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
58
|
+
// Honor the explicit workspace switch before looking for the nearest file.
|
|
59
|
+
let workspacePath = null;
|
|
60
|
+
if (process.env.GOWORK !== "off") {
|
|
61
|
+
if (process.env.GOWORK) workspacePath = path.resolve(process.env.GOWORK);
|
|
62
|
+
else for (let cur = g.dir; ; cur = path.dirname(cur)) {
|
|
63
|
+
const fp = path.join(cur, "go.work");
|
|
64
|
+
if (fs.existsSync(fp)) { workspacePath = fp; break; }
|
|
65
|
+
if (path.dirname(cur) === cur) break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const workspace = !!workspacePath;
|
|
69
|
+
let workspaceReplaces = [];
|
|
70
|
+
if (workspace) {
|
|
71
|
+
try {
|
|
72
|
+
workspaceReplaces = G.parseGoModFile(workspacePath, { replacementsOnly: true });
|
|
73
|
+
if (!parsedManifests.includes(workspacePath)) parsedManifests.push(workspacePath);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
warnings.push({ type: "parse-error", manifestPath: workspacePath, message: `go.work could not be read: ${error.message}` });
|
|
76
|
+
}
|
|
77
|
+
// Replaces alone cannot establish MVS across all workspace modules.
|
|
78
|
+
warnings.push({ type: "go-coverage", ecosystem: "go", reason: "workspace-graph-not-resolved", manifestPath: workspacePath,
|
|
79
|
+
message: "Go workspace graph was not resolved: recognized go.work replacements are applied, but workspace module selection and transitive versions remain uncertain. Inventory may be incomplete or include unselected versions." });
|
|
63
80
|
}
|
|
64
81
|
let goMinor = null;
|
|
65
82
|
if (g.names.has("go.mod")) {
|
|
66
83
|
const fp = path.join(g.dir, "go.mod");
|
|
67
84
|
parsedManifests.push(fp);
|
|
68
85
|
try {
|
|
69
|
-
const r = G.parseGoModFile(fp);
|
|
86
|
+
const r = G.parseGoModFile(fp, { workspaceReplaces });
|
|
70
87
|
const gm = /^1\.(\d+)/.exec(r.goVersion || "");
|
|
71
88
|
goMinor = gm ? Number(gm[1]) : null;
|
|
72
89
|
for (const d of r.dropped) {
|
|
@@ -88,6 +105,11 @@ module.exports = {
|
|
|
88
105
|
// go.sum graph for anything go.mod didn't select — skipping it silently
|
|
89
106
|
// dropped every transitive dep of a pre-1.17 module.
|
|
90
107
|
const needSum = !modHadDeps || goMinor == null || goMinor < 17;
|
|
108
|
+
if (needSum && (goMinor == null || goMinor < 17 || g.names.has('go.sum'))) {
|
|
109
|
+
warnings.push({ type: 'go-coverage', ecosystem: 'go', reason: 'module-graph-not-resolved',
|
|
110
|
+
manifestPath: path.join(g.dir, g.names.has('go.mod') ? 'go.mod' : 'go.sum'),
|
|
111
|
+
message: 'Go module graph was not resolved: this manifest does not establish the full pruned graph, and go.sum records checksums rather than selected build dependencies. Transitive inventory may be incomplete or include historical versions.' });
|
|
112
|
+
}
|
|
91
113
|
if (needSum && g.names.has("go.sum")) {
|
|
92
114
|
const fp = path.join(g.dir, "go.sum");
|
|
93
115
|
parsedManifests.push(fp);
|
|
@@ -18,8 +18,19 @@ const cveIndexScanner = {
|
|
|
18
18
|
id: "cve-index",
|
|
19
19
|
kind: "cve", // résultats → chapitre CVE (mergés avec OSV)
|
|
20
20
|
async scan(deps, opts = {}) {
|
|
21
|
-
const { ensureCveIndex, newIndex, addToIndex } = require("../cve-download");
|
|
21
|
+
const { ensureCveIndex, loadCveIndex, newIndex, addToIndex, isCurrentCveIndex } = require("../cve-download");
|
|
22
|
+
const store = require("../advisory-store").openAdvisoryStore();
|
|
23
|
+
try {
|
|
24
|
+
const { matchCveStore } = require("../native-advisories");
|
|
25
|
+
const hasStored = () => !!(store.getSourceCoverage('cveproject','*') || store.getSourceCoverage('cveproject-legacy','*'));
|
|
26
|
+
const fallback = err => {
|
|
27
|
+
const idx = loadCveIndex();
|
|
28
|
+
if (!idx && !hasStored()) throw err;
|
|
29
|
+
const result = matchCveStore(deps, store, idx);
|
|
30
|
+
return {matches:result.matches,meta:{cveDataDate:idx?.meta?.builtAt || null,incomplete:true,refreshError:err.message,identityUncertain:result.identityUncertain || (!!idx && !isCurrentCveIndex(idx)),uncertainCandidates:result.uncertainCandidates,oldProjection:!!idx && !isCurrentCveIndex(idx)}};
|
|
31
|
+
};
|
|
22
32
|
if (opts.hostedProxy && !opts.offline && !opts.cveOffline) {
|
|
33
|
+
try {
|
|
23
34
|
const keys = new Set();
|
|
24
35
|
for (const dep of deps.values()) {
|
|
25
36
|
if ((dep.ecosystem && dep.ecosystem !== "maven") || dep.provenance === "binary") continue;
|
|
@@ -27,23 +38,77 @@ const cveIndexScanner = {
|
|
|
27
38
|
if (group && artifact) keys.add("p:" + group + ":" + artifact);
|
|
28
39
|
if (artifact) keys.add("a:" + artifact);
|
|
29
40
|
}
|
|
30
|
-
const idx = newIndex(), all = [...keys], seen = new Set();
|
|
41
|
+
const idx = newIndex(), all = [...keys], seen = new Set(), collected = [];
|
|
42
|
+
let oldestFetchedAt = Infinity, oldestBuiltAt = Infinity, timestampsKnown = true, builtAtKnown = true, staleResponse = false;
|
|
31
43
|
for (let i = 0; i < all.length; i += 200) {
|
|
32
|
-
const res = await require("../providers").getResource("github", "cve-maven", { keys: all.slice(i, i + 200) });
|
|
44
|
+
const res = await require("../providers").getResource("github", "cve-maven", { keys: all.slice(i, i + 200) }, { forceRefresh:true });
|
|
33
45
|
if (!res.ok) throw new Error(`hosted CVE index unavailable (HTTP ${res.status})`);
|
|
34
46
|
const data = await res.json();
|
|
35
47
|
if (!Array.isArray(data.cves)) throw new Error("invalid hosted CVE index response");
|
|
48
|
+
const stamp = Date.parse(res.headers?.get('x-fad-proxy-fetched-at') || '');
|
|
49
|
+
if (!Number.isFinite(stamp) || stamp <= 0 || stamp > Date.now()+300000) timestampsKnown = false;
|
|
50
|
+
else oldestFetchedAt = Math.min(oldestFetchedAt, stamp);
|
|
51
|
+
if (res.headers?.get('x-fad-proxy') === 'stale') staleResponse = true;
|
|
52
|
+
const built = Date.parse(data.builtAt || '');
|
|
53
|
+
if (!Number.isFinite(built) || built <= 0 || built > Date.now()+300000) builtAtKnown = false;
|
|
54
|
+
else oldestBuiltAt = Math.min(oldestBuiltAt, built);
|
|
36
55
|
idx.meta.builtAt = data.builtAt;
|
|
37
|
-
for (const cve of data.cves) if (!seen.has(cve.id)) { seen.add(cve.id); addToIndex(idx, cve); }
|
|
56
|
+
for (const cve of data.cves) if (!seen.has(cve.id)) { seen.add(cve.id); addToIndex(idx, cve); collected.push(cve); }
|
|
38
57
|
}
|
|
39
|
-
|
|
58
|
+
const fetchedAt = timestampsKnown && Number.isFinite(oldestFetchedAt) ? oldestFetchedAt : null;
|
|
59
|
+
const provenance = {transport:'proxy'};
|
|
60
|
+
const {projectedCveEnvelope} = require('../native-advisories');
|
|
61
|
+
if (fetchedAt) {
|
|
62
|
+
for (let i=0;i<collected.length;i+=100) store.commit({records:collected.slice(i,i+100).map(cve=>projectedCveEnvelope(cve,fetchedAt,provenance))});
|
|
63
|
+
store.commit({coverages:[{source:'cveproject-legacy',ecosystem:'*',fetchedAt,complete:false,provenance}]});
|
|
64
|
+
}
|
|
65
|
+
// A proxy projection cannot prove that a rejected CVE was reinstated.
|
|
66
|
+
// Preserve the native tombstone regardless of the proxy corpus date;
|
|
67
|
+
// only a newer native published revision may replace it in the store.
|
|
68
|
+
let identityUncertain = false;
|
|
69
|
+
const uncertainCandidates=[];
|
|
70
|
+
let matches = matchDepsAgainstCves(deps,idx,{onUncertain:candidate=>{identityUncertain=true;uncertainCandidates.push(candidate);}}), conflict = false;
|
|
71
|
+
const {isWithdrawn} = require('../advisory-store');
|
|
72
|
+
matches = matches.filter(m => {
|
|
73
|
+
const native = store.getRecord('cveproject',m.cve.id);
|
|
74
|
+
if (native && isWithdrawn(native)) {conflict=true; return false;}
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
// Other native revisions may supersede a complete proxy batch only
|
|
78
|
+
// when their revision is demonstrably newer than its corpus date.
|
|
79
|
+
if (builtAtKnown && Number.isFinite(oldestBuiltAt)) {
|
|
80
|
+
const nativeResult=matchCveStore(deps,store,null), nativeMatches=nativeResult.matches;
|
|
81
|
+
identityUncertain ||= nativeResult.identityUncertain;
|
|
82
|
+
uncertainCandidates.push(...nativeResult.uncertainCandidates);
|
|
83
|
+
const newer = id => {const r=store.getRecord('cveproject',id);const at=Date.parse(r?.document?.cveMetadata?.dateUpdated || '');return r && Number.isFinite(at) && at > oldestBuiltAt ? r : null;};
|
|
84
|
+
matches=matches.filter(m=>{const r=newer(m.cve.id);if(r){conflict=true;return false;}return true;});
|
|
85
|
+
for (const m of nativeMatches) if(newer(m.cve.id)) {conflict=true;matches.push(m);}
|
|
86
|
+
}
|
|
87
|
+
return { matches, meta: { cveDataDate: builtAtKnown && Number.isFinite(oldestBuiltAt) ? new Date(oldestBuiltAt).toISOString() : null, incomplete: true,
|
|
88
|
+
stale: staleResponse || (fetchedAt != null && opts.queryTtlMs != null && Date.now()-fetchedAt >= opts.queryTtlMs), timestampUnknown: !fetchedAt, conflict, identityUncertain, uncertainCandidates } };
|
|
89
|
+
} catch (err) { return fallback(err); }
|
|
40
90
|
}
|
|
41
|
-
|
|
91
|
+
let idx;
|
|
92
|
+
if ((opts.offline || opts.cveOffline) && !loadCveIndex() && (store.getSourceCoverage('cveproject','*') || store.getSourceCoverage('cveproject-legacy','*'))) idx = null;
|
|
93
|
+
else try { idx = await ensureCveIndex({
|
|
42
94
|
force: !!opts.cveRefresh && !opts.offline,
|
|
43
95
|
offline: !!opts.cveOffline || !!opts.offline,
|
|
44
96
|
verbose: opts.verbose,
|
|
97
|
+
ttlMs: opts.queryTtlMs,
|
|
98
|
+
}); } catch (err) { return fallback(err); }
|
|
99
|
+
const result = matchCveStore(deps, store, idx);
|
|
100
|
+
const oldProjection = !!idx && !isCurrentCveIndex(idx);
|
|
101
|
+
// A complete current Maven index is itself a complete projection of the
|
|
102
|
+
// source, even if the separate native-record journal is only partial.
|
|
103
|
+
const snapshot = store.db.prepare("SELECT complete,stale FROM cache_snapshots WHERE namespace='cve_lookup'").get();
|
|
104
|
+
const scopedBucket=store.db.prepare("SELECT 1 FROM cache_entries WHERE namespace='airgap-cve-index' AND key=? AND stale=0");
|
|
105
|
+
const scopedComplete=!!idx && [...deps.values()].filter(d=>(!d.ecosystem||d.ecosystem==='maven') && d.provenance!=='binary' && d.scope!=='parent').every(d=>{
|
|
106
|
+
const artifact=String(d.artifactId||d.name||'').toLowerCase();
|
|
107
|
+
return scopedBucket.get(`p:${String(d.groupId||d.namespace||'').toLowerCase()}:${artifact}`) && scopedBucket.get(`a:${artifact}`);
|
|
45
108
|
});
|
|
46
|
-
|
|
109
|
+
const completeIndex = !!idx && !oldProjection && snapshot?.stale === 0 && (snapshot.complete === 1 || scopedComplete);
|
|
110
|
+
return { matches: result.matches, meta: { cveDataDate: idx?.meta?.builtAt || (result.coverage?.fetchedAt ? new Date(result.coverage.fetchedAt).toISOString() : null), incomplete: !(result.coverage?.complete || completeIndex), identityUncertain:result.identityUncertain || oldProjection, uncertainCandidates:result.uncertainCandidates,oldProjection } };
|
|
111
|
+
} finally { store.close(); }
|
|
47
112
|
},
|
|
48
113
|
};
|
|
49
114
|
|
|
@@ -64,14 +129,18 @@ module.exports = {
|
|
|
64
129
|
const pomFiles = await core.findPomFilesAsync(dir, skipDir);
|
|
65
130
|
const store = core.newMetadataStore();
|
|
66
131
|
const propsByPom = {};
|
|
132
|
+
const warnings = [];
|
|
67
133
|
for (const pom of pomFiles) {
|
|
68
|
-
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.` }); }
|
|
69
137
|
}
|
|
70
138
|
for (const pom of Object.keys(store.byPath)) {
|
|
71
|
-
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.` }); }
|
|
72
142
|
}
|
|
73
143
|
const deps = collectResolvedDeps(store, propsByPom, { ignoreTest: opts.ignoreTest, deps2Exclude: opts.deps2Exclude });
|
|
74
|
-
const warnings = [];
|
|
75
144
|
// Embedded binaries: discover Maven coordinates inside committed .jar/.war/.ear
|
|
76
145
|
// archives (vendored libs, fat-jars). Keyed by physical location so they don't
|
|
77
146
|
// merge with declared deps (they get their own report chapter). Default on;
|
|
@@ -84,7 +153,8 @@ module.exports = {
|
|
|
84
153
|
warnings.push(...jarWarnings);
|
|
85
154
|
} catch (e) { warnings.push({ type: "embedded-jar", message: `embedded-jar scan failed: ${e.message}` }); }
|
|
86
155
|
}
|
|
87
|
-
|
|
156
|
+
const parsedPoms = pomFiles.filter(pom => Object.hasOwn(store.byPath, pom));
|
|
157
|
+
return { deps, warnings, parsedManifests: parsedPoms, _maven: { store, propsByPom, pomFiles: parsedPoms } };
|
|
88
158
|
},
|
|
89
159
|
|
|
90
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) {
|
|
@@ -52,14 +47,13 @@ function isResolvedVersion(v) {
|
|
|
52
47
|
}
|
|
53
48
|
|
|
54
49
|
/**
|
|
55
|
-
* --ignore-test: what a production install would NOT ship.
|
|
50
|
+
* --ignore-test: what a production install would NOT ship. Declared-dev
|
|
56
51
|
* scopes as before, plus a transitive reachable only through dev deps (isDev). A
|
|
57
52
|
* declared devDependency that a prod dep ALSO pulls in (isDev === false) ships, so it
|
|
58
53
|
* stays.
|
|
59
54
|
*/
|
|
60
55
|
function isDevOnly(scope, isDev) {
|
|
61
56
|
if (isDev) return true;
|
|
62
|
-
if (scope === "optional") return true;
|
|
63
57
|
return scope === "dev" && isDev !== false;
|
|
64
58
|
}
|
|
65
59
|
|
|
@@ -179,7 +173,9 @@ function upsert(out, dep, manifestPath, lockType, relations) {
|
|
|
179
173
|
// one name are routinely classified differently (ms@2.1.3 under a prod dep,
|
|
180
174
|
// ms@1.0.0 only under jest). "dev" marks a dev-only occurrence; attribution reads a
|
|
181
175
|
// version as dev only when EVERY occurrence of it is.
|
|
182
|
-
|
|
176
|
+
// A dev declaration can also be reachable through a production optional
|
|
177
|
+
// path (npm devOptional). Preserve that production evidence per version.
|
|
178
|
+
const scopeToken = dep.isDev ? "dev" : (record.scope === 'dev' ? 'prod' : (record.scope || "prod"));
|
|
183
179
|
record.versionScopes = {};
|
|
184
180
|
for (const v of record.versions) record.versionScopes[v] = [scopeToken];
|
|
185
181
|
// Union evidence per version before the coordinate-wide scope/depth merge.
|
|
@@ -301,7 +297,7 @@ function collectNpmDeps(rootDir, opts = {}) {
|
|
|
301
297
|
if (pj && !hasLock) {
|
|
302
298
|
let pinned = 0, ranges = 0;
|
|
303
299
|
for (const d of pj.deps) {
|
|
304
|
-
if (ignoreTest &&
|
|
300
|
+
if (ignoreTest && d.isDev) continue;
|
|
305
301
|
if (deps2Exclude && deps2Exclude.test(d.name)) continue;
|
|
306
302
|
if (isResolvedVersion(d.version)) {
|
|
307
303
|
upsert(out, { name: d.name, version: d.version, scope: d.scope || "prod", isDev: !!d.isDev }, group.packageJson, "package-json-nolock", ["direct"]);
|
|
@@ -331,7 +327,11 @@ function collectNpmDeps(rootDir, opts = {}) {
|
|
|
331
327
|
|
|
332
328
|
// Used only as a source of scope info — never emits deps on its own. Keyed by
|
|
333
329
|
// the DECLARED name, which for an alias is the alias, not the real package.
|
|
334
|
-
const directScopes = pj ? new Map(
|
|
330
|
+
const directScopes = pj ? new Map() : null;
|
|
331
|
+
if (pj) for (const d of pj.deps) {
|
|
332
|
+
const name=d.alias || d.name, previous=directScopes.get(name);
|
|
333
|
+
if (!previous || rankScope(d.scope)>rankScope(previous)) directScopes.set(name,d.scope);
|
|
334
|
+
}
|
|
335
335
|
|
|
336
336
|
if (pl) {
|
|
337
337
|
parsedCount++;
|
|
@@ -408,6 +408,8 @@ function webjarToNpm(dep) {
|
|
|
408
408
|
if (g !== "org.webjars" && !g.startsWith("org.webjars.")) return null;
|
|
409
409
|
let name = dep.artifactId || "";
|
|
410
410
|
if (!name) return null;
|
|
411
|
+
// The Java locator is WebJars infrastructure, not a bundled JS library.
|
|
412
|
+
if (g === "org.webjars" && /^webjars-locator(?:-|$)/.test(name)) return null;
|
|
411
413
|
if (name.includes("__")) name = "@" + name.replace(/__/g, "/");
|
|
412
414
|
return { name, version: dep.version || null };
|
|
413
415
|
}
|
package/lib/codecs/npm/parse.js
CHANGED
|
@@ -272,7 +272,7 @@ function parsePackageJson(filePath) {
|
|
|
272
272
|
const push = (obj, scope) => {
|
|
273
273
|
for (const [name, version] of Object.entries(obj || {})) {
|
|
274
274
|
if (isWorkspaceVersion(version)) continue;
|
|
275
|
-
const isDev = scope === "dev"
|
|
275
|
+
const isDev = scope === "dev";
|
|
276
276
|
// "lodash-legacy": "npm:lodash@4.17.20" → lodash @ 4.17.20 (alias kept).
|
|
277
277
|
const al = parseNpmAlias(version);
|
|
278
278
|
if (al) deps.push({ name: al.name, alias: name, version: al.range, scope, isDev, depth: 0 });
|
|
@@ -346,15 +346,16 @@ function parsePackageLock(filePath) {
|
|
|
346
346
|
// node_modules/, so depth===0 alone doesn't mean "direct". An entry
|
|
347
347
|
// is direct iff it appears in the root project's dependency lists.
|
|
348
348
|
let scope = "prod";
|
|
349
|
-
if (entry.dev
|
|
349
|
+
if (entry.dev && !entry.devOptional) scope = "dev";
|
|
350
|
+
else if (entry.devOptional) scope = "optional";
|
|
350
351
|
else if (entry.optional) scope = "optional";
|
|
351
352
|
else if (entry.peer) scope = "peer";
|
|
352
353
|
const isDirectDep = depth === 0 && isAnyDirect(installName);
|
|
353
354
|
if (isDirectDep) {
|
|
354
|
-
if (isDirect(installName, "
|
|
355
|
+
if (isDirect(installName, "prod")) scope = "prod";
|
|
355
356
|
else if (isDirect(installName, "optional")) scope = "optional";
|
|
356
357
|
else if (isDirect(installName, "peer")) scope = "peer";
|
|
357
|
-
else scope = "
|
|
358
|
+
else scope = "dev";
|
|
358
359
|
} else if (depth > 0 || !isAnyDirect(installName)) {
|
|
359
360
|
// Flattened-but-not-direct = transitive. Keep dev/optional flags
|
|
360
361
|
// for filtering, but record it as a transitive.
|
|
@@ -362,7 +363,12 @@ function parsePackageLock(filePath) {
|
|
|
362
363
|
}
|
|
363
364
|
// isDev flag survives the scope reclassification: a flattened
|
|
364
365
|
// transitive of a dev-only dep is still dev-only.
|
|
365
|
-
const
|
|
366
|
+
const directProduction = isDirectDep && ["prod", "optional", "peer"].some(s => isDirect(installName, s));
|
|
367
|
+
// npm's devOptional means both a dev path and an optional production path.
|
|
368
|
+
const isDev = !directProduction && !entry.devOptional && !!(entry.dev || (isDirectDep && isDirect(installName, "dev")));
|
|
369
|
+
// A dev-only direct declaration with a production optional path is
|
|
370
|
+
// indirect in production, even when npm hoists it to the root.
|
|
371
|
+
if (isDirectDep && scope === 'dev' && entry.devOptional) scope = 'transitive';
|
|
366
372
|
out.deps.push({
|
|
367
373
|
name,
|
|
368
374
|
...(name !== installName ? { alias: installName } : {}),
|
|
@@ -381,6 +387,7 @@ function parsePackageLock(filePath) {
|
|
|
381
387
|
let scope = "prod";
|
|
382
388
|
if (entry.dev) scope = "dev";
|
|
383
389
|
else if (entry.optional) scope = "optional";
|
|
390
|
+
if (depth > 0) scope = "transitive";
|
|
384
391
|
const isDev = !!entry.dev || parentIsDev;
|
|
385
392
|
// v1 spells an alias install in the version: "npm:string-width@4.2.3".
|
|
386
393
|
const al = parseNpmAlias(entry.version);
|
|
@@ -26,18 +26,15 @@ const { withPublic, authHeaderFor, normalise } = require("../../registries");
|
|
|
26
26
|
|
|
27
27
|
const CACHE_DIR = path.join(require("../../cache-directory").getCacheDir());
|
|
28
28
|
const CACHE_PATH = path.join(CACHE_DIR, "npm-registry-cache.json");
|
|
29
|
-
const CACHE_MAX_AGE_MS =
|
|
29
|
+
const CACHE_MAX_AGE_MS = 4 * 3600 * 1000;
|
|
30
|
+
const sourceFetchedAt=new WeakMap();
|
|
30
31
|
|
|
31
32
|
function loadCache() {
|
|
32
|
-
|
|
33
|
-
catch { return { meta: { fetchedAt: 0 }, entries: {} }; }
|
|
33
|
+
return require('../../json-cache').load(CACHE_DIR,'npm-registry',{ meta: { fetchedAt: 0 }, entries: {} });
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function saveCache(data) {
|
|
37
|
-
|
|
38
|
-
fs.mkdirSync(CACHE_DIR, { recursive: true });
|
|
39
|
-
fs.writeFileSync(CACHE_PATH, JSON.stringify(data));
|
|
40
|
-
} catch { /* ignore */ }
|
|
37
|
+
require('../../json-cache').save(CACHE_DIR,'npm-registry',data);
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
/** Pull a recommended replacement out of a free-form deprecation message. */
|
|
@@ -121,7 +118,11 @@ async function fetchPackument(name, opts = {}) {
|
|
|
121
118
|
const res = await require("../../providers").getResource("npm", "package", { name },
|
|
122
119
|
{ fetcher, headers, ...(hosted ? { requestTimeoutMs: timeoutMs } : { signal: AbortSignal.timeout(timeoutMs) }),
|
|
123
120
|
...(base.name === "public" ? {} : { urlOverride: url, direct: true }) });
|
|
124
|
-
if (res.ok)
|
|
121
|
+
if (res.ok) {
|
|
122
|
+
const body=await res.json(),fetchedAt=Date.parse(res.headers?.get('x-fad-proxy-fetched-at')||'');
|
|
123
|
+
if(body&&typeof body==='object'&&Number.isFinite(fetchedAt))sourceFetchedAt.set(body,fetchedAt);
|
|
124
|
+
return body;
|
|
125
|
+
}
|
|
125
126
|
lastErr = `HTTP ${res.status}`;
|
|
126
127
|
statuses.push(res.status);
|
|
127
128
|
} catch (err) {
|
|
@@ -157,10 +158,23 @@ async function checkNpmRegistryDeps(resolvedDeps, opts = {}) {
|
|
|
157
158
|
if (!targets.length) return result;
|
|
158
159
|
|
|
159
160
|
const cache = loadCache();
|
|
160
|
-
const fresh = (offline || !require("../../providers").hasHostedProxy()) && cache.meta?.fetchedAt && (
|
|
161
|
+
const fresh = (offline || !require("../../providers").hasHostedProxy()) && cache.meta?.fetchedAt && require('../../cache-policy').fresh(cache.meta.fetchedAt, CACHE_MAX_AGE_MS);
|
|
162
|
+
const previous = !fresh && !offline ? {entries:cache.entries, fetchedAt:cache.meta?.fetchedAt} : null;
|
|
161
163
|
if (!fresh && !offline) cache.entries = {};
|
|
162
164
|
|
|
163
165
|
const cacheKey = t => `${t.npmName}@${t.version}`;
|
|
166
|
+
// A definitive packument 404/410 is evidence about the package name, not
|
|
167
|
+
// just the version used for the probe. Preserve it across versions offline
|
|
168
|
+
// unless another cached observation for that name found a packument.
|
|
169
|
+
const offlineAbsent = new Map();
|
|
170
|
+
if (offline) for (const [key, value] of Object.entries(cache.entries || {})) {
|
|
171
|
+
const split = key.lastIndexOf('@');
|
|
172
|
+
if (split <= 0) continue;
|
|
173
|
+
const name = key.slice(0, split), status = offlineAbsent.get(name) || { absent: false, present: false };
|
|
174
|
+
if (value?.absent) status.absent = true;
|
|
175
|
+
else if (value && !value.error) status.present = true;
|
|
176
|
+
offlineAbsent.set(name, status);
|
|
177
|
+
}
|
|
164
178
|
const liveCount = offline ? 0 : targets.filter(t => !cache.entries[cacheKey(t)]).length;
|
|
165
179
|
if (liveCount && !offline && !onProgress) {
|
|
166
180
|
console.log(`📦 npm registry: checking ${targets.length} packages for deprecation${allLibs ? " + outdated" : ""} (${liveCount} live, ${targets.length - liveCount} cached)…`);
|
|
@@ -169,6 +183,7 @@ async function checkNpmRegistryDeps(resolvedDeps, opts = {}) {
|
|
|
169
183
|
// Incremental progress — fetching ~hundreds/thousands of packuments at
|
|
170
184
|
// concurrency N would otherwise be total silence for a minute or more.
|
|
171
185
|
let processed = 0;
|
|
186
|
+
let oldestFetchedAt=Date.now();
|
|
172
187
|
const startedAt = Date.now();
|
|
173
188
|
const printProgress = (final = false) => {
|
|
174
189
|
if (onProgress) { onProgress(processed, targets.length); return; }
|
|
@@ -185,8 +200,21 @@ async function checkNpmRegistryDeps(resolvedDeps, opts = {}) {
|
|
|
185
200
|
const { dep, npmName, version } = t;
|
|
186
201
|
const key = cacheKey(t);
|
|
187
202
|
let extracted = cache.entries[key];
|
|
203
|
+
if (!extracted && offline) {
|
|
204
|
+
const status = offlineAbsent.get(npmName);
|
|
205
|
+
if (status?.absent && !status.present) extracted = { absent: true };
|
|
206
|
+
}
|
|
207
|
+
if (!extracted && offline && !registries.length) {
|
|
208
|
+
const seeded=require('../../package-versions').getVersion('npm',npmName,version);
|
|
209
|
+
if (seeded) {
|
|
210
|
+
const manifest=JSON.parse(seeded.body);
|
|
211
|
+
const f=packumentToFindings({versions:{[version]:manifest}},{version});
|
|
212
|
+
extracted={deprecated:null,latest:null,latestDate:null,license:f.license || null};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
188
215
|
if (!extracted) {
|
|
189
216
|
const packument = await fetchPackument(npmName, { offline, registries });
|
|
217
|
+
if(packument&&typeof packument==='object')oldestFetchedAt=Math.min(oldestFetchedAt,sourceFetchedAt.get(packument)||Date.now());
|
|
190
218
|
if (packument && !packument.error) {
|
|
191
219
|
const f = packumentToFindings(packument, { version });
|
|
192
220
|
extracted = {
|
|
@@ -225,8 +253,9 @@ async function checkNpmRegistryDeps(resolvedDeps, opts = {}) {
|
|
|
225
253
|
if (liveCount) printProgress(true);
|
|
226
254
|
|
|
227
255
|
if (!offline) {
|
|
228
|
-
if (!fresh) cache.meta = { fetchedAt:
|
|
229
|
-
|
|
256
|
+
if (!fresh) cache.meta = { fetchedAt: oldestFetchedAt };
|
|
257
|
+
require('../../cache-policy').preserveEntries(cache, previous);
|
|
258
|
+
saveCache(cache);
|
|
230
259
|
}
|
|
231
260
|
|
|
232
261
|
result.deprecated.sort((a, b) => a.dep.artifactId.localeCompare(b.dep.artifactId));
|
|
@@ -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) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* API: https://api.nuget.org/v3/registration5-gz-semver2/{lowerid}/index.json
|
|
6
6
|
* → { items: [ { items: [ { catalogEntry: { version, deprecation } } ] } ] }
|
|
7
7
|
*
|
|
8
|
-
* Cached in ~/.fad-checker/nuget-cache.json for
|
|
8
|
+
* Cached in ~/.fad-checker/nuget-cache.json for 4h.
|
|
9
9
|
*
|
|
10
10
|
* @author: N.BRAUN
|
|
11
11
|
* @email: pp9ping@gmail.com
|
|
@@ -19,10 +19,10 @@ const { withPublic, authHeaderFor, normalise } = require("../../registries");
|
|
|
19
19
|
|
|
20
20
|
const CACHE_DIR = path.join(require("../../cache-directory").getCacheDir());
|
|
21
21
|
const CACHE_PATH = path.join(CACHE_DIR, "nuget-cache.json");
|
|
22
|
-
const CACHE_MAX_AGE_MS =
|
|
22
|
+
const CACHE_MAX_AGE_MS = 4 * 3600 * 1000;
|
|
23
23
|
|
|
24
|
-
function loadCache() {
|
|
25
|
-
function saveCache(d) {
|
|
24
|
+
function loadCache() { return require('../../json-cache').load(CACHE_DIR,'nuget',{ entries: {}, meta: {} }); }
|
|
25
|
+
function saveCache(d) { require('../../json-cache').save(CACHE_DIR,'nuget',d); }
|
|
26
26
|
function isStable(v) { return /^\d+(\.\d+)*$/.test(String(v || "")); }
|
|
27
27
|
function cmp(a, b) {
|
|
28
28
|
const pa = String(a).split(/[.\-+]/).map(n => parseInt(n, 10) || 0);
|
|
@@ -135,7 +135,8 @@ async function checkNugetRegistryDeps(deps, opts = {}) {
|
|
|
135
135
|
const result = { deprecated: [], outdated: [], licensed: [], private: [] };
|
|
136
136
|
if (!targets.length) return result;
|
|
137
137
|
const cache = loadCache();
|
|
138
|
-
const fresh = (offline || !require("../../providers").hasHostedProxy()) && cache.meta?.fetchedAt && (
|
|
138
|
+
const fresh = (offline || !require("../../providers").hasHostedProxy()) && cache.meta?.fetchedAt && require('../../cache-policy').fresh(cache.meta.fetchedAt, CACHE_MAX_AGE_MS);
|
|
139
|
+
const previous = !fresh && !offline ? {entries:cache.entries, fetchedAt:cache.meta?.fetchedAt} : null;
|
|
139
140
|
if (!fresh && !offline) cache.entries = {};
|
|
140
141
|
const limit = pLimit(concurrency);
|
|
141
142
|
await Promise.all(targets.map(t => limit(async () => {
|
|
@@ -168,7 +169,8 @@ async function checkNugetRegistryDeps(deps, opts = {}) {
|
|
|
168
169
|
// fresh to the next ONLINE run and skip its refetch.
|
|
169
170
|
if (!offline) {
|
|
170
171
|
if (!fresh) cache.meta = { fetchedAt: Date.now() };
|
|
171
|
-
|
|
172
|
+
require('../../cache-policy').preserveEntries(cache, previous);
|
|
173
|
+
saveCache(cache);
|
|
172
174
|
}
|
|
173
175
|
return result;
|
|
174
176
|
}
|
|
@@ -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 */ }
|