vigievuln 1.1.2 → 1.2.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 +25 -0
- package/README.md +51 -141
- package/completions/vigievuln.bash +1 -1
- package/completions/vigievuln.zsh +1 -0
- package/lib/account-client.js +21 -14
- package/lib/account-session.js +6 -2
- package/lib/advisory-compression.js +25 -0
- package/lib/advisory-fixes.js +21 -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 +357 -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/cli-command-routing.js +29 -6
- package/lib/cli-groups.js +32 -3
- package/lib/cli-project-commands.js +47 -6
- package/lib/cli-setup.js +300 -0
- package/lib/codecs/binary/pe-metadata.js +79 -0
- package/lib/codecs/binary/scan.js +4 -3
- package/lib/codecs/binary.codec.js +4 -2
- package/lib/codecs/composer/registry.js +8 -6
- package/lib/codecs/go/parse.js +7 -9
- package/lib/codecs/go/registry.js +7 -5
- package/lib/codecs/go.codec.js +5 -0
- package/lib/codecs/maven.codec.js +73 -8
- package/lib/codecs/npm/collect.js +12 -5
- package/lib/codecs/npm/parse.js +12 -5
- package/lib/codecs/npm/registry.js +42 -12
- package/lib/codecs/nuget/registry.js +8 -6
- package/lib/codecs/pypi/registry.js +8 -6
- package/lib/codecs/ruby/registry.js +7 -5
- package/lib/compression-dictionary.js +5 -0
- package/lib/coverage-diagnostics.js +26 -0
- package/lib/cve-download.js +157 -41
- package/lib/cve-legacy-ranges.js +59 -0
- package/lib/cve-match.js +85 -17
- package/lib/cve-npm-proxy.js +29 -0
- package/lib/cve-report.js +145 -58
- package/lib/cve-version-verdict.js +77 -0
- package/lib/deps-descriptor.js +8 -3
- 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/hosted-proxy.js +6 -1
- package/lib/i18n.js +31 -8
- package/lib/json-cache.js +18 -0
- package/lib/json-export.js +16 -2
- 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/maven-repo.js +11 -6
- 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 +52 -24
- package/lib/osv-db.js +253 -59
- package/lib/osv-legacy.js +57 -0
- package/lib/osv.js +241 -168
- 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 +49 -26
- package/lib/providers/vigievuln.js +7 -0
- package/lib/proxy-cache.js +1 -1
- package/lib/proxy-scope.js +59 -0
- package/lib/proxy-throttle.js +71 -0
- package/lib/resource-cache/engine.js +36 -9
- 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 +11 -7
- package/lib/snyk.js +32 -20
- package/lib/source-profile.js +67 -0
- package/lib/sqlite-driver.js +46 -0
- package/lib/transitive.js +69 -34
- package/lib/unmanaged.js +2 -1
- package/lib/vigievuln-advisories.js +47 -0
- package/package.json +7 -6
- package/vigievuln.js +380 -107
package/lib/cache-directory.js
CHANGED
|
@@ -1,77 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const fs = require('node:fs');
|
|
3
|
-
const path = require('node:path');
|
|
4
|
-
const os = require('node:os');
|
|
5
|
-
const {spawnSync} = require('node:child_process');
|
|
6
|
-
const warned = new Set();
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
const warnPending = () => {
|
|
24
|
-
if (warned.has(current)) return;
|
|
25
|
-
warned.add(current);
|
|
26
|
-
const show = value => '"' + value.replace(/[\x00-\x1f\x7f"]/g, c => c === '"' ? '\\"' : `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`) + '"';
|
|
27
|
-
let previous;
|
|
28
|
-
try { previous = stat(legacy); } catch { /* leave recovery to the user */ }
|
|
29
|
-
const recovery = previous?.isDirectory() && !previous.isSymbolicLink()
|
|
30
|
-
? `Stop VigieVuln, back up or move ${show(current)}, then rename ${show(legacy)} to ${show(current)}.`
|
|
31
|
-
: `Stop VigieVuln and inspect ${show(legacy)} safely; it is not a regular directory and requires manual recovery.`;
|
|
32
|
-
warn(`VigieVuln cache migration failed; previous data remains at ${show(legacy)} and is not being used. ` +
|
|
33
|
-
`${recovery} After recovery, remove ${show(marker)}.`);
|
|
34
|
-
};
|
|
35
|
-
if (checkCurrent()) {
|
|
36
|
-
let pending;
|
|
37
|
-
try { pending = stat(marker); } catch { /* an unreadable reminder must not block the cache */ }
|
|
38
|
-
if (pending && pending.isFile() && !pending.isSymbolicLink()) {
|
|
39
|
-
let previous;
|
|
40
|
-
try { previous = stat(legacy); } catch { previous = true; }
|
|
41
|
-
if (previous) warnPending();
|
|
42
|
-
}
|
|
43
|
-
return current;
|
|
44
|
-
}
|
|
45
|
-
const old = stat(legacy);
|
|
46
|
-
if (!old) return current;
|
|
47
|
-
// Do not let an mv fallback copy or delete a cache on another filesystem.
|
|
48
|
-
const parent = stat(homeDir);
|
|
49
|
-
if (old.isDirectory() && !old.isSymbolicLink() && parent && old.dev === parent.dev) {
|
|
50
|
-
try {
|
|
51
|
-
if (!checkCurrent()) {
|
|
52
|
-
// Node's POSIX rename can replace an empty destination created concurrently.
|
|
53
|
-
// GNU mv -n -T uses no-clobber semantics. Darwin's renameatx_np
|
|
54
|
-
// syscall with RENAME_EXCL refuses an existing destination atomically.
|
|
55
|
-
// Windows rename refuses a target. On failure retain the old directory.
|
|
56
|
-
if (platform === 'linux') spawn('/bin/mv', ['-n', '-T', '--', legacy, current], {stdio:'ignore'});
|
|
57
|
-
else if (platform === 'darwin') spawn('/usr/bin/perl', ['-e',
|
|
58
|
-
'exit(syscall(488, -2, $ARGV[0], -2, $ARGV[1], 4) == 0 ? 0 : 1)', legacy, current], {stdio:'ignore'});
|
|
59
|
-
else if (platform === 'win32') fsImpl.renameSync(legacy, current);
|
|
60
|
-
}
|
|
61
|
-
} catch { /* Keep the legacy data and fall back to a fresh directory. */ }
|
|
62
|
-
}
|
|
63
|
-
if (!checkCurrent()) {
|
|
64
|
-
try { fsImpl.mkdirSync(current, {mode:0o700}); }
|
|
65
|
-
catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
66
|
-
checkCurrent();
|
|
67
|
-
}
|
|
68
|
-
if (stat(legacy)) {
|
|
69
|
-
// The marker contains no paths or configuration and is never overwritten.
|
|
70
|
-
try { fsImpl.writeFileSync(marker, '', {flag:'wx', mode:0o600}); } catch { /* warning still appears now */ }
|
|
71
|
-
warnPending();
|
|
72
|
-
}
|
|
73
|
-
return current;
|
|
3
|
+
const fs=require('node:fs');
|
|
4
|
+
const path=require('node:path');
|
|
5
|
+
const os=require('node:os');
|
|
6
|
+
|
|
7
|
+
// Cache locations never migrate data from pre-1.2 directories. Startup disposes
|
|
8
|
+
// of legacy files while retaining configuration and account sessions.
|
|
9
|
+
let activeCacheDir=null;
|
|
10
|
+
function directory(name,{homeDir=os.homedir()}={}){
|
|
11
|
+
const root=path.join(homeDir,name);
|
|
12
|
+
try{
|
|
13
|
+
const stat=fs.lstatSync(root);
|
|
14
|
+
if(!stat.isDirectory()||stat.isSymbolicLink())throw Error('unsafe VigieVuln cache directory');
|
|
15
|
+
}catch(error){if(error.code!=='ENOENT')throw error}
|
|
16
|
+
return root;
|
|
74
17
|
}
|
|
75
|
-
const getCacheDir
|
|
76
|
-
const getProxyCacheDir
|
|
77
|
-
|
|
18
|
+
const getCacheDir=options=>activeCacheDir||directory('.vigie-vuln',options);
|
|
19
|
+
const getProxyCacheDir=options=>directory('.vigie-vuln-proxy-cache',options);
|
|
20
|
+
const setActiveCacheDir=value=>{activeCacheDir=value};
|
|
21
|
+
module.exports={getCacheDir,getProxyCacheDir,setActiveCacheDir};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_TTL_MS = 4 * 60 * 60 * 1000;
|
|
4
|
+
let forceUpdate = false;
|
|
5
|
+
function setForceUpdate(value) { forceUpdate = value === true; }
|
|
6
|
+
function shouldForceUpdate() { return forceUpdate; }
|
|
7
|
+
function fresh(fetchedAt, ttlMs = DEFAULT_TTL_MS, now = Date.now()) {
|
|
8
|
+
return !forceUpdate && Number.isFinite(fetchedAt) && fetchedAt > 0 && now >= fetchedAt && now - fetchedAt < Math.min(ttlMs, DEFAULT_TTL_MS);
|
|
9
|
+
}
|
|
10
|
+
// Legacy registry caches carry one timestamp for the whole map. If some old
|
|
11
|
+
// entries were not refreshed, keep their oldest timestamp instead of making
|
|
12
|
+
// them appear newly consulted, and never replace them with transient errors.
|
|
13
|
+
function preserveEntries(cache, previous) {
|
|
14
|
+
if (!previous?.entries) return cache;
|
|
15
|
+
let retained=false;
|
|
16
|
+
for (const [key,value] of Object.entries(previous.entries)) {
|
|
17
|
+
const next=cache.entries[key];
|
|
18
|
+
if (!Object.hasOwn(cache.entries,key) || (next?.error && !next.absent)) {
|
|
19
|
+
cache.entries[key]=value;retained=true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if(retained) cache.meta={...cache.meta,fetchedAt:Math.min(Number(cache.meta?.fetchedAt)||0,Number(previous.fetchedAt)||0)};
|
|
23
|
+
return cache;
|
|
24
|
+
}
|
|
25
|
+
module.exports = {DEFAULT_TTL_MS, setForceUpdate, shouldForceUpdate, fresh, preserveEntries};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {getCacheDb}=require('./cache-db');
|
|
4
|
+
const zlib=require('node:zlib');
|
|
5
|
+
|
|
6
|
+
function createCacheRepository(cacheDir){
|
|
7
|
+
const db=getCacheDb(cacheDir);
|
|
8
|
+
const get=db.prepare('SELECT fetched_at,expires_at,stale,encoding,payload,metadata_json FROM cache_entries WHERE namespace=? AND key=?');
|
|
9
|
+
const put=db.prepare(`INSERT INTO cache_entries(namespace,key,fetched_at,expires_at,stale,encoding,payload,metadata_json)
|
|
10
|
+
VALUES (?,?,?,?,?,?,?,?) ON CONFLICT(namespace,key) DO UPDATE SET fetched_at=excluded.fetched_at,
|
|
11
|
+
expires_at=excluded.expires_at,stale=excluded.stale,encoding=excluded.encoding,payload=excluded.payload,metadata_json=excluded.metadata_json`);
|
|
12
|
+
const remove=db.prepare('DELETE FROM cache_entries WHERE namespace=? AND key=?');
|
|
13
|
+
return {
|
|
14
|
+
db,
|
|
15
|
+
get(namespace,key){
|
|
16
|
+
const row=get.get(namespace,key);if(!row)return null;
|
|
17
|
+
const compressed=row.encoding.endsWith('+deflate');
|
|
18
|
+
const body=compressed?zlib.inflateRawSync(Buffer.from(row.payload),{maxOutputLength:134217728}):Buffer.from(row.payload);
|
|
19
|
+
const encoding=compressed?row.encoding.slice(0,-8):row.encoding;
|
|
20
|
+
return {value:encoding==='json'?JSON.parse(body.toString('utf8')):encoding==='text'?body.toString('utf8'):body,
|
|
21
|
+
fetchedAt:row.fetched_at,expiresAt:row.expires_at,stale:!!row.stale,metadata:JSON.parse(row.metadata_json)};
|
|
22
|
+
},
|
|
23
|
+
put(namespace,key,value,{fetchedAt=Date.now(),expiresAt=null,stale=false,metadata={}}={}){
|
|
24
|
+
const encoding=Buffer.isBuffer(value)||value instanceof Uint8Array?'binary':typeof value==='string'?'text':'json';
|
|
25
|
+
const bytes=encoding==='binary'?Buffer.from(value):Buffer.from(encoding==='text'?value:JSON.stringify(value));
|
|
26
|
+
const compressed=bytes.length>=4096;
|
|
27
|
+
put.run(namespace,key,fetchedAt,expiresAt,stale?1:0,compressed?encoding+'+deflate':encoding,
|
|
28
|
+
compressed?zlib.deflateRawSync(bytes,{level:1}):bytes,JSON.stringify({...metadata,...(compressed?{uncompressedBytes:bytes.length}:{})}));
|
|
29
|
+
},
|
|
30
|
+
delete(namespace,key){return remove.run(namespace,key).changes>0},
|
|
31
|
+
*entries(namespace){
|
|
32
|
+
let last='';
|
|
33
|
+
for(;;){
|
|
34
|
+
const rows=db.prepare('SELECT key FROM cache_entries WHERE namespace=? AND key>? ORDER BY key LIMIT 1000').all(namespace,last);
|
|
35
|
+
if(!rows.length)return;
|
|
36
|
+
for(const row of rows){last=row.key;yield [row.key,this.get(namespace,row.key)]}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
getSnapshot(namespace){const row=db.prepare('SELECT * FROM cache_snapshots WHERE namespace=?').get(namespace);return row?{fetchedAt:row.fetched_at,complete:!!row.complete,stale:!!row.stale,recordCount:row.record_count,metadata:JSON.parse(row.metadata_json)}:null},
|
|
40
|
+
putSnapshot(namespace,{fetchedAt=Date.now(),complete=false,stale=false,recordCount=0,metadata={}}={}){
|
|
41
|
+
db.prepare(`INSERT INTO cache_snapshots(namespace,fetched_at,complete,stale,record_count,metadata_json) VALUES (?,?,?,?,?,?)
|
|
42
|
+
ON CONFLICT(namespace) DO UPDATE SET fetched_at=excluded.fetched_at,complete=excluded.complete,
|
|
43
|
+
stale=excluded.stale,record_count=excluded.record_count,metadata_json=excluded.metadata_json`).run(namespace,fetchedAt,complete?1:0,stale?1:0,recordCount,JSON.stringify(metadata));
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports={createCacheRepository};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs=require('node:fs');
|
|
4
|
+
const path=require('node:path');
|
|
5
|
+
const os=require('node:os');
|
|
6
|
+
function statOrNull(file){try{return fs.lstatSync(file)}catch(error){if(error.code==='ENOENT')return null;throw error}}
|
|
7
|
+
|
|
8
|
+
function cleanRoot(root,{keepConfig=false}={}){
|
|
9
|
+
let stat;try{stat=fs.lstatSync(root)}catch(error){if(error.code==='ENOENT')return;throw error}
|
|
10
|
+
if(!stat.isDirectory()||stat.isSymbolicLink())throw Error('unsafe cache directory');
|
|
11
|
+
const keep=new Set(['cache.sqlite','cache.sqlite-wal','cache.sqlite-shm',...(keepConfig?['config.json']:[])]);
|
|
12
|
+
if(keepConfig&&statOrNull(path.join(root,'config.json'))){
|
|
13
|
+
const item=fs.lstatSync(path.join(root,'config.json'));
|
|
14
|
+
if(!item.isFile()||item.isSymbolicLink()||item.nlink!==1)throw Error('unsafe cache configuration');
|
|
15
|
+
}
|
|
16
|
+
for(const name of fs.readdirSync(root))if(!keep.has(name))fs.rmSync(path.join(root,name),{recursive:true,force:true});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function prepareDirectCache({homeDir=os.homedir()}={}){
|
|
20
|
+
const current=path.join(homeDir,'.vigie-vuln'),legacy=path.join(homeDir,'.fad-checker');
|
|
21
|
+
const existing=statOrNull(current),old=statOrNull(legacy);
|
|
22
|
+
if(existing){
|
|
23
|
+
const stat=existing;
|
|
24
|
+
if(!stat.isDirectory()||stat.isSymbolicLink())throw Error('unsafe cache directory');
|
|
25
|
+
}
|
|
26
|
+
if(old&&(!old.isDirectory()||old.isSymbolicLink()))throw Error('unsafe legacy cache directory');
|
|
27
|
+
fs.mkdirSync(current,{recursive:true,mode:0o700});
|
|
28
|
+
const config=path.join(current,'config.json'),oldConfig=path.join(legacy,'config.json');
|
|
29
|
+
if(!statOrNull(config)&&statOrNull(oldConfig)){
|
|
30
|
+
const stat=fs.lstatSync(oldConfig);
|
|
31
|
+
if(!stat.isFile()||stat.isSymbolicLink()||stat.nlink!==1)throw Error('unsafe legacy cache configuration');
|
|
32
|
+
fs.copyFileSync(oldConfig,config,fs.constants.COPYFILE_EXCL);fs.chmodSync(config,0o600);
|
|
33
|
+
}
|
|
34
|
+
cleanRoot(current,{keepConfig:true});
|
|
35
|
+
if(old){
|
|
36
|
+
fs.rmSync(legacy,{recursive:true,force:true});
|
|
37
|
+
}
|
|
38
|
+
return current;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function prepareScopedCache(root){cleanRoot(root);return root}
|
|
42
|
+
|
|
43
|
+
function prepareServeCache({homeDir=os.homedir()}={}){
|
|
44
|
+
const current=path.join(homeDir,'.vigie-vuln-proxy-cache'),legacy=path.join(homeDir,'.fad-checker-proxy-cache');
|
|
45
|
+
cleanRoot(current);
|
|
46
|
+
if(fs.existsSync(legacy)){
|
|
47
|
+
const stat=fs.lstatSync(legacy);
|
|
48
|
+
if(!stat.isDirectory()||stat.isSymbolicLink())throw Error('unsafe legacy proxy cache directory');
|
|
49
|
+
fs.rmSync(legacy,{recursive:true,force:true});
|
|
50
|
+
}
|
|
51
|
+
return current;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports={cleanRoot,prepareDirectCache,prepareScopedCache,prepareServeCache};
|
package/lib/certfr.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Cache: ~/.fad-checker/certfr-cache.json = { meta: { fetchedAt }, entries: { ref:
|
|
13
13
|
* { kind, rev, title, cves } } } — the accumulating entry-map shape, so --import-cache
|
|
14
|
-
* merges it key by key. The listings are re-read after
|
|
14
|
+
* merges it key by key. The listings are re-read after 4h; offline uses what is there.
|
|
15
15
|
*
|
|
16
16
|
* @author: N.BRAUN
|
|
17
17
|
* @email: pp9ping@gmail.com
|
|
@@ -22,7 +22,7 @@ const os = require("os");
|
|
|
22
22
|
|
|
23
23
|
const DEFAULT_CACHE_DIR = path.join(require("./cache-directory").getCacheDir());
|
|
24
24
|
const CACHE_FILE = "certfr-cache.json";
|
|
25
|
-
const CACHE_TTL_MS =
|
|
25
|
+
const CACHE_TTL_MS = 4 * 3600 * 1000;
|
|
26
26
|
const KINDS = ["avis", "alerte"];
|
|
27
27
|
const SAVE_EVERY = 500;
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ const cachePath = dir => path.join(dir || DEFAULT_CACHE_DIR, CACHE_FILE);
|
|
|
30
30
|
|
|
31
31
|
function readCache(dir) {
|
|
32
32
|
try {
|
|
33
|
-
const data =
|
|
33
|
+
const data = require('./cache-repository').createCacheRepository(dir || DEFAULT_CACHE_DIR).get('catalogue','certfr')?.value;
|
|
34
34
|
if (data?.entries && typeof data.entries === "object") return data;
|
|
35
35
|
} catch { /* none yet */ }
|
|
36
36
|
return { meta: { fetchedAt: 0 }, entries: {} };
|
|
@@ -39,10 +39,7 @@ function readCache(dir) {
|
|
|
39
39
|
function writeCache(dir, data) {
|
|
40
40
|
if (dir === false) return; // a caller that persists the index itself (vigievuln)
|
|
41
41
|
try {
|
|
42
|
-
|
|
43
|
-
const tmp = cachePath(dir) + ".tmp";
|
|
44
|
-
fs.writeFileSync(tmp, JSON.stringify(data));
|
|
45
|
-
fs.renameSync(tmp, cachePath(dir));
|
|
42
|
+
require('./cache-repository').createCacheRepository(dir || DEFAULT_CACHE_DIR).put('catalogue','certfr',data,{fetchedAt:data.meta?.fetchedAt||Date.now()});
|
|
46
43
|
} catch { /* a cache is an optimisation */ }
|
|
47
44
|
}
|
|
48
45
|
|
|
@@ -82,9 +79,11 @@ async function refresh(data, { fetcher, verbose, cacheDir, concurrency, onProgre
|
|
|
82
79
|
const { getResource } = require("./providers");
|
|
83
80
|
const headers = { "User-Agent": "vigievuln-certfr" };
|
|
84
81
|
const todo = [];
|
|
82
|
+
let oldestFetchedAt = Date.now();
|
|
85
83
|
for (const kind of KINDS) {
|
|
86
84
|
const r = await getResource("certfr", "index", { kind }, { fetcher, headers });
|
|
87
85
|
if (!r.ok) throw new Error(`CERT-FR ${kind} listing HTTP ${r.status}`);
|
|
86
|
+
oldestFetchedAt = Math.min(oldestFetchedAt, require('./providers/common').responseFetchedAt(r));
|
|
88
87
|
todo.push(...staleAdvisories(await r.json(), data.entries, kind));
|
|
89
88
|
}
|
|
90
89
|
let done = 0, failed = 0, next = 0;
|
|
@@ -93,6 +92,7 @@ async function refresh(data, { fetcher, verbose, cacheDir, concurrency, onProgre
|
|
|
93
92
|
const a = todo[next++];
|
|
94
93
|
try {
|
|
95
94
|
const r = await getResource("certfr", "advisory", { kind: a.kind, ref: a.ref, rev: a.rev }, { fetcher, headers });
|
|
95
|
+
oldestFetchedAt = Math.min(oldestFetchedAt, require('./providers/common').responseFetchedAt(r));
|
|
96
96
|
// A 404/410 is an answer (a listed advisory without JSON): record it empty so it
|
|
97
97
|
// is not re-requested every run. Anything else is retried next time.
|
|
98
98
|
if (r.ok) data.entries[a.ref] = { kind: a.kind, rev: a.rev, title: a.title, cves: advisoryCves(await r.json()) };
|
|
@@ -107,7 +107,7 @@ async function refresh(data, { fetcher, verbose, cacheDir, concurrency, onProgre
|
|
|
107
107
|
await Promise.all(Array.from({ length: Math.max(1, concurrency) }, worker));
|
|
108
108
|
// A run that could not read some advisories leaves the listing stamp unchanged, so the
|
|
109
109
|
// next run retries them instead of waiting a day.
|
|
110
|
-
if (!failed) data.meta = { fetchedAt:
|
|
110
|
+
if (!failed) data.meta = { fetchedAt: oldestFetchedAt };
|
|
111
111
|
writeCache(cacheDir, data);
|
|
112
112
|
if (verbose) console.log(` CERT-FR: ${todo.length - failed} advisories indexed${failed ? `, ${failed} failed` : ""}`);
|
|
113
113
|
return { changed: todo.filter(a => data.entries[a.ref]?.rev === a.rev).map(a => a.ref), failed };
|
|
@@ -136,7 +136,7 @@ async function enrichCertFr(matches, opts = {}) {
|
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
const data = readCache(cacheDir);
|
|
139
|
-
if (!offline &&
|
|
139
|
+
if (!offline && !require('./cache-policy').fresh(data.meta?.fetchedAt || 0, CACHE_TTL_MS)) {
|
|
140
140
|
try { await refresh(data, { fetcher, verbose, cacheDir, concurrency, onProgress }); }
|
|
141
141
|
catch (err) { if (verbose) console.warn(` CERT-FR refresh failed: ${err.message} — using the cached index`); }
|
|
142
142
|
}
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
const COMMAND_HELP = `
|
|
4
4
|
Commands:
|
|
5
5
|
scan <dir> [options] scan a source tree (alias of -s <dir>)
|
|
6
|
-
|
|
6
|
+
setup configure sources and proxy
|
|
7
|
+
watch <dir> --name <name> collect and upload a project
|
|
7
8
|
watch <dir> --id <id> update an explicitly selected project
|
|
8
|
-
watch <dir> --export <file>
|
|
9
|
+
watch <dir> --export <file> export descriptor locally
|
|
9
10
|
login | logout | whoami aliases of auth login | logout | status
|
|
10
11
|
config show show masked configuration
|
|
11
|
-
cache export <file>
|
|
12
|
-
cache
|
|
12
|
+
cache export|import <file> transfer the complete local cache
|
|
13
|
+
cache prepare <descriptor> --output <file> prepare a project archive online
|
|
13
14
|
|
|
14
15
|
watch --help: privacy, safe updates; free account: 1 project,
|
|
15
16
|
100 distinct direct coordinates (versions count once). Legacy commands remain supported.`;
|
|
@@ -36,12 +37,34 @@ function routeArguments(input) {
|
|
|
36
37
|
}
|
|
37
38
|
if (command === 'cache') {
|
|
38
39
|
if (args.length === 1 || args.some(a => a === '--help' || a === '-h'))
|
|
39
|
-
return { help: 'Usage: vigievuln cache export <file> [--
|
|
40
|
+
return { help: 'Usage: vigievuln cache prepare <descriptor.json> --output <archive.tar.gz> [source options]\n vigievuln cache export <file> [--verbose] [source options]\n vigievuln cache import <file> [--replace] [--force] [--verbose] [source options]\nPrepare warms the descriptor and writes a project archive in one invocation. Export copies the complete local cache.' };
|
|
40
41
|
const [, operation, file, ...rest] = args;
|
|
42
|
+
if (operation === 'prepare') {
|
|
43
|
+
if (!file || file.startsWith('-')) throw new Error('usage: vigievuln cache prepare <descriptor.json> --output <archive.tar.gz>');
|
|
44
|
+
if (rest.some(a=>/^--(?:export-cache|import-cache|prepare-offline|import-anonymized)(?:=|$)/.test(a))) throw new Error('cache prepare cannot be combined with another cache or descriptor command');
|
|
45
|
+
return {args:['--prepare-offline',file,...rest]};
|
|
46
|
+
}
|
|
41
47
|
if (!['export', 'import'].includes(operation) || !file || file.startsWith('-'))
|
|
42
48
|
throw new Error('usage: vigievuln cache export|import <file> [options]');
|
|
43
49
|
const allowed = operation === 'export' ? ['--include-config', '--verbose'] : ['--force', '--replace', '--verbose'];
|
|
44
|
-
|
|
50
|
+
for (let i = 0; i < rest.length; i++) {
|
|
51
|
+
const arg = rest[i];
|
|
52
|
+
if (allowed.includes(arg)) continue;
|
|
53
|
+
const match = /^(--config|--source-profile|--proxy-cache)(?:=(.*))?$/.exec(arg);
|
|
54
|
+
if (match) {
|
|
55
|
+
const value = match[2] === undefined ? rest[++i] : match[2];
|
|
56
|
+
if (!value || value.startsWith('-')) throw new Error(`${match[1]} requires a value`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (arg === '--vigievuln-proxy') {
|
|
60
|
+
if (rest[i + 1] && !rest[i + 1].startsWith('-')) {
|
|
61
|
+
if (!['fr', 'com'].includes(rest[++i])) throw new Error('--vigievuln-proxy accepts fr or com');
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (/^--vigievuln-proxy=(fr|com)$/.test(arg)) continue;
|
|
66
|
+
throw new Error('unexpected cache option; see vigievuln cache --help');
|
|
67
|
+
}
|
|
45
68
|
return { args: [`--${operation}-cache`, file, ...rest] };
|
|
46
69
|
}
|
|
47
70
|
return { args };
|
package/lib/cli-groups.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
const DISABLE = {
|
|
19
19
|
report: "report", transitive: "transitive", "all-libs": "allLibs", osv: "osv", nvd: "nvd", "nvd-mirror": "nvdMirror",
|
|
20
20
|
"packagist-audit": "packagistAudit",
|
|
21
|
-
epss: "epss", eol: "eol", kev: "kev", euvd: "euvd", certfr: "certfr", checksums: "checksums", "osv-db": "osvDb",
|
|
21
|
+
epss: "epss", eol: "eol", kev: "kev", euvd: "euvd", gcve: "gcve", certfr: "certfr", checksums: "checksums", "osv-db": "osvDb",
|
|
22
22
|
retire: "retire", "vendored-js-inventory": "vendoredJsInventory",
|
|
23
23
|
maven: "maven", gradle: "gradle", npm: "npm", yarn: "yarn", nuget: "nuget",
|
|
24
24
|
composer: "composer", pypi: "pypi", go: "go", ruby: "ruby",
|
|
@@ -30,7 +30,7 @@ const DISABLE = {
|
|
|
30
30
|
const ACTIVATE = {
|
|
31
31
|
licenses: "licenses", "eol-support": "eolSupport", typosquat: "typosquat", snyk: "snyk",
|
|
32
32
|
"osv-db": "osvDb", "nvd-cpe-match": "nvdCpeMatch", "cve-refresh": "cveRefresh",
|
|
33
|
-
"osv-db-refresh": "osvDbRefresh", "retire-refresh": "retireRefresh", "cve-offline": "cveOffline",
|
|
33
|
+
"osv-db-refresh": "osvDbRefresh", "retire-refresh": "retireRefresh", "cve-offline": "cveOffline", "gcve-offline": "gcveOffline",
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
function parseList(raw) {
|
|
@@ -62,6 +62,35 @@ function applyGroups(options, { disable, activate } = {}) {
|
|
|
62
62
|
return { errors };
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/** Apply group tokens at their own configuration layer, respecting direct flags. */
|
|
66
|
+
function applyLayeredGroups(options, { program, layers = {}, globalStore = {} } = {}) {
|
|
67
|
+
const cli = program.opts();
|
|
68
|
+
const cliSet = name => program.getOptionValueSource(name) === 'cli';
|
|
69
|
+
const entries = [
|
|
70
|
+
{ values: cli, has: cliSet },
|
|
71
|
+
{ values: layers.fileLayer || {}, has(name) { return Object.hasOwn(this.values, name); } },
|
|
72
|
+
{ values: layers.envLayer || {}, has(name) { return Object.hasOwn(this.values, name); } },
|
|
73
|
+
{ values: globalStore || {}, has(name) { return Object.hasOwn(this.values, name); } },
|
|
74
|
+
];
|
|
75
|
+
const errors = [];
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
const expanded = {};
|
|
78
|
+
const result = applyGroups(expanded, {
|
|
79
|
+
disable: entry.has('disable') ? entry.values.disable : undefined,
|
|
80
|
+
activate: entry.has('activate') ? entry.values.activate : undefined,
|
|
81
|
+
});
|
|
82
|
+
entry.expanded = expanded;
|
|
83
|
+
errors.push(...result.errors);
|
|
84
|
+
}
|
|
85
|
+
for (const name of new Set([...Object.values(DISABLE), ...Object.values(ACTIVATE)])) {
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
if (entry.has(name)) break;
|
|
88
|
+
if (Object.hasOwn(entry.expanded, name)) { options[name] = entry.expanded[name]; break; }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { errors };
|
|
92
|
+
}
|
|
93
|
+
|
|
65
94
|
/** Output types, folded into -r. `--report-<type> [file]` still takes an explicit path. */
|
|
66
95
|
const REPORTS = ["html", "doc", "xlsx", "sbom", "csaf", "json", "sarif"];
|
|
67
96
|
|
|
@@ -98,4 +127,4 @@ function foldedFlags() {
|
|
|
98
127
|
];
|
|
99
128
|
}
|
|
100
129
|
|
|
101
|
-
module.exports = { DISABLE, ACTIVATE, REPORTS, ADMIN_FLAGS, parseList, applyGroups, applyReports, foldedFlags };
|
|
130
|
+
module.exports = { DISABLE, ACTIVATE, REPORTS, ADMIN_FLAGS, parseList, applyGroups, applyLayeredGroups, applyReports, foldedFlags };
|
|
@@ -22,7 +22,7 @@ function parse(args) {
|
|
|
22
22
|
}
|
|
23
23
|
return out;
|
|
24
24
|
}
|
|
25
|
-
async function ensureSignedIn({account,store,ask=prompt,interactive=!!(process.stdin.isTTY && process.stderr.isTTY),warn=console.error}) {
|
|
25
|
+
async function ensureSignedIn({account,store,ask=prompt,interactive=!!(process.stdin.isTTY && process.stderr.isTTY),warn=console.error,accountOrigin='https://www.vigievuln.fr'}) {
|
|
26
26
|
if(store.read()) {
|
|
27
27
|
try {
|
|
28
28
|
const result=await account.me(),session=store.read();
|
|
@@ -31,28 +31,69 @@ async function ensureSignedIn({account,store,ask=prompt,interactive=!!(process.s
|
|
|
31
31
|
catch(error) {if(!['UNAUTHORIZED','NOT_AUTHENTICATED','SESSION_EXPIRED'].includes(error.code))throw error;}
|
|
32
32
|
}
|
|
33
33
|
if(!interactive)throw new Error('login required: run vigievuln login in an interactive terminal, then retry');
|
|
34
|
-
warn(
|
|
34
|
+
warn(`Sign in to your Vigie Vuln account at ${accountOrigin}. Register: ${accountOrigin}/account`);
|
|
35
35
|
const email=await ask('Email: '), password=await ask('Password: ',true);
|
|
36
36
|
const result=await account.login({email,password});
|
|
37
37
|
await requireTerms({account,terms:result.terms,ask,interactive,warn});
|
|
38
38
|
return {session:store.read(),account:result.account};
|
|
39
39
|
}
|
|
40
40
|
async function run(args, dependencies={}) {
|
|
41
|
-
const [group,command,...
|
|
41
|
+
const [group,command,...rawRest]=args;
|
|
42
|
+
const rest=rawRest.filter(arg=>arg!=='--allow-insecure-http');
|
|
43
|
+
const allowInsecureHttp=rawRest.includes('--allow-insecure-http');
|
|
44
|
+
if (rawRest.filter(arg=>arg==='--allow-insecure-http').length > 1 || (allowInsecureHttp && group!=='auth')) throw new Error('invalid --allow-insecure-http option');
|
|
42
45
|
if(group==='watch')return require('./cli-watch').runWatch(args.slice(1),{ensureSession:async()=>{
|
|
43
46
|
const store=createAccountSessionStore(),account=createAccountClient({sessionStore:store});
|
|
44
47
|
return (await ensureSignedIn({account,store,...dependencies})).session;
|
|
45
48
|
}});
|
|
46
49
|
if(args.some(a=>a==='--help' || a==='-h') || (group==='auth' && !command)) {
|
|
47
|
-
console.log(group==='auth' ? 'Usage: vigievuln login | logout | whoami\nAliases: auth login | logout | status (also auth whoami).\nLogin
|
|
50
|
+
console.log(group==='auth' ? 'Usage: vigievuln login | logout | whoami\nAliases: auth login | logout | status (also auth whoami).\nLogin selects the official proxy when no proxy is configured.\nMissing/expired sessions require login; an interactive terminal can prompt.'
|
|
48
51
|
: 'Usage: vigievuln project status\n vigievuln project push --file <descriptor> (--name <new project> | --id <existing project>)\nUse watch <dir> --help for local collection and safe project updates.');
|
|
49
52
|
return;
|
|
50
53
|
}
|
|
51
|
-
const store=createAccountSessionStore()
|
|
54
|
+
const store=createAccountSessionStore();
|
|
55
|
+
const config=require('./config');
|
|
56
|
+
const selected=config.get('proxyCache');
|
|
57
|
+
let accountOrigin=require('./account-client').ACCOUNT_ORIGIN;
|
|
58
|
+
if(group==='auth' && selected && !/^(default|vigievuln|https:\/\/api\.vigievuln\.(fr|com)\/?$)$/i.test(selected)) {
|
|
59
|
+
const {proxyOrigin,requireHttpConsent,HTTP_WARNING}=require('./proxy-scope');
|
|
60
|
+
accountOrigin=proxyOrigin(selected);
|
|
61
|
+
if (accountOrigin.startsWith('http://')) {
|
|
62
|
+
const warn=dependencies.warn || console.error;warn(HTTP_WARNING);
|
|
63
|
+
if (!allowInsecureHttp && config.get('insecureHttpOrigin')!==accountOrigin) {
|
|
64
|
+
const interactive=dependencies.interactive ?? !!(process.stdin.isTTY && process.stderr.isTTY);
|
|
65
|
+
if (!interactive) requireHttpConsent(accountOrigin,{acceptedOrigin:config.get('insecureHttpOrigin')});
|
|
66
|
+
const answer=await (dependencies.ask || prompt)(`Allow unencrypted HTTP to ${accountOrigin}? [y/N] `);
|
|
67
|
+
if (!/^y(?:es)?$/i.test(String(answer).trim())) throw new Error('Login cancelled: HTTP connection not approved.');
|
|
68
|
+
config.set('insecureHttpOrigin',accountOrigin);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (group==='auth' && ['login','status','whoami'].includes(command) &&
|
|
73
|
+
accountOrigin!==require('./account-client').ACCOUNT_ORIGIN &&
|
|
74
|
+
!(await (dependencies.authenticationRequired || require('./cli-setup').authenticationRequired)(accountOrigin))) {
|
|
75
|
+
if (rest.length) throw new Error('unexpected authentication option');
|
|
76
|
+
if (command === 'login') config.set('proxyAnonymousOrigin',accountOrigin);
|
|
77
|
+
console.log(`The server at ${accountOrigin} allows anonymous access; login is not required.`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const account=createAccountClient({sessionStore:store,accountOrigin});
|
|
52
81
|
if(group==='auth') {
|
|
53
82
|
if(rest.length)throw new Error('unexpected authentication option');
|
|
54
83
|
if(['login','status','whoami'].includes(command)) {
|
|
55
|
-
const result=await ensureSignedIn({account,store,...dependencies});
|
|
84
|
+
const result=await ensureSignedIn({account,store,accountOrigin,...dependencies});
|
|
85
|
+
if(command==='login' && !selected) {config.set('proxyCache','vigievuln');console.log('Official VigieVuln proxy configured for future scans.');}
|
|
86
|
+
if(command==='login' && accountOrigin===require('./account-client').ACCOUNT_ORIGIN && config.get('proxyCacheTokenOrigin')) {
|
|
87
|
+
config.set('proxyCacheToken',null);config.set('proxyCacheTokenOrigin',null);
|
|
88
|
+
}
|
|
89
|
+
if(command==='login' && accountOrigin!==require('./account-client').ACCOUNT_ORIGIN &&
|
|
90
|
+
(config.get('proxyCacheTokenOrigin')!==accountOrigin || !config.get('proxyCacheToken'))) {
|
|
91
|
+
const key=await account.createProxyKey();config.set('proxyCacheToken',key.token);config.set('proxyCacheTokenOrigin',accountOrigin);
|
|
92
|
+
console.log(`Proxy key saved for ${accountOrigin}.`);
|
|
93
|
+
}
|
|
94
|
+
if(command==='login' && accountOrigin!==require('./account-client').ACCOUNT_ORIGIN && config.get('proxyAnonymousOrigin')===accountOrigin)
|
|
95
|
+
config.set('proxyAnonymousOrigin',null);
|
|
96
|
+
console.log(`Signed in as ${result.account.email}.`);return;
|
|
56
97
|
}
|
|
57
98
|
if(command==='logout') {await account.logout();console.log('Signed out.');return;}
|
|
58
99
|
throw new Error('usage: vigievuln auth login|status|logout');
|