vigievuln 1.1.0 → 1.1.2
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 +13 -0
- package/README.md +18 -11
- package/lib/account-client.js +29 -3
- package/lib/account-session.js +5 -2
- package/lib/account-terms.js +13 -0
- package/lib/cache-archive.js +46 -24
- package/lib/cache-directory.js +77 -0
- package/lib/certfr.js +1 -1
- package/lib/cli-project-commands.js +16 -5
- package/lib/cli-watch.js +2 -1
- package/lib/codecs/composer/registry.js +3 -2
- package/lib/codecs/go/registry.js +1 -1
- package/lib/codecs/maven/jar-scan.js +25 -17
- package/lib/codecs/npm/registry.js +1 -1
- package/lib/codecs/nuget/registry.js +3 -2
- package/lib/codecs/pypi/parse.js +15 -8
- package/lib/codecs/pypi/registry.js +3 -2
- package/lib/codecs/pypi.codec.js +1 -1
- package/lib/codecs/ruby/registry.js +1 -1
- package/lib/config.js +1 -1
- package/lib/cve-download.js +1 -1
- package/lib/cve-report.js +3 -1
- package/lib/epss.js +1 -1
- package/lib/euvd.js +1 -1
- package/lib/hash-id.js +1 -1
- package/lib/hosted-proxy.js +19 -17
- package/lib/kev.js +5 -2
- package/lib/nvd.js +1 -1
- package/lib/options-env.js +4 -5
- package/lib/osv-db.js +1 -1
- package/lib/osv.js +1 -1
- package/lib/outdated.js +1 -1
- package/lib/packagist-audit.js +5 -3
- package/lib/project-client.js +15 -4
- package/lib/provenance.js +1 -1
- package/lib/proxy-cache.js +14 -4
- package/lib/resource-cache/fs-store.js +1 -1
- package/lib/resource-cache/validate.js +3 -1
- package/lib/retire.js +17 -8
- package/lib/transitive.js +1 -1
- package/package.json +3 -3
- package/vigievuln.js +41 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog — VigieVuln
|
|
2
2
|
|
|
3
|
+
## [1.1.2] — Unreleased
|
|
4
|
+
|
|
5
|
+
- Fix Windows account sessions when the home directory uses an 8.3 short path, including GitHub Actions temporary directories.
|
|
6
|
+
- Require explicit `--config` for repository configuration and bound Composer validation and JAR decompression.
|
|
7
|
+
- Reject cache archives containing links and keep Python requirements includes inside the scan root.
|
|
8
|
+
- Harden local proxy access and surface failed data sources as incomplete coverage.
|
|
9
|
+
|
|
10
|
+
## [1.1.1] — 2026-10-28
|
|
11
|
+
|
|
12
|
+
- Review and explicitly accept the current service terms when a hosted account requires it.
|
|
13
|
+
- Refuse project descriptors larger than 500,000 UTF-8 bytes before upload.
|
|
14
|
+
- Document the renewable one-month free project watch and its expiry.
|
|
15
|
+
|
|
3
16
|
## [1.1.0] — 2026-10-28
|
|
4
17
|
|
|
5
18
|
- Hosted proxy scans query CVE, KEV, EUVD and CERT-FR records by dependency or CVE instead of downloading bulk catalogues.
|
package/README.md
CHANGED
|
@@ -46,10 +46,13 @@ It scans **10 ecosystems + 9 CMS/Frameworks** (WordPress, Drupal, Symfony, Larav
|
|
|
46
46
|
## Migration from fad-checker
|
|
47
47
|
|
|
48
48
|
The npm package and primary command are now `vigievuln`. Existing `fad` and
|
|
49
|
-
`fad-checker` commands remain aliases. The cache
|
|
50
|
-
existing
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
`fad-checker` commands remain aliases. The default cache and configuration directory is `~/.vigie-vuln/`. If it does not exist, an existing `~/.fad-checker/` is automatically renamed to it. If the new directory already exists, it is kept. If the rename fails, a new directory is created and execution continues; the old directory is not merged.
|
|
50
|
+
The separate shared proxy cache similarly migrates from `~/.fad-checker-proxy-cache/` to `~/.vigie-vuln-proxy-cache/` without merging or overwriting an existing new directory. If either rename fails, the CLI warns you, preserves the old directory and uses a new one. Existing cache archives made with `.fad-checker` remain importable.
|
|
51
|
+
|
|
52
|
+
To recover a failed migration, stop the CLI and proxy server, back up and move the new directory out of the way, then rename the old directory to the new name. Remove the corresponding sibling marker, `~/.vigie-vuln.migration-pending` or `~/.vigie-vuln-proxy-cache.migration-pending`, after recovery. Do not overwrite or merge the directories. While both the marker and old directory exist, the warning repeats once per process; if the marker could not be created, only the immediate warning is assured.
|
|
53
|
+
`VIGIEVULN_ENV` takes precedence over the legacy `FAD_CHECKER_ENV`. Project
|
|
54
|
+
configuration is loaded only when explicitly selected with `--config` and must be trusted.
|
|
55
|
+
Default report output is now
|
|
53
56
|
`./vigievuln-report`; pass `-o` to retain another location.
|
|
54
57
|
|
|
55
58
|
## Quick start
|
|
@@ -63,7 +66,7 @@ A free [NVD API key](https://nvd.nist.gov/developers/request-an-api-key) (instan
|
|
|
63
66
|
|
|
64
67
|
### Monitor a project
|
|
65
68
|
|
|
66
|
-
Create and verify your [account](https://www.vigievuln.fr/account), then:
|
|
69
|
+
Create and verify your [account](https://www.vigievuln.fr/account), then sign in and explicitly accept the [terms of service dated 2026-10-28](https://www.vigievuln.fr/terms) when prompted:
|
|
67
70
|
|
|
68
71
|
```bash
|
|
69
72
|
vigievuln login
|
|
@@ -75,7 +78,11 @@ vigievuln logout
|
|
|
75
78
|
|
|
76
79
|
`watch` collects the inventory locally and uploads it once. Run it again with the same unique project name to update that project's inventory; it does not run a background watcher. `login` creates an account session and does not configure the proxy cache.
|
|
77
80
|
|
|
78
|
-
The free tier includes **one project and up to 100 distinct direct dependency coordinates per project**. Multiple versions of the same coordinate count once. Dependencies whose direct relationship cannot be established are excluded from monitoring and reported as incomplete coverage.
|
|
81
|
+
The free tier includes **one project and up to 100 distinct direct dependency coordinates per project**. Multiple versions of the same coordinate count once. An uploaded descriptor may be at most **500,000 bytes (0.5 MB decimal)**; an upload exceeding this size or 100 distinct direct coordinates is rejected with an error. Dependencies whose direct relationship cannot be established are excluded from monitoring and reported as incomplete coverage. These limits apply to hosted monitoring, not local scans.
|
|
82
|
+
|
|
83
|
+
Free monitoring expires **one calendar month (UTC)** after a successful `watch` upload. Each successful upload, including a project API push, renews the period for one calendar month (UTC). At expiry, the hosted project and its monitoring data are purged and an expiry email is sent; the account remains. Copies in backups are not deleted immediately.
|
|
84
|
+
|
|
85
|
+
If the current terms have not been accepted, the CLI displays their link and asks for explicit acceptance in an interactive terminal. For non-interactive use, run `vigievuln login` interactively and accept the terms first.
|
|
79
86
|
|
|
80
87
|
To review the inventory before uploading, export it locally:
|
|
81
88
|
|
|
@@ -83,7 +90,7 @@ To review the inventory before uploading, export it locally:
|
|
|
83
90
|
vigievuln watch ./project --export fichier.json
|
|
84
91
|
```
|
|
85
92
|
|
|
86
|
-
`--export` only writes the descriptor: it runs offline, requires no login
|
|
93
|
+
`--export` only writes the descriptor: it runs offline, requires no login, sends nothing to the service and does not renew monitoring. Review package names and versions, including private packages, before uploading. Source code, paths and registry URLs are omitted from the descriptor.
|
|
87
94
|
|
|
88
95
|
Monitoring establishes a silent initial baseline, then reports new high or critical vulnerabilities (CVSS ≥ 7) and known exploited vulnerabilities affecting direct dependencies. Enable alerts in your account and refresh the inventory when dependencies change. [Monitoring workflow and compatibility commands](docs/USAGE.md#project-monitoring).
|
|
89
96
|
|
|
@@ -98,7 +105,7 @@ vigievuln --set-proxy-cache vigievuln # `default` selects the same official pro
|
|
|
98
105
|
vigievuln scan ./code
|
|
99
106
|
```
|
|
100
107
|
|
|
101
|
-
The selection and the proxy key created during proxy sign-in are saved in `~/.
|
|
108
|
+
The selection and the proxy key created during proxy sign-in are saved in `~/.vigie-vuln/config.json` and reused on subsequent scans. This proxy key is separate from the account session used by `watch`. Alternatively, save an existing key with `vigievuln --set-proxy-cache-token <key>`, or provide it via `VIGIEVULN_PROXY_CACHE_TOKEN` (useful in CI). Remove the selection or key with `--unset-proxy-cache` or `--unset-proxy-cache-token`. `--proxy-cache <url>` overrides the saved selection for one scan. The hosted proxy receives requested package coordinates and CVE identifiers; it does not receive your source code. [Proxy documentation](docs/USAGE.md#hosted-vigievuln-proxy).
|
|
102
109
|
|
|
103
110
|
### Interactive HTML samples
|
|
104
111
|
|
|
@@ -200,12 +207,12 @@ vigievuln doesn't just read the `composer.json` under a WordPress or Drupal site
|
|
|
200
207
|
| **SPIP** | core (`$spip_version_branche` in `ecrire/inc_version.php`), dist plugins (`paquet.xml`), user plugins (`paquet.xml`/legacy `plugin.xml`) | **NVD product CVEs** (`cpe:2.3:a:spip:spip`) — the only machine-readable SPIP source; plugins stay honestly not-qualified |
|
|
201
208
|
| **Joomla / Magento (Adobe Commerce)** | core, extensions/modules, themes | no machine-readable publisher feed exists; components locked as Composer packages read as covered by the **dependency lanes**, the rest stays honestly **not qualified**. A Magento source distribution reports its exact version from the root `composer.json` |
|
|
202
209
|
|
|
203
|
-
Every advisory snapshot a live lane fetches is stamped and cached in `~/.
|
|
210
|
+
Every advisory snapshot a live lane fetches is stamped and cached in `~/.vigie-vuln/advisory-snapshots/`, carried by `--export-cache`/`--import-cache`, **warmed from the air-gapped descriptor itself** by `--import-anonymized`, and reused automatically offline — the Wordfence API key never travels to the enclave. Private/custom components are inventoried separately and never sent to any publisher. → **[the dedicated guide](docs/CMS-FRAMEWORKS.md)** · [application usage](docs/USAGE.md#application-inventory-experimental)
|
|
204
211
|
|
|
205
212
|
## Air-gapped audits
|
|
206
213
|
|
|
207
214
|
> **Zero-data-sent guarantee.** Under `--offline`, vigievuln makes **no network calls
|
|
208
|
-
> whatsoever**; it reads only the warmed `~/.
|
|
215
|
+
> whatsoever**; it reads only the warmed `~/.vigie-vuln/` caches and never transmits a
|
|
209
216
|
> dependency, path or finding off the machine. It is regression-tested
|
|
210
217
|
> (`test/offline-guarantee.test.js`, a tripwire fetcher that throws if touched) and
|
|
211
218
|
> auditor-reproducible: `unshare -rn node vigievuln.js -s ./proj --offline …` runs it in a
|
|
@@ -235,7 +242,7 @@ vigievuln -s ./proj -e "^(client|internal)\." --export-anonymized deps.json
|
|
|
235
242
|
vigievuln --import-anonymized deps.json # scans coordinates → OSV/NVD/CVE/registry/EOL + retire signatures
|
|
236
243
|
# + warms the CMS advisory snapshots (Drupal/PrestaShop/TYPO3 feeds,
|
|
237
244
|
# WP checksums per core version, Wordfence when a key is set)
|
|
238
|
-
vigievuln --export-cache fad-cache.tar.gz # bundle the warmed ~/.
|
|
245
|
+
vigievuln --export-cache fad-cache.tar.gz # bundle the warmed ~/.vigie-vuln/
|
|
239
246
|
|
|
240
247
|
# ── Phase 3; OFFLINE (audited machine): full report, all local context ──
|
|
241
248
|
vigievuln --import-cache fad-cache.tar.gz # merged into the enclave's own cache
|
package/lib/account-client.js
CHANGED
|
@@ -18,6 +18,18 @@ class AccountClientError extends Error {
|
|
|
18
18
|
const invalidResponse = () => new AccountClientError('INVALID_RESPONSE', 'Invalid account API response.');
|
|
19
19
|
const isAccount = value => value && typeof value === 'object' && !Array.isArray(value) &&
|
|
20
20
|
typeof value.id === 'string' && value.id.length > 0 && typeof value.email === 'string' && value.email.length > 0;
|
|
21
|
+
function readTerms(value) {
|
|
22
|
+
if (!value || typeof value !== 'object' || Array.isArray(value) ||
|
|
23
|
+
typeof value.version !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/.test(value.version) ||
|
|
24
|
+
typeof value.documentUrl !== 'string' || value.documentUrl.length > 2048 ||
|
|
25
|
+
/[\x00-\x20\x7f]/.test(value.documentUrl) || typeof value.accepted !== 'boolean') throw invalidResponse();
|
|
26
|
+
let url;
|
|
27
|
+
try { url = new URL(value.documentUrl, ACCOUNT_ORIGIN); } catch { throw invalidResponse(); }
|
|
28
|
+
if (url.protocol !== 'https:' || url.origin !== ACCOUNT_ORIGIN || url.username || url.password ||
|
|
29
|
+
url.pathname !== '/terms/' + value.version || url.search || url.hash ||
|
|
30
|
+
![url.pathname, ACCOUNT_ORIGIN + url.pathname].includes(value.documentUrl)) throw invalidResponse();
|
|
31
|
+
return { version: value.version, url: url.href, accepted: value.accepted };
|
|
32
|
+
}
|
|
21
33
|
|
|
22
34
|
/**
|
|
23
35
|
* Account authentication for future project commands; no proxy config or keys.
|
|
@@ -118,13 +130,14 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
118
130
|
try { session = validateAccountSession(data, now()); }
|
|
119
131
|
catch { throw invalidResponse(); }
|
|
120
132
|
if (data.tokenType !== 'Bearer' || !isAccount(data.account)) throw invalidResponse();
|
|
133
|
+
const terms = readTerms(data.account.terms);
|
|
121
134
|
try { await sessionStore.write(session); }
|
|
122
135
|
catch (error) {
|
|
123
136
|
// Avoid leaving a newly issued session alive when local persistence fails.
|
|
124
137
|
try { await request('logout', 'POST', {}, session.token); } catch { /* expires server-side */ }
|
|
125
138
|
throw error;
|
|
126
139
|
}
|
|
127
|
-
return { account: data.account, expiresAt: session.expiresAt };
|
|
140
|
+
return { account: data.account, expiresAt: session.expiresAt, ...(terms && { terms }) };
|
|
128
141
|
}
|
|
129
142
|
|
|
130
143
|
async function me() {
|
|
@@ -132,13 +145,26 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
132
145
|
try {
|
|
133
146
|
const data = await request('me', 'GET', undefined, session.token);
|
|
134
147
|
if (!isAccount(data.account)) throw invalidResponse();
|
|
135
|
-
|
|
148
|
+
const terms = readTerms(data.account.terms);
|
|
149
|
+
return { account: data.account, ...(terms && { terms }) };
|
|
136
150
|
} catch (error) {
|
|
137
151
|
if (error.code === 'UNAUTHORIZED') await sessionStore.clear();
|
|
138
152
|
throw error;
|
|
139
153
|
}
|
|
140
154
|
}
|
|
141
155
|
|
|
156
|
+
async function acceptTerms(version) {
|
|
157
|
+
if (typeof version !== 'string' || !version || version.length > 200 || /[\x00-\x1f\x7f]/.test(version)) {
|
|
158
|
+
throw new AccountClientError('INVALID_TERMS', 'A valid terms version is required.');
|
|
159
|
+
}
|
|
160
|
+
const session = await currentSession();
|
|
161
|
+
const data = await request('terms', 'POST', { termsVersion: version, accepted: true }, session.token);
|
|
162
|
+
if (!isAccount(data.account)) throw invalidResponse();
|
|
163
|
+
const terms = readTerms(data.account.terms);
|
|
164
|
+
if (!terms || !terms.accepted || terms.version !== version) throw invalidResponse();
|
|
165
|
+
return { terms };
|
|
166
|
+
}
|
|
167
|
+
|
|
142
168
|
async function createProxyKey() {
|
|
143
169
|
const session = await currentSession();
|
|
144
170
|
const data = await request('proxy-keys', 'POST', { name: 'VigieVuln CLI' }, session.token);
|
|
@@ -159,7 +185,7 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
159
185
|
} finally { await sessionStore.clear(); }
|
|
160
186
|
}
|
|
161
187
|
|
|
162
|
-
return { login, logout, me, createProxyKey };
|
|
188
|
+
return { login, logout, me, createProxyKey, acceptTerms };
|
|
163
189
|
}
|
|
164
190
|
|
|
165
191
|
module.exports = { ACCOUNT_ORIGIN, DEFAULT_TIMEOUT_MS, createAccountClient, AccountClientError };
|
package/lib/account-session.js
CHANGED
|
@@ -304,9 +304,12 @@ public static class VigieVulnSession {
|
|
|
304
304
|
static object Execute(Dictionary<string, object> request) {
|
|
305
305
|
string operation = (string)request["operation"], home = (string)request["homeDir"];
|
|
306
306
|
if (operation != "read" && operation != "write" && operation != "clear") IO();
|
|
307
|
-
// Reject UNC/device paths
|
|
307
|
+
// Reject UNC/device paths and alternate streams. Windows may supply an
|
|
308
|
+
// 8.3 short path (notably TEMP on GitHub runners); expand it before
|
|
309
|
+
// checking every component and the private directory by handle.
|
|
308
310
|
if (!System.Text.RegularExpressions.Regex.IsMatch(home, @"^[A-Za-z]:\\") || home.IndexOf(':', 2) >= 0 ||
|
|
309
|
-
home.IndexOf('/') >= 0 || home.IndexOf('\0') >= 0
|
|
311
|
+
home.IndexOf('/') >= 0 || home.IndexOf('\0') >= 0) Unsafe();
|
|
312
|
+
home = Path.GetFullPath(home);
|
|
310
313
|
string root = home.Substring(0, 3);
|
|
311
314
|
uint serial, component, flags;
|
|
312
315
|
StringBuilder format = new StringBuilder(32);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
async function requireTerms({account, terms, ask, interactive = !!(process.stdin.isTTY && process.stderr.isTTY), warn = console.error}) {
|
|
4
|
+
if (!terms) throw new Error('unable to verify current terms; please retry or contact support');
|
|
5
|
+
if (terms.accepted) return;
|
|
6
|
+
warn(`Vigie Vuln terms of service (version ${terms.version}): ${terms.url}`);
|
|
7
|
+
if (!interactive) throw new Error('terms acceptance required: run vigievuln login in an interactive terminal, then retry');
|
|
8
|
+
const answer = await ask('Accept these terms? Type yes to accept: ');
|
|
9
|
+
if (typeof answer !== 'string' || answer.trim().toLowerCase() !== 'yes')
|
|
10
|
+
throw new Error('terms not accepted; run vigievuln login to review them');
|
|
11
|
+
await account.acceptTerms(terms.version);
|
|
12
|
+
}
|
|
13
|
+
module.exports = { requireTerms };
|
package/lib/cache-archive.js
CHANGED
|
@@ -29,7 +29,7 @@ const { execFile, spawn } = require("child_process");
|
|
|
29
29
|
const { promisify } = require("util");
|
|
30
30
|
const execFileP = promisify(execFile);
|
|
31
31
|
|
|
32
|
-
const FAD_CACHE_DIR =
|
|
32
|
+
const FAD_CACHE_DIR = require("./cache-directory").getCacheDir({homeDir:os.homedir()});
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Files inside ~/.fad-checker/ that hold secrets and should NOT be shipped by default.
|
|
@@ -210,7 +210,7 @@ async function runTar(args, archive, cwd, writing, verbose) {
|
|
|
210
210
|
|
|
211
211
|
async function exportCache(destFile, opts = {}) {
|
|
212
212
|
const { verbose, includeConfig } = opts;
|
|
213
|
-
if (!fs.existsSync(FAD_CACHE_DIR)) throw new Error(`no ~/.
|
|
213
|
+
if (!fs.existsSync(FAD_CACHE_DIR)) throw new Error(`no ~/.vigie-vuln/ directory to export`);
|
|
214
214
|
const abs = path.resolve(destFile);
|
|
215
215
|
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
216
216
|
|
|
@@ -284,33 +284,55 @@ async function importCache(srcFile, opts = {}) {
|
|
|
284
284
|
const replace = !!(opts.replace || force);
|
|
285
285
|
const abs = path.resolve(srcFile);
|
|
286
286
|
if (!fs.existsSync(abs)) throw new Error(`archive not found: ${abs}`);
|
|
287
|
-
const parent = path.dirname(FAD_CACHE_DIR);
|
|
288
|
-
|
|
289
|
-
if (replace) {
|
|
290
|
-
if (fs.existsSync(FAD_CACHE_DIR) && !force) {
|
|
291
|
-
// Move existing aside as .fad-checker.bak-<timestamp>
|
|
292
|
-
const backup = `${FAD_CACHE_DIR}.bak-${Date.now()}`;
|
|
293
|
-
fs.renameSync(FAD_CACHE_DIR, backup);
|
|
294
|
-
if (verbose) console.log(`💾 existing ~/.fad-checker/ moved to ${backup}`);
|
|
295
|
-
} else if (force && fs.existsSync(FAD_CACHE_DIR)) {
|
|
296
|
-
fs.rmSync(FAD_CACHE_DIR, { recursive: true, force: true });
|
|
297
|
-
if (verbose) console.log(`🗑 --force: existing ~/.fad-checker/ removed`);
|
|
298
|
-
}
|
|
299
|
-
await extractTo(abs, parent, verbose);
|
|
300
|
-
if (!fs.existsSync(FAD_CACHE_DIR)) {
|
|
301
|
-
throw new Error(`import completed but ~/.fad-checker/ was not created — was the archive built with vigievuln --export-cache?`);
|
|
302
|
-
}
|
|
303
|
-
return { dir: FAD_CACHE_DIR, mode: "replace" };
|
|
304
|
-
}
|
|
305
287
|
|
|
306
288
|
// Merge: unpack beside the cache (same filesystem), reconcile, drop the staging dir.
|
|
307
|
-
|
|
289
|
+
fs.mkdirSync(path.dirname(FAD_CACHE_DIR), { recursive: true });
|
|
290
|
+
const staging = fs.mkdtempSync(`${FAD_CACHE_DIR}.import-`);
|
|
308
291
|
const stats = { added: 0, updated: 0, merged: 0, kept: 0, skipped: [] };
|
|
309
292
|
try {
|
|
310
293
|
await extractTo(abs, staging, verbose);
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
294
|
+
// Never promote links or special files into a live cache, including in
|
|
295
|
+
// replace mode. A later cache write could otherwise escape the cache root.
|
|
296
|
+
const inspect = dir => {
|
|
297
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
298
|
+
const file = path.join(dir, entry), st = fs.lstatSync(file);
|
|
299
|
+
if (st.isSymbolicLink() || (!st.isDirectory() && (!st.isFile() || st.nlink !== 1)))
|
|
300
|
+
throw new Error("archive contains links or special files");
|
|
301
|
+
if (st.isDirectory()) inspect(file);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
inspect(staging);
|
|
305
|
+
const modern = path.join(staging, path.basename(FAD_CACHE_DIR));
|
|
306
|
+
const legacy = path.join(staging, '.fad-checker');
|
|
307
|
+
// Windows Compress-Archive historically emitted the cache contents at
|
|
308
|
+
// the ZIP root, whereas tar and Unix ZIP preserve the directory name.
|
|
309
|
+
const flatWindowsZip = process.platform === 'win32' && abs.toLowerCase().endsWith('.zip');
|
|
310
|
+
const incoming = fs.existsSync(modern) ? modern : fs.existsSync(legacy) ? legacy : flatWindowsZip ? staging : legacy;
|
|
311
|
+
if (!fs.existsSync(incoming) || !fs.lstatSync(incoming).isDirectory()) {
|
|
312
|
+
throw new Error(`archive holds no .vigie-vuln/ or .fad-checker/ directory — was it built with vigievuln --export-cache?`);
|
|
313
|
+
}
|
|
314
|
+
if (replace) {
|
|
315
|
+
// Configuration contains machine-local credentials and is never
|
|
316
|
+
// accepted from an imported archive, even for a replacement.
|
|
317
|
+
for (const name of NEVER_IMPORT) {
|
|
318
|
+
const src = path.join(FAD_CACHE_DIR, name), dst = path.join(incoming, name);
|
|
319
|
+
fs.rmSync(dst, { force: true });
|
|
320
|
+
if (fs.existsSync(src)) {
|
|
321
|
+
const st = fs.lstatSync(src);
|
|
322
|
+
if (!st.isFile() || st.isSymbolicLink() || st.nlink !== 1) throw new Error('unsafe local cache configuration');
|
|
323
|
+
fs.copyFileSync(src, dst, fs.constants.COPYFILE_EXCL);
|
|
324
|
+
try { fs.chmodSync(dst, 0o600); } catch { /* platform does not support chmod */ }
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (fs.existsSync(FAD_CACHE_DIR) && !force) {
|
|
328
|
+
const backup = `${FAD_CACHE_DIR}.bak-${Date.now()}`;
|
|
329
|
+
fs.renameSync(FAD_CACHE_DIR, backup);
|
|
330
|
+
if (verbose) console.log(`💾 existing ~/.vigie-vuln/ moved to ${backup}`);
|
|
331
|
+
} else if (force && fs.existsSync(FAD_CACHE_DIR)) {
|
|
332
|
+
fs.rmSync(FAD_CACHE_DIR, {recursive:true, force:true});
|
|
333
|
+
}
|
|
334
|
+
fs.renameSync(incoming, FAD_CACHE_DIR);
|
|
335
|
+
return {dir:FAD_CACHE_DIR, mode:'replace'};
|
|
314
336
|
}
|
|
315
337
|
fs.mkdirSync(FAD_CACHE_DIR, { recursive: true });
|
|
316
338
|
mergeTree(incoming, FAD_CACHE_DIR, stats);
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
|
|
8
|
+
// The cache is separate from account sessions and from the proxy server store.
|
|
9
|
+
function resolveDirectory(currentName, legacyName, {homeDir = os.homedir(), fsImpl = fs, platform = process.platform, spawn = spawnSync, warn = console.error} = {}) {
|
|
10
|
+
const current = path.join(homeDir, currentName);
|
|
11
|
+
const legacy = path.join(homeDir, legacyName);
|
|
12
|
+
const marker = path.join(homeDir, currentName + '.migration-pending');
|
|
13
|
+
const stat = file => {
|
|
14
|
+
try { return fsImpl.lstatSync(file); }
|
|
15
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
16
|
+
};
|
|
17
|
+
const checkCurrent = () => {
|
|
18
|
+
const entry = stat(current);
|
|
19
|
+
if (entry && (entry.isSymbolicLink() || !entry.isDirectory()))
|
|
20
|
+
throw new Error('VigieVuln cache directory must be a directory, not a symbolic link');
|
|
21
|
+
return entry;
|
|
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;
|
|
74
|
+
}
|
|
75
|
+
const getCacheDir = options => resolveDirectory('.vigie-vuln', '.fad-checker', options);
|
|
76
|
+
const getProxyCacheDir = options => resolveDirectory('.vigie-vuln-proxy-cache', '.fad-checker-proxy-cache', options);
|
|
77
|
+
module.exports = {getCacheDir, getProxyCacheDir};
|
package/lib/certfr.js
CHANGED
|
@@ -20,7 +20,7 @@ const fs = require("fs");
|
|
|
20
20
|
const path = require("path");
|
|
21
21
|
const os = require("os");
|
|
22
22
|
|
|
23
|
-
const DEFAULT_CACHE_DIR = path.join(
|
|
23
|
+
const DEFAULT_CACHE_DIR = path.join(require("./cache-directory").getCacheDir());
|
|
24
24
|
const CACHE_FILE = "certfr-cache.json";
|
|
25
25
|
const CACHE_TTL_MS = 24 * 3600 * 1000;
|
|
26
26
|
const KINDS = ["avis", "alerte"];
|
|
@@ -3,8 +3,9 @@ const fs=require("node:fs");
|
|
|
3
3
|
const readline=require("node:readline");
|
|
4
4
|
const {Writable}=require("node:stream");
|
|
5
5
|
const {createAccountClient}=require("./account-client");
|
|
6
|
+
const {requireTerms}=require("./account-terms");
|
|
6
7
|
const {createAccountSessionStore}=require("./account-session");
|
|
7
|
-
const {projectRequest,createProject,updateProject}=require("./project-client");
|
|
8
|
+
const {projectRequest,createProject,updateProject,sanitizeDescriptor,checkDescriptorSize,MAX_DESCRIPTOR_BYTES}=require("./project-client");
|
|
8
9
|
|
|
9
10
|
function prompt(label,secret=false) {
|
|
10
11
|
if (!process.stdin.isTTY || !process.stderr.isTTY) throw new Error("interactive login requires a terminal");
|
|
@@ -25,7 +26,7 @@ async function ensureSignedIn({account,store,ask=prompt,interactive=!!(process.s
|
|
|
25
26
|
if(store.read()) {
|
|
26
27
|
try {
|
|
27
28
|
const result=await account.me(),session=store.read();
|
|
28
|
-
if(session)return {session,account:result.account};
|
|
29
|
+
if(session){await requireTerms({account,terms:result.terms,ask,interactive,warn});return {session,account:result.account};}
|
|
29
30
|
}
|
|
30
31
|
catch(error) {if(!['UNAUTHORIZED','NOT_AUTHENTICATED','SESSION_EXPIRED'].includes(error.code))throw error;}
|
|
31
32
|
}
|
|
@@ -33,6 +34,7 @@ async function ensureSignedIn({account,store,ask=prompt,interactive=!!(process.s
|
|
|
33
34
|
warn('Sign in to your Vigie Vuln account. Register: https://www.vigievuln.fr/account');
|
|
34
35
|
const email=await ask('Email: '), password=await ask('Password: ',true);
|
|
35
36
|
const result=await account.login({email,password});
|
|
37
|
+
await requireTerms({account,terms:result.terms,ask,interactive,warn});
|
|
36
38
|
return {session:store.read(),account:result.account};
|
|
37
39
|
}
|
|
38
40
|
async function run(args, dependencies={}) {
|
|
@@ -60,6 +62,18 @@ async function run(args, dependencies={}) {
|
|
|
60
62
|
if(command!=='status' && (command!=='push' || !opts['--file'] || (!!opts['--name'] === !!opts['--id'])))
|
|
61
63
|
throw new Error('usage: vigievuln project push --file <descriptor> (--name <new project> | --id <existing project>)');
|
|
62
64
|
if(command==='status' && Object.keys(opts).length)throw new Error('project status takes no options');
|
|
65
|
+
let descriptor;
|
|
66
|
+
if(command==='push') {
|
|
67
|
+
const stat=fs.statSync(opts['--file']);
|
|
68
|
+
if(!stat.isFile())throw new Error('invalid descriptor file');
|
|
69
|
+
if(stat.size>MAX_DESCRIPTOR_BYTES)throw new Error(`project descriptor exceeds the upload limit of ${MAX_DESCRIPTOR_BYTES} UTF-8 bytes`);
|
|
70
|
+
const bytes=fs.readFileSync(opts['--file']);
|
|
71
|
+
if(bytes.length>MAX_DESCRIPTOR_BYTES)throw new Error(`project descriptor exceeds the upload limit of ${MAX_DESCRIPTOR_BYTES} UTF-8 bytes`);
|
|
72
|
+
try {descriptor=JSON.parse(bytes.toString('utf8'));}
|
|
73
|
+
catch {throw new Error('unable to read project descriptor as JSON');}
|
|
74
|
+
checkDescriptorSize(descriptor);
|
|
75
|
+
checkDescriptorSize(sanitizeDescriptor(descriptor));
|
|
76
|
+
}
|
|
63
77
|
const {session}=await ensureSignedIn({account,store,...dependencies});
|
|
64
78
|
if(command==='status') {
|
|
65
79
|
const data=await projectRequest('/v1/projects',{session:session.token});
|
|
@@ -67,9 +81,6 @@ async function run(args, dependencies={}) {
|
|
|
67
81
|
for(const p of data.projects)console.log(`${p.id}\t${p.name}\trevision ${p.revision}`);
|
|
68
82
|
if(!data.projects.length)console.log('No projects.');return;
|
|
69
83
|
}
|
|
70
|
-
const stat=fs.statSync(opts['--file']);if(!stat.isFile() || stat.size>1900000)throw new Error('invalid or oversized descriptor file');
|
|
71
|
-
let descriptor;try {descriptor=JSON.parse(fs.readFileSync(opts['--file'],'utf8'));}
|
|
72
|
-
catch {throw new Error('unable to read project descriptor as JSON');}
|
|
73
84
|
console.error('Project coordinates and versions will be stored on the service. Review and exclude private packages before uploading.');
|
|
74
85
|
let result;
|
|
75
86
|
if(opts['--name']) result=await createProject({session:session.token,name:opts['--name'],descriptor});
|
package/lib/cli-watch.js
CHANGED
|
@@ -3,7 +3,7 @@ const fs = require('node:fs');
|
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
const { Command } = require('commander');
|
|
5
5
|
const { buildProjectDescriptor } = require('./project-descriptor');
|
|
6
|
-
const { sanitizeDescriptor, projectRequest, createProject, updateProject } = require('./project-client');
|
|
6
|
+
const { sanitizeDescriptor, checkDescriptorSize, projectRequest, createProject, updateProject } = require('./project-client');
|
|
7
7
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
8
|
|
|
9
9
|
function watchCommand() {
|
|
@@ -79,6 +79,7 @@ async function runWatch(args, { ensureSession, log = console.log, warn = console
|
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
if (!descriptor.deps.length) throw new Error('no dependencies collected; refusing to upload an empty project inventory');
|
|
82
|
+
checkDescriptorSize(descriptor);
|
|
82
83
|
const session = await ensureSession();
|
|
83
84
|
let current;
|
|
84
85
|
const validateProject = p => p && UUID.test(p.id) && typeof p.name === 'string' && Number.isSafeInteger(p.revision) && p.revision > 0;
|
|
@@ -18,7 +18,7 @@ let pLimit; try { pLimit = require("p-limit"); } catch { pLimit = () => (fn) =>
|
|
|
18
18
|
const { authHeaderFor, normalise } = require("../../registries");
|
|
19
19
|
const { belongsToOtherComposerRegistry } = require("../../packagist-audit");
|
|
20
20
|
|
|
21
|
-
const CACHE_DIR = path.join(
|
|
21
|
+
const CACHE_DIR = path.join(require("../../cache-directory").getCacheDir());
|
|
22
22
|
const CACHE_PATH = path.join(CACHE_DIR, "packagist-cache.json");
|
|
23
23
|
const CACHE_MAX_AGE_MS = 24 * 3600 * 1000;
|
|
24
24
|
const API = "https://packagist.org/packages";
|
|
@@ -74,6 +74,7 @@ function composerV2ToPackageObject(json, name) {
|
|
|
74
74
|
// public Packagist rich API (packages/<name>.json). Per-registry Basic/Bearer auth.
|
|
75
75
|
async function fetchPackage(name, { offline, registries = [], fetcher = globalThis.fetch } = {}) {
|
|
76
76
|
if (offline) return null;
|
|
77
|
+
if (typeof name !== 'string' || name.length > 200 || !/^[a-z0-9]+(?:[_.-][a-z0-9]+)*\/[a-z0-9]+(?:(?:[_.]|-{1,2})[a-z0-9]+)*$/i.test(name)) return { error: 'invalid package name', absent: false };
|
|
77
78
|
let lastErr = null;
|
|
78
79
|
const statuses = []; // one per base: HTTP status, or null for a non-answer
|
|
79
80
|
for (const base of registries || []) {
|
|
@@ -81,7 +82,7 @@ async function fetchPackage(name, { offline, registries = [], fetcher = globalTh
|
|
|
81
82
|
const ah = authHeaderFor(base); if (ah) headers.Authorization = ah;
|
|
82
83
|
try {
|
|
83
84
|
const res = await require("../../providers").getResource("packagist", "p2", { name },
|
|
84
|
-
{ fetcher, headers, urlOverride: `${normalise(base.url)}p2/${name}.json`, direct: true });
|
|
85
|
+
{ fetcher, headers, urlOverride: `${normalise(base.url)}p2/${String(name).split('/').map(encodeURIComponent).join('/')}.json`, direct: true });
|
|
85
86
|
if (res.ok) return composerV2ToPackageObject(await res.json(), name);
|
|
86
87
|
lastErr = `HTTP ${res.status}`;
|
|
87
88
|
statuses.push(res.status);
|
|
@@ -16,7 +16,7 @@ const os = require("os");
|
|
|
16
16
|
let pLimit; try { pLimit = require("p-limit"); } catch { pLimit = () => (fn) => fn(); }
|
|
17
17
|
const { withPublic, authHeaderFor, normalise } = require("../../registries");
|
|
18
18
|
|
|
19
|
-
const CACHE_DIR = path.join(
|
|
19
|
+
const CACHE_DIR = path.join(require("../../cache-directory").getCacheDir());
|
|
20
20
|
const CACHE_PATH = path.join(CACHE_DIR, "go-proxy-cache.json");
|
|
21
21
|
const CACHE_MAX_AGE_MS = 24 * 3600 * 1000;
|
|
22
22
|
|
|
@@ -24,13 +24,16 @@
|
|
|
24
24
|
*/
|
|
25
25
|
const fs = require("fs");
|
|
26
26
|
const path = require("path");
|
|
27
|
-
const {
|
|
27
|
+
const { strFromU8 } = require("fflate");
|
|
28
|
+
const { inflateRawSync } = require("node:zlib");
|
|
28
29
|
const { makeDepRecord } = require("../../dep-record");
|
|
29
30
|
|
|
30
31
|
const ARCHIVE_RE = /\.(jar|war|ear)$/i;
|
|
31
32
|
const SKIP_DIRS = new Set(["node_modules", ".git", "target", "build", "out", "dist-newstyle", ".gradle", ".m2"]);
|
|
32
33
|
// A fat-jar can be large; cap what we read into memory and how deep we recurse.
|
|
33
34
|
const MAX_ARCHIVE_BYTES = 512 * 1024 * 1024;
|
|
35
|
+
const MAX_ENTRY_BYTES = 64 * 1024 * 1024;
|
|
36
|
+
const MAX_EXPANDED_BYTES = 128 * 1024 * 1024;
|
|
34
37
|
const MAX_DEPTH = 8;
|
|
35
38
|
|
|
36
39
|
// The ONLY entries we ever decompress out of an archive: its own Maven coordinate
|
|
@@ -93,7 +96,7 @@ function coordFromFilename(fileName) {
|
|
|
93
96
|
/** Read the named entries from an in-memory zip buffer. Returns {} on a corrupt zip. */
|
|
94
97
|
function readEntries(buf, filter) {
|
|
95
98
|
try {
|
|
96
|
-
return
|
|
99
|
+
return readZipEntriesFromFd(buf, buf.length, filter || (() => true));
|
|
97
100
|
} catch {
|
|
98
101
|
return null; // not a valid zip / unsupported (e.g. ZIP64 edge) — caller warns
|
|
99
102
|
}
|
|
@@ -118,9 +121,14 @@ const LOC_SIG = 0x04034b50; // local file header
|
|
|
118
121
|
* @returns {Object<string, Uint8Array>} matched entries, same shape as readEntries()
|
|
119
122
|
*/
|
|
120
123
|
function readZipEntriesFromFd(fd, fileSize, filter) {
|
|
124
|
+
const read = (buffer, length, offset) => {
|
|
125
|
+
if (offset < 0 || length < 0 || offset + length > fileSize) throw new Error('truncated ZIP');
|
|
126
|
+
if (Buffer.isBuffer(fd)) fd.copy(buffer, 0, offset, offset + length);
|
|
127
|
+
else if (fs.readSync(fd, buffer, 0, length, offset) !== length) throw new Error('truncated ZIP');
|
|
128
|
+
};
|
|
121
129
|
const back = Math.min(fileSize, 65557); // max EOCD comment (65535) + 22-byte record
|
|
122
130
|
const tail = Buffer.allocUnsafe(back);
|
|
123
|
-
|
|
131
|
+
read(tail, back, fileSize - back);
|
|
124
132
|
let e = -1;
|
|
125
133
|
for (let i = tail.length - 22; i >= 0; i--) {
|
|
126
134
|
if (tail.readUInt32LE(i) === EOCD_SIG) { e = i; break; }
|
|
@@ -131,10 +139,11 @@ function readZipEntriesFromFd(fd, fileSize, filter) {
|
|
|
131
139
|
const cdOff = tail.readUInt32LE(e + 16);
|
|
132
140
|
if (count === 0xffff || cdSize === 0xffffffff || cdOff === 0xffffffff) throw new Error("ZIP64");
|
|
133
141
|
|
|
142
|
+
if (cdSize > MAX_ENTRY_BYTES || cdOff + cdSize > fileSize) throw new Error('ZIP central directory too large');
|
|
134
143
|
const cd = Buffer.allocUnsafe(cdSize);
|
|
135
|
-
|
|
144
|
+
read(cd, cdSize, cdOff);
|
|
136
145
|
const out = {};
|
|
137
|
-
let p = 0;
|
|
146
|
+
let p = 0, expanded = 0;
|
|
138
147
|
for (let i = 0; i < count; i++) {
|
|
139
148
|
if (p + 46 > cd.length || cd.readUInt32LE(p) !== CEN_SIG) throw new Error("bad central record");
|
|
140
149
|
const flags = cd.readUInt16LE(p + 8);
|
|
@@ -150,17 +159,19 @@ function readZipEntriesFromFd(fd, fileSize, filter) {
|
|
|
150
159
|
if (!filter(name)) continue;
|
|
151
160
|
if (flags & 0x1) throw new Error("encrypted entry");
|
|
152
161
|
if (compSize === 0xffffffff || uncompSize === 0xffffffff || localOff === 0xffffffff) throw new Error("ZIP64 entry");
|
|
162
|
+
if (compSize > MAX_ENTRY_BYTES || uncompSize > MAX_ENTRY_BYTES || (expanded += uncompSize) > MAX_EXPANDED_BYTES) throw new Error('ZIP expanded data too large');
|
|
153
163
|
// The local header's name/extra lengths can differ from the central record's,
|
|
154
164
|
// so read it to locate the actual start of the entry's data.
|
|
155
165
|
const loc = Buffer.allocUnsafe(30);
|
|
156
|
-
|
|
166
|
+
read(loc, 30, localOff);
|
|
157
167
|
if (loc.readUInt32LE(0) !== LOC_SIG) throw new Error("bad local header");
|
|
158
168
|
const dataOff = localOff + 30 + loc.readUInt16LE(26) + loc.readUInt16LE(28);
|
|
159
169
|
const comp = compSize > 0 ? Buffer.allocUnsafe(compSize) : Buffer.alloc(0);
|
|
160
|
-
if (compSize > 0)
|
|
170
|
+
if (compSize > 0) read(comp, compSize, dataOff);
|
|
161
171
|
if (method === 0) out[name] = comp; // stored
|
|
162
|
-
else if (method === 8) out[name] =
|
|
172
|
+
else if (method === 8) out[name] = inflateRawSync(comp, { maxOutputLength: Math.min(MAX_ENTRY_BYTES, uncompSize + 1) });
|
|
163
173
|
else throw new Error("compression method " + method);
|
|
174
|
+
if (out[name].length !== uncompSize) throw new Error('ZIP size mismatch');
|
|
164
175
|
}
|
|
165
176
|
return out;
|
|
166
177
|
}
|
|
@@ -194,6 +205,11 @@ function coordForArchive(entries, fileName) {
|
|
|
194
205
|
* into any nested archives. `ctx` carries { out, warnings, onProgress, scanned }.
|
|
195
206
|
*/
|
|
196
207
|
function processEntries(entries, displayPath, fileName, ctx, depth) {
|
|
208
|
+
ctx.expandedBytes = (ctx.expandedBytes || 0) + Object.values(entries).reduce((sum, bytes) => sum + bytes.length, 0);
|
|
209
|
+
if (ctx.expandedBytes > MAX_EXPANDED_BYTES) {
|
|
210
|
+
ctx.warnings.push({ type: 'embedded-jar', message: `expanded archive budget exceeded: ${displayPath}` });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
197
213
|
const resolved = coordForArchive(entries, fileName);
|
|
198
214
|
if (resolved) {
|
|
199
215
|
const { coord } = resolved;
|
|
@@ -259,16 +275,8 @@ function scanArchiveFile(abs, displayPath, fileName, ctx) {
|
|
|
259
275
|
const entries = readZipEntriesFromFd(fd, size, wantedEntry);
|
|
260
276
|
processEntries(entries, displayPath, fileName, ctx, 0);
|
|
261
277
|
return;
|
|
262
|
-
} catch {
|
|
278
|
+
} catch (e) { ctx.warnings.push({ type: "embedded-jar", message: `could not read archive (corrupt, oversized or unsupported): ${displayPath}` }); return; }
|
|
263
279
|
finally { if (fd !== undefined) { try { fs.closeSync(fd); } catch { /* ignore */ } } }
|
|
264
|
-
|
|
265
|
-
// Fallback: read the whole file + fflate (handles ZIP64 etc.).
|
|
266
|
-
let buf;
|
|
267
|
-
try { buf = fs.readFileSync(abs); }
|
|
268
|
-
catch (e) { ctx.warnings.push({ type: "embedded-jar", message: `could not read ${abs}: ${e.message}` }); return; }
|
|
269
|
-
const entries = readEntries(buf, wantedEntry);
|
|
270
|
-
if (entries === null) { ctx.warnings.push({ type: "embedded-jar", message: `could not read archive (corrupt/unsupported): ${displayPath}` }); return; }
|
|
271
|
-
processEntries(entries, displayPath, fileName, ctx, 0);
|
|
272
280
|
}
|
|
273
281
|
|
|
274
282
|
/** Recursively list archive file paths under `dir`. */
|
|
@@ -24,7 +24,7 @@ const pLimit = require("p-limit");
|
|
|
24
24
|
const { semverCompare, webjarToNpm } = require("./collect");
|
|
25
25
|
const { withPublic, authHeaderFor, normalise } = require("../../registries");
|
|
26
26
|
|
|
27
|
-
const CACHE_DIR = path.join(
|
|
27
|
+
const CACHE_DIR = path.join(require("../../cache-directory").getCacheDir());
|
|
28
28
|
const CACHE_PATH = path.join(CACHE_DIR, "npm-registry-cache.json");
|
|
29
29
|
const CACHE_MAX_AGE_MS = 24 * 3600 * 1000; // 1 day, aligned with Maven Central
|
|
30
30
|
|