vigievuln 1.1.1 → 1.1.3
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 +18 -1
- package/README.md +14 -26
- package/lib/account-client.js +21 -14
- package/lib/account-session.js +11 -4
- package/lib/cache-archive.js +32 -1
- package/lib/cli-project-commands.js +25 -5
- package/lib/codecs/composer/registry.js +2 -1
- package/lib/codecs/maven/jar-scan.js +25 -17
- package/lib/codecs/maven.codec.js +2 -2
- package/lib/codecs/npm/registry.js +2 -1
- package/lib/codecs/nuget/registry.js +2 -1
- package/lib/codecs/pypi/parse.js +15 -8
- package/lib/codecs/pypi/registry.js +2 -1
- package/lib/codecs/pypi.codec.js +1 -1
- package/lib/cve-match.js +3 -4
- package/lib/cve-report.js +6 -4
- package/lib/hosted-proxy.js +6 -1
- package/lib/kev.js +4 -1
- package/lib/maven-repo.js +11 -6
- package/lib/nvd.js +10 -8
- package/lib/options-env.js +4 -5
- package/lib/osv.js +3 -1
- package/lib/packagist-audit.js +4 -2
- package/lib/providers/index.js +18 -9
- package/lib/proxy-cache.js +11 -1
- package/lib/proxy-throttle.js +71 -0
- package/lib/resource-cache/engine.js +12 -5
- package/lib/resource-cache/validate.js +3 -1
- package/lib/retire.js +8 -5
- package/package.json +3 -3
- package/vigievuln.js +40 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
# Changelog — VigieVuln
|
|
2
2
|
|
|
3
|
-
## [1.1.
|
|
3
|
+
## [1.1.3] — 2026-10-29
|
|
4
|
+
|
|
5
|
+
- Reuse fresh proxy-confirmed responses locally for up to one hour, and preserve stale-source warnings when refresh fails.
|
|
6
|
+
- Allow up to 100 hosted proxy requests per second, respecting server rate limits and retry delays.
|
|
7
|
+
- Select the official proxy on login when no proxy is configured; retain an existing proxy selection.
|
|
8
|
+
- Improve hosted scans, report links, account and cache handling, and Maven presence validation.
|
|
9
|
+
- Trim whitespace around Maven versions before OSV lookups so one malformed value cannot reject a whole batch.
|
|
10
|
+
- Refresh the example audit reports and their screenshot.
|
|
11
|
+
- Send the CLI version to the hosted proxy and explain how to update when the server requires a newer version.
|
|
12
|
+
|
|
13
|
+
## [1.1.2] — Unreleased
|
|
14
|
+
|
|
15
|
+
- Fix Windows account sessions when the home directory uses an 8.3 short path, including GitHub Actions temporary directories.
|
|
16
|
+
- Require explicit `--config` for repository configuration and bound Composer validation and JAR decompression.
|
|
17
|
+
- Reject cache archives containing links and keep Python requirements includes inside the scan root.
|
|
18
|
+
- Harden local proxy access and surface failed data sources as incomplete coverage.
|
|
19
|
+
|
|
20
|
+
## [1.1.1] — 2026-10-28
|
|
4
21
|
|
|
5
22
|
- Review and explicitly accept the current service terms when a hosted account requires it.
|
|
6
23
|
- Refuse project descriptors larger than 500,000 UTF-8 bytes before upload.
|
package/README.md
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
[](https://github.com/9pings/VigieVuln/actions/workflows/ci.yml)
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
**VigieVuln**
|
|
13
|
+
**VigieVuln** is a polyglot dependency auditor built for **professional code audits**.
|
|
14
14
|
|
|
15
15
|
It scans **10 ecosystems + 9 CMS/Frameworks** (WordPress, Drupal, Symfony, Laravel…) in one pass, with **no build tools**, support **air-gapped** workflows using transferred caches, private package detection, committed binaries & certificates, then produces clean **HTML reports + json baseline + (DOC/XLSX/SARIF/CycloneDX/etc)** .
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
🌐 **[Project site & docs →](https://9pings.github.io/VigieVuln/)**
|
|
19
19
|
|
|
20
|
-
*
|
|
20
|
+
*Terminal demo recorded with VigieVuln 1.0.1.*
|
|
21
21
|
|
|
22
22
|
<p align="center"><img src="docs/assets/demo.gif" alt="vigievuln animated terminal demo: an offline Maven audit — dependencies absent from Maven Central flagged as private/internal, the compact single-line vulnerability-database progress, then findings coloured by severity" height="500"></p>
|
|
23
23
|
|
|
@@ -43,17 +43,6 @@ It scans **10 ecosystems + 9 CMS/Frameworks** (WordPress, Drupal, Symfony, Larav
|
|
|
43
43
|
|
|
44
44
|
📖 **[Usage & all flags](docs/USAGE.md)** · **[Architecture](docs/ARCHITECTURE.md)** · **[Comparison vs other tools](docs/COMPARISON.md)** · **[Data sources](docs/DATA-SOURCES.md)**
|
|
45
45
|
|
|
46
|
-
## Migration from fad-checker
|
|
47
|
-
|
|
48
|
-
The npm package and primary command are now `vigievuln`. Existing `fad` and
|
|
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` and `.vigievuln-env.json` take precedence over their legacy
|
|
54
|
-
`FAD_CHECKER_ENV` / `.fad-env.json` counterparts. Default report output is now
|
|
55
|
-
`./vigievuln-report`; pass `-o` to retain another location.
|
|
56
|
-
|
|
57
46
|
## Quick start
|
|
58
47
|
|
|
59
48
|
```bash
|
|
@@ -75,11 +64,9 @@ vigievuln project status
|
|
|
75
64
|
vigievuln logout
|
|
76
65
|
```
|
|
77
66
|
|
|
78
|
-
`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`
|
|
67
|
+
`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` selects the official proxy if none is configured; an existing proxy remains selected.
|
|
79
68
|
|
|
80
|
-
The free tier
|
|
81
|
-
|
|
82
|
-
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.
|
|
69
|
+
The free tier watches **one project, up to 100 direct dependencies and a 0.5 MB descriptor**, for **one month renewed by each upload**; expiry deletes the monitoring data and triggers an email.
|
|
83
70
|
|
|
84
71
|
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.
|
|
85
72
|
|
|
@@ -89,18 +76,20 @@ To review the inventory before uploading, export it locally:
|
|
|
89
76
|
vigievuln watch ./project --export fichier.json
|
|
90
77
|
```
|
|
91
78
|
|
|
92
|
-
`--export`
|
|
79
|
+
`--export` writes an offline descriptor without uploading; review package names and versions, including private packages, before sharing it.
|
|
93
80
|
|
|
94
|
-
|
|
81
|
+
Enable alerts in your account to receive new high, critical or known exploited vulnerabilities affecting your direct dependencies; refresh the inventory when dependencies change. [Monitoring guide](docs/USAGE.md#project-monitoring).
|
|
95
82
|
|
|
96
83
|
Existing commands remain supported: `vigievuln -s ./code`, `auth login|status|logout`, `--prepare-project` and `project push`.
|
|
97
84
|
|
|
98
85
|
### Official Vigie Vuln proxy cache
|
|
99
86
|
|
|
87
|
+
[Vigie Vuln DB](https://www.vigievuln.fr/) hosts vulnerability data and the official proxy cache in Europe.
|
|
88
|
+
|
|
100
89
|
Configure the proxy once, then sign in with your verified [Vigie Vuln account](https://www.vigievuln.fr/account) when prompted:
|
|
101
90
|
|
|
102
91
|
```bash
|
|
103
|
-
vigievuln
|
|
92
|
+
vigievuln login # selects the official proxy if none is configured
|
|
104
93
|
vigievuln scan ./code
|
|
105
94
|
```
|
|
106
95
|
|
|
@@ -108,10 +97,10 @@ The selection and the proxy key created during proxy sign-in are saved in `~/.vi
|
|
|
108
97
|
|
|
109
98
|
### Interactive HTML samples
|
|
110
99
|
|
|
111
|
-
- **[Apache Dubbo 2.7.8 — open the report](https://9pings.github.io/VigieVuln/samples/dubbo.html)**: the project used for the report screenshot below, rescanned with VigieVuln 1.
|
|
100
|
+
- **[Apache Dubbo 2.7.8 — open the report](https://9pings.github.io/VigieVuln/samples/dubbo.html)**: the project used for the report screenshot below, rescanned with VigieVuln 1.1.3; 105 Maven descriptors, direct/transitive CVEs, KEV matches, EOL and fix recommendations.
|
|
112
101
|
- **[Multi-instance CMS & frameworks — open the report](https://9pings.github.io/VigieVuln/samples/multi-cms-frameworks.html)**: WordPress 6.4.2, Drupal 8.5.0, Symfony Demo (Symfony 7.1.1) and BookStack v24.10 (Laravel 10.48.22), with findings attributed to each instance.
|
|
113
102
|
|
|
114
|
-
These are standalone reports from real source scans, generated
|
|
103
|
+
These are standalone reports from real source scans, generated on **2026-10-29** using the hosted proxy and local caches. The CMS sample focuses on PHP dependencies; WordPress advisory coverage is explicitly incomplete without a Wordfence feed. [Sample scope, sources and reproduction commands](docs/samples/README.md).
|
|
115
104
|
|
|
116
105
|
> [!WARNING]
|
|
117
106
|
> vigievuln is new and may still contain ( rare ) bugs. Treat its output as a strong first pass, **double-check anything critical**, and please [report issues](https://github.com/9pings/VigieVuln/issues); they get fixed fast.
|
|
@@ -251,15 +240,14 @@ vigievuln -s ./proj --offline # re-collect locally (real paths) +
|
|
|
251
240
|
# the online phase ride the same archive and are consumed automatically — no flags.
|
|
252
241
|
```
|
|
253
242
|
|
|
254
|
-
|
|
243
|
+
Descriptor imports also warm Maven registry presence (unless
|
|
255
244
|
`--no-all-libs` is set). Legacy negative presence entries are discarded automatically:
|
|
256
245
|
older versions could confuse network errors with missing packages. Until verified
|
|
257
246
|
online, those entries remain **unknown**, including after a cache merge. Other warmed
|
|
258
247
|
analysis data is retained.
|
|
259
248
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
cache with VigieVuln 1.0.0 to verify these entries; until then offline reports warn about incomplete
|
|
249
|
+
Unverified empty OSV cache entries are not trusted, because a failed request may have
|
|
250
|
+
been stored as “no vulnerabilities”. Re-warm and export the cache to verify these entries; until then offline reports warn about incomplete
|
|
263
251
|
OSV coverage. Existing cached advisory IDs remain usable. Offline KEV and binary identity
|
|
264
252
|
lookups reuse the last available snapshot even after 24 hours, without changing its date.
|
|
265
253
|
|
package/lib/account-client.js
CHANGED
|
@@ -18,33 +18,35 @@ 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) {
|
|
21
|
+
function readTerms(value, origin = ACCOUNT_ORIGIN) {
|
|
22
22
|
if (!value || typeof value !== 'object' || Array.isArray(value) ||
|
|
23
23
|
typeof value.version !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/.test(value.version) ||
|
|
24
24
|
typeof value.documentUrl !== 'string' || value.documentUrl.length > 2048 ||
|
|
25
25
|
/[\x00-\x20\x7f]/.test(value.documentUrl) || typeof value.accepted !== 'boolean') throw invalidResponse();
|
|
26
26
|
let url;
|
|
27
|
-
try { url = new URL(value.documentUrl,
|
|
28
|
-
if (url.
|
|
27
|
+
try { url = new URL(value.documentUrl, origin); } catch { throw invalidResponse(); }
|
|
28
|
+
if (url.origin !== origin || url.username || url.password ||
|
|
29
29
|
url.pathname !== '/terms/' + value.version || url.search || url.hash ||
|
|
30
|
-
![url.pathname,
|
|
30
|
+
![url.pathname, origin + url.pathname].includes(value.documentUrl)) throw invalidResponse();
|
|
31
31
|
return { version: value.version, url: url.href, accepted: value.accepted };
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* Account authentication for
|
|
36
|
-
*
|
|
35
|
+
* Account authentication for the official service or an explicitly configured proxy.
|
|
36
|
+
* Sessions are bound to their account origin before any authenticated request.
|
|
37
37
|
* login({email,password}) -> {account,expiresAt}; me() -> {account};
|
|
38
38
|
* logout() -> {revoked}. logout always clears local storage, including on a
|
|
39
39
|
* remote error, which is still reported (revocation is then unconfirmed).
|
|
40
40
|
* The password exists only in the in-flight request, never in the store.
|
|
41
41
|
*/
|
|
42
|
-
function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
42
|
+
function createAccountClient({ fetcher = globalThis.fetch, now = Date.now, accountOrigin = ACCOUNT_ORIGIN,
|
|
43
43
|
sessionStore = createAccountSessionStore({ now }), timeoutMs = DEFAULT_TIMEOUT_MS } = {}) {
|
|
44
44
|
if (typeof fetcher !== 'function' || !Number.isInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2147483647) {
|
|
45
45
|
throw new AccountClientError('INVALID_OPTIONS', 'Invalid account transport or timeout.');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
let parsedOrigin; try { parsedOrigin = new URL(accountOrigin); } catch { throw new AccountClientError('INVALID_OPTIONS', 'Invalid account origin.'); }
|
|
49
|
+
if (parsedOrigin.origin !== accountOrigin || !['https:', 'http:'].includes(parsedOrigin.protocol) || parsedOrigin.username || parsedOrigin.password) throw new AccountClientError('INVALID_OPTIONS', 'Invalid account origin.');
|
|
48
50
|
async function request(route, method, body, token) {
|
|
49
51
|
const controller = new AbortController();
|
|
50
52
|
let timer;
|
|
@@ -56,7 +58,7 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
56
58
|
}, timeoutMs);
|
|
57
59
|
});
|
|
58
60
|
const operation = async () => {
|
|
59
|
-
response = await fetcher(
|
|
61
|
+
response = await fetcher(accountOrigin + '/v1/accounts/' + route, {
|
|
60
62
|
method, redirect: 'error', credentials: 'omit', cache: 'no-store',
|
|
61
63
|
headers: { accept: 'application/json', ...(body !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
62
64
|
...(token ? { authorization: 'Bearer ' + token } : {}) },
|
|
@@ -68,7 +70,7 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
68
70
|
}
|
|
69
71
|
// Also reject an injected transport that reports a redirect/followed URL.
|
|
70
72
|
if (response.redirected || (response.status >= 300 && response.status < 400) ||
|
|
71
|
-
(response.url && response.url !==
|
|
73
|
+
(response.url && response.url !== accountOrigin + '/v1/accounts/' + route)) {
|
|
72
74
|
throw new AccountClientError('REDIRECT_REFUSED', 'Account API redirects are forbidden.');
|
|
73
75
|
}
|
|
74
76
|
if (!response.ok) {
|
|
@@ -116,7 +118,9 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
116
118
|
async function currentSession() {
|
|
117
119
|
const session = await sessionStore.read();
|
|
118
120
|
if (!session) throw new AccountClientError('NOT_AUTHENTICATED', 'No account session. Sign in first.');
|
|
119
|
-
|
|
121
|
+
const valid = validateAccountSession(session, now());
|
|
122
|
+
if ((valid.origin || ACCOUNT_ORIGIN) !== accountOrigin) throw new AccountClientError('NOT_AUTHENTICATED', 'Session belongs to another server. Sign in again.');
|
|
123
|
+
return valid;
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
async function login(credentials = {}) {
|
|
@@ -130,7 +134,8 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
130
134
|
try { session = validateAccountSession(data, now()); }
|
|
131
135
|
catch { throw invalidResponse(); }
|
|
132
136
|
if (data.tokenType !== 'Bearer' || !isAccount(data.account)) throw invalidResponse();
|
|
133
|
-
const terms = readTerms(data.account.terms);
|
|
137
|
+
const terms = readTerms(data.account.terms, accountOrigin);
|
|
138
|
+
if (accountOrigin !== ACCOUNT_ORIGIN) session.origin = accountOrigin;
|
|
134
139
|
try { await sessionStore.write(session); }
|
|
135
140
|
catch (error) {
|
|
136
141
|
// Avoid leaving a newly issued session alive when local persistence fails.
|
|
@@ -145,7 +150,7 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
145
150
|
try {
|
|
146
151
|
const data = await request('me', 'GET', undefined, session.token);
|
|
147
152
|
if (!isAccount(data.account)) throw invalidResponse();
|
|
148
|
-
const terms = readTerms(data.account.terms);
|
|
153
|
+
const terms = readTerms(data.account.terms, accountOrigin);
|
|
149
154
|
return { account: data.account, ...(terms && { terms }) };
|
|
150
155
|
} catch (error) {
|
|
151
156
|
if (error.code === 'UNAUTHORIZED') await sessionStore.clear();
|
|
@@ -160,7 +165,7 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
160
165
|
const session = await currentSession();
|
|
161
166
|
const data = await request('terms', 'POST', { termsVersion: version, accepted: true }, session.token);
|
|
162
167
|
if (!isAccount(data.account)) throw invalidResponse();
|
|
163
|
-
const terms = readTerms(data.account.terms);
|
|
168
|
+
const terms = readTerms(data.account.terms, accountOrigin);
|
|
164
169
|
if (!terms || !terms.accepted || terms.version !== version) throw invalidResponse();
|
|
165
170
|
return { terms };
|
|
166
171
|
}
|
|
@@ -173,11 +178,13 @@ function createAccountClient({ fetcher = globalThis.fetch, now = Date.now,
|
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
async function logout() {
|
|
181
|
+
const existing = await sessionStore.read();
|
|
182
|
+
if (existing && (existing.origin || ACCOUNT_ORIGIN) !== accountOrigin) throw new AccountClientError('NOT_AUTHENTICATED', 'Session belongs to another server.');
|
|
176
183
|
try {
|
|
177
184
|
const stored = await sessionStore.read();
|
|
178
185
|
if (!stored) return { revoked: 0 };
|
|
179
186
|
let session;
|
|
180
|
-
try { session = validateAccountSession(stored, now()); }
|
|
187
|
+
try { session = validateAccountSession(stored, now()); if ((session.origin || ACCOUNT_ORIGIN) !== accountOrigin) throw new AccountClientError('NOT_AUTHENTICATED', 'Session belongs to another server.'); }
|
|
181
188
|
catch (error) { if (error.code === 'SESSION_EXPIRED') return { revoked: 0 }; throw error; }
|
|
182
189
|
const data = await request('logout', 'POST', {}, session.token);
|
|
183
190
|
if (!Number.isSafeInteger(data.revoked) || data.revoked < 0) throw invalidResponse();
|
package/lib/account-session.js
CHANGED
|
@@ -15,7 +15,7 @@ class AccountSessionError extends Error {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// The account API uses epoch milliseconds. Never persist credentials or the
|
|
18
|
-
// entire login response:
|
|
18
|
+
// entire login response: only token, expiry and an optional server origin are stored.
|
|
19
19
|
function validateAccountSession(value, now = Date.now()) {
|
|
20
20
|
if (!value || typeof value !== 'object' || Array.isArray(value) ||
|
|
21
21
|
typeof value.token !== 'string' || !/^[A-Za-z0-9_-]{1,200}$/.test(value.token) ||
|
|
@@ -25,7 +25,11 @@ function validateAccountSession(value, now = Date.now()) {
|
|
|
25
25
|
if (value.expiresAt <= now) {
|
|
26
26
|
throw new AccountSessionError('SESSION_EXPIRED', 'Account session expired. Sign in again.');
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
if (value.origin !== undefined) {
|
|
29
|
+
let url; try { url = new URL(value.origin); } catch { throw new AccountSessionError('INVALID_SESSION', 'Invalid account session origin.'); }
|
|
30
|
+
if (url.origin !== value.origin || !['https:', 'http:'].includes(url.protocol) || url.username || url.password) throw new AccountSessionError('INVALID_SESSION', 'Invalid account session origin.');
|
|
31
|
+
}
|
|
32
|
+
return { token: value.token, expiresAt: value.expiresAt, ...(value.origin && { origin: value.origin }) };
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
/**
|
|
@@ -304,9 +308,12 @@ public static class VigieVulnSession {
|
|
|
304
308
|
static object Execute(Dictionary<string, object> request) {
|
|
305
309
|
string operation = (string)request["operation"], home = (string)request["homeDir"];
|
|
306
310
|
if (operation != "read" && operation != "write" && operation != "clear") IO();
|
|
307
|
-
// Reject UNC/device paths
|
|
311
|
+
// Reject UNC/device paths and alternate streams. Windows may supply an
|
|
312
|
+
// 8.3 short path (notably TEMP on GitHub runners); expand it before
|
|
313
|
+
// checking every component and the private directory by handle.
|
|
308
314
|
if (!System.Text.RegularExpressions.Regex.IsMatch(home, @"^[A-Za-z]:\\") || home.IndexOf(':', 2) >= 0 ||
|
|
309
|
-
home.IndexOf('/') >= 0 || home.IndexOf('\0') >= 0
|
|
315
|
+
home.IndexOf('/') >= 0 || home.IndexOf('\0') >= 0) Unsafe();
|
|
316
|
+
home = Path.GetFullPath(home);
|
|
310
317
|
string root = home.Substring(0, 3);
|
|
311
318
|
uint serial, component, flags;
|
|
312
319
|
StringBuilder format = new StringBuilder(32);
|
package/lib/cache-archive.js
CHANGED
|
@@ -129,6 +129,13 @@ function mergeFile(srcFile, dstFile, rel, stats) {
|
|
|
129
129
|
if (!fs.existsSync(dstFile)) { copyPreservingTime(srcFile, dstFile); stats.added++; return; }
|
|
130
130
|
const srcJson = readJson(srcFile), dstJson = readJson(dstFile);
|
|
131
131
|
if (isEntryMap(srcJson) && isEntryMap(dstJson)) {
|
|
132
|
+
// Legacy Maven false values do not prove absence and must never override a
|
|
133
|
+
// confirmed hit, even if their containing cache file is more recent.
|
|
134
|
+
if (rel === "maven-exists-cache.json") {
|
|
135
|
+
const { discardUnverifiedEntries } = require("./maven-presence");
|
|
136
|
+
discardUnverifiedEntries(srcJson);
|
|
137
|
+
discardUnverifiedEntries(dstJson);
|
|
138
|
+
}
|
|
132
139
|
mergeEntryMaps(srcFile, dstFile, srcJson, dstJson);
|
|
133
140
|
stats.merged++;
|
|
134
141
|
return;
|
|
@@ -286,10 +293,22 @@ async function importCache(srcFile, opts = {}) {
|
|
|
286
293
|
if (!fs.existsSync(abs)) throw new Error(`archive not found: ${abs}`);
|
|
287
294
|
|
|
288
295
|
// Merge: unpack beside the cache (same filesystem), reconcile, drop the staging dir.
|
|
289
|
-
|
|
296
|
+
fs.mkdirSync(path.dirname(FAD_CACHE_DIR), { recursive: true });
|
|
297
|
+
const staging = fs.mkdtempSync(`${FAD_CACHE_DIR}.import-`);
|
|
290
298
|
const stats = { added: 0, updated: 0, merged: 0, kept: 0, skipped: [] };
|
|
291
299
|
try {
|
|
292
300
|
await extractTo(abs, staging, verbose);
|
|
301
|
+
// Never promote links or special files into a live cache, including in
|
|
302
|
+
// replace mode. A later cache write could otherwise escape the cache root.
|
|
303
|
+
const inspect = dir => {
|
|
304
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
305
|
+
const file = path.join(dir, entry), st = fs.lstatSync(file);
|
|
306
|
+
if (st.isSymbolicLink() || (!st.isDirectory() && (!st.isFile() || st.nlink !== 1)))
|
|
307
|
+
throw new Error("archive contains links or special files");
|
|
308
|
+
if (st.isDirectory()) inspect(file);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
inspect(staging);
|
|
293
312
|
const modern = path.join(staging, path.basename(FAD_CACHE_DIR));
|
|
294
313
|
const legacy = path.join(staging, '.fad-checker');
|
|
295
314
|
// Windows Compress-Archive historically emitted the cache contents at
|
|
@@ -300,6 +319,18 @@ async function importCache(srcFile, opts = {}) {
|
|
|
300
319
|
throw new Error(`archive holds no .vigie-vuln/ or .fad-checker/ directory — was it built with vigievuln --export-cache?`);
|
|
301
320
|
}
|
|
302
321
|
if (replace) {
|
|
322
|
+
// Configuration contains machine-local credentials and is never
|
|
323
|
+
// accepted from an imported archive, even for a replacement.
|
|
324
|
+
for (const name of NEVER_IMPORT) {
|
|
325
|
+
const src = path.join(FAD_CACHE_DIR, name), dst = path.join(incoming, name);
|
|
326
|
+
fs.rmSync(dst, { force: true });
|
|
327
|
+
if (fs.existsSync(src)) {
|
|
328
|
+
const st = fs.lstatSync(src);
|
|
329
|
+
if (!st.isFile() || st.isSymbolicLink() || st.nlink !== 1) throw new Error('unsafe local cache configuration');
|
|
330
|
+
fs.copyFileSync(src, dst, fs.constants.COPYFILE_EXCL);
|
|
331
|
+
try { fs.chmodSync(dst, 0o600); } catch { /* platform does not support chmod */ }
|
|
332
|
+
}
|
|
333
|
+
}
|
|
303
334
|
if (fs.existsSync(FAD_CACHE_DIR) && !force) {
|
|
304
335
|
const backup = `${FAD_CACHE_DIR}.bak-${Date.now()}`;
|
|
305
336
|
fs.renameSync(FAD_CACHE_DIR, backup);
|
|
@@ -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,7 +31,7 @@ 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});
|
|
@@ -44,15 +44,35 @@ async function run(args, dependencies={}) {
|
|
|
44
44
|
return (await ensureSignedIn({account,store,...dependencies})).session;
|
|
45
45
|
}});
|
|
46
46
|
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
|
|
47
|
+
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
48
|
: '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
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
const store=createAccountSessionStore()
|
|
51
|
+
const store=createAccountSessionStore();
|
|
52
|
+
const config=require('./config');
|
|
53
|
+
const selected=config.get('proxyCache');
|
|
54
|
+
let accountOrigin=require('./account-client').ACCOUNT_ORIGIN;
|
|
55
|
+
if(group==='auth' && selected && !/^(default|vigievuln|https:\/\/api\.vigievuln\.(fr|com)\/?$)$/i.test(selected)) {
|
|
56
|
+
let url; try { url=new URL(selected); } catch { throw new Error('Invalid configured proxy URL.'); }
|
|
57
|
+
if (!['https:','http:'].includes(url.protocol) || url.username || url.password || url.pathname!=='/' || url.search || url.hash) throw new Error('The configured proxy must be an HTTP(S) origin without credentials or a path.');
|
|
58
|
+
if (url.protocol==='http:' && !['localhost','127.0.0.1','[::1]'].includes(url.hostname)) throw new Error('Login to a remote proxy requires HTTPS.');
|
|
59
|
+
accountOrigin=url.origin;
|
|
60
|
+
}
|
|
61
|
+
const account=createAccountClient({sessionStore:store,accountOrigin});
|
|
52
62
|
if(group==='auth') {
|
|
53
63
|
if(rest.length)throw new Error('unexpected authentication option');
|
|
54
64
|
if(['login','status','whoami'].includes(command)) {
|
|
55
|
-
const result=await ensureSignedIn({account,store,...dependencies});
|
|
65
|
+
const result=await ensureSignedIn({account,store,accountOrigin,...dependencies});
|
|
66
|
+
if(command==='login' && !selected) {config.set('proxyCache','vigievuln');console.log('Official VigieVuln proxy configured for future scans.');}
|
|
67
|
+
if(command==='login' && accountOrigin===require('./account-client').ACCOUNT_ORIGIN && config.get('proxyCacheTokenOrigin')) {
|
|
68
|
+
config.set('proxyCacheToken',null);config.set('proxyCacheTokenOrigin',null);
|
|
69
|
+
}
|
|
70
|
+
if(command==='login' && accountOrigin!==require('./account-client').ACCOUNT_ORIGIN &&
|
|
71
|
+
(config.get('proxyCacheTokenOrigin')!==accountOrigin || !config.get('proxyCacheToken'))) {
|
|
72
|
+
const key=await account.createProxyKey();config.set('proxyCacheToken',key.token);config.set('proxyCacheTokenOrigin',accountOrigin);
|
|
73
|
+
console.log(`Proxy key saved for ${accountOrigin}.`);
|
|
74
|
+
}
|
|
75
|
+
console.log(`Signed in as ${result.account.email}.`);return;
|
|
56
76
|
}
|
|
57
77
|
if(command==='logout') {await account.logout();console.log('Signed out.');return;}
|
|
58
78
|
throw new Error('usage: vigievuln auth login|status|logout');
|
|
@@ -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);
|
|
@@ -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`. */
|
|
@@ -22,14 +22,14 @@ const cveIndexScanner = {
|
|
|
22
22
|
if (opts.hostedProxy && !opts.offline && !opts.cveOffline) {
|
|
23
23
|
const keys = new Set();
|
|
24
24
|
for (const dep of deps.values()) {
|
|
25
|
-
if (dep.ecosystem
|
|
25
|
+
if ((dep.ecosystem && dep.ecosystem !== "maven") || dep.provenance === "binary") continue;
|
|
26
26
|
const group = String(dep.groupId || "").toLowerCase(), artifact = String(dep.artifactId || "").toLowerCase();
|
|
27
27
|
if (group && artifact) keys.add("p:" + group + ":" + artifact);
|
|
28
28
|
if (artifact) keys.add("a:" + artifact);
|
|
29
29
|
}
|
|
30
30
|
const idx = newIndex(), all = [...keys], seen = new Set();
|
|
31
31
|
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) }
|
|
32
|
+
const res = await require("../providers").getResource("github", "cve-maven", { keys: all.slice(i, i + 200) });
|
|
33
33
|
if (!res.ok) throw new Error(`hosted CVE index unavailable (HTTP ${res.status})`);
|
|
34
34
|
const data = await res.json();
|
|
35
35
|
if (!Array.isArray(data.cves)) throw new Error("invalid hosted CVE index response");
|
|
@@ -117,8 +117,9 @@ async function fetchPackument(name, opts = {}) {
|
|
|
117
117
|
const ah = authHeaderFor(base);
|
|
118
118
|
if (ah) headers.Authorization = ah;
|
|
119
119
|
try {
|
|
120
|
+
const hosted = base.name === "public" && require("../../providers").hasHostedProxy();
|
|
120
121
|
const res = await require("../../providers").getResource("npm", "package", { name },
|
|
121
|
-
{ fetcher, headers, signal: AbortSignal.timeout(timeoutMs),
|
|
122
|
+
{ fetcher, headers, ...(hosted ? { requestTimeoutMs: timeoutMs } : { signal: AbortSignal.timeout(timeoutMs) }),
|
|
122
123
|
...(base.name === "public" ? {} : { urlOverride: url, direct: true }) });
|
|
123
124
|
if (res.ok) return await res.json();
|
|
124
125
|
lastErr = `HTTP ${res.status}`;
|
|
@@ -111,7 +111,8 @@ async function fetchRegistration(name, { offline, version = null, registries = [
|
|
|
111
111
|
catch (e) { lastErr = e.message; statuses.push(null); continue; }
|
|
112
112
|
if (!regBase) { lastErr = "no registration base"; statuses.push(null); continue; }
|
|
113
113
|
try {
|
|
114
|
-
|
|
114
|
+
if (!/^[a-z0-9_.-]+$/i.test(id) || id === '.' || id === '..') throw new Error('invalid NuGet package name');
|
|
115
|
+
const url = `${regBase}${encodeURIComponent(id)}/index.json`;
|
|
115
116
|
const res = await require("../../providers").getResource("nuget", "registration", { name: id },
|
|
116
117
|
{ fetcher, headers, ...(url === `https://api.nuget.org/v3/registration5-gz-semver2/${id}/index.json`
|
|
117
118
|
? {} : { urlOverride: url, direct: true }) });
|
package/lib/codecs/pypi/parse.js
CHANGED
|
@@ -123,13 +123,20 @@ function parsePyprojectToml(filePath) {
|
|
|
123
123
|
// Walk a requirements.txt graph, following -r/--requirement (deps) and
|
|
124
124
|
// -c/--constraint (version pins) includes recursively. `kind` is "req" for the
|
|
125
125
|
// dependency graph and "constraint" for files reached via -c.
|
|
126
|
-
function collectReqGraph(filePath, seen, kind, acc) {
|
|
126
|
+
function collectReqGraph(filePath, seen, kind, acc, root) {
|
|
127
127
|
const real = path.resolve(filePath);
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
let resolved;
|
|
129
|
+
try { resolved = fs.realpathSync(real); }
|
|
130
|
+
catch { acc.missing.push(real); return; }
|
|
131
|
+
const relative = path.relative(root, resolved);
|
|
132
|
+
if (relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) {
|
|
133
|
+
acc.missing.push(`${real} (outside scan root; ignored)`); return;
|
|
134
|
+
}
|
|
135
|
+
if (seen.has(resolved)) return; // cycle / re-include guard
|
|
136
|
+
seen.add(resolved);
|
|
130
137
|
if (seen.size > 200) return; // sanity bound
|
|
131
138
|
let lines;
|
|
132
|
-
try { lines = fs.readFileSync(
|
|
139
|
+
try { lines = fs.readFileSync(resolved, "utf8").split(/\r?\n/); }
|
|
133
140
|
catch { acc.missing.push(real); return; }
|
|
134
141
|
const dir = path.dirname(real);
|
|
135
142
|
for (const raw of lines) {
|
|
@@ -141,9 +148,9 @@ function collectReqGraph(filePath, seen, kind, acc) {
|
|
|
141
148
|
line = line.replace(/\\$/, "").trim();
|
|
142
149
|
if (!line) continue;
|
|
143
150
|
const rMatch = line.match(/^(?:-r|--requirement)[=\s]+(.+)$/);
|
|
144
|
-
if (rMatch) { collectReqGraph(path.resolve(dir, rMatch[1].trim()), seen, kind, acc); continue; }
|
|
151
|
+
if (rMatch) { collectReqGraph(path.resolve(dir, rMatch[1].trim()), seen, kind, acc, root); continue; }
|
|
145
152
|
const cMatch = line.match(/^(?:-c|--constraint)[=\s]+(.+)$/);
|
|
146
|
-
if (cMatch) { collectReqGraph(path.resolve(dir, cMatch[1].trim()), seen, "constraint", acc); continue; }
|
|
153
|
+
if (cMatch) { collectReqGraph(path.resolve(dir, cMatch[1].trim()), seen, "constraint", acc, root); continue; }
|
|
147
154
|
if (line.startsWith("-")) continue; // -e ., --hash, other flags
|
|
148
155
|
// Per-requirement options ("pkg==1.0 --hash=sha256:…") come after the spec.
|
|
149
156
|
const { name, spec } = splitPep508(line.split(/\s+--/)[0].trim());
|
|
@@ -154,9 +161,9 @@ function collectReqGraph(filePath, seen, kind, acc) {
|
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
163
|
|
|
157
|
-
function parseRequirementsTxt(filePath) {
|
|
164
|
+
function parseRequirementsTxt(filePath, scanRoot = path.dirname(filePath)) {
|
|
158
165
|
const acc = { reqs: [], constraints: new Map(), missing: [] };
|
|
159
|
-
collectReqGraph(filePath, new Set(), "req", acc);
|
|
166
|
+
collectReqGraph(filePath, new Set(), "req", acc, fs.realpathSync(scanRoot));
|
|
160
167
|
const deps = [];
|
|
161
168
|
let skipped = 0;
|
|
162
169
|
const seen = new Set();
|