@iso4/fetch 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -10
- package/dist/index.mjs +24 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -249,16 +249,17 @@ middleware body that is not bytes or text is JSON-encoded. Each call to
|
|
|
249
249
|
|
|
250
250
|
## Security defaults
|
|
251
251
|
|
|
252
|
-
| Threat
|
|
253
|
-
|
|
|
254
|
-
| SSRF / private IP
|
|
255
|
-
| DNS rebinding
|
|
256
|
-
| Redirect bypass
|
|
257
|
-
| Credential leak on redirect
|
|
258
|
-
| Response amplification
|
|
259
|
-
| Host auth leakage
|
|
260
|
-
| Path traversal
|
|
261
|
-
| Path/allowlist consistency
|
|
252
|
+
| Threat | Mitigation |
|
|
253
|
+
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
254
|
+
| SSRF / private IP | DNS resolved at connection time (allowed requests only); loopback, RFC1918, link-local blocked; the connected socket's address is checked again |
|
|
255
|
+
| DNS rebinding | undici DNS interceptor pins the connection to the resolved IP |
|
|
256
|
+
| Redirect bypass | No auto-follow by default; allow/deny re-checked on each hop |
|
|
257
|
+
| Credential leak on redirect | `authorization`/`cookie`/`proxy-authorization` dropped on a cross-origin hop |
|
|
258
|
+
| Response amplification | Body streamed with `maxBodyBytes` cap |
|
|
259
|
+
| Host auth leakage | Isolated undici `Agent` — no shared pool, cookies, or auth with the host app |
|
|
260
|
+
| Path traversal | `.`/`..` (and the `%2e` forms) normalised by the URL parser before matching |
|
|
261
|
+
| Path/allowlist consistency | Paths matched literally, never decoded, so the approved path is sent verbatim |
|
|
262
|
+
| Credentials in error messages | URLs with credentials refused; invalid-URL and invalid-header errors use fixed messages that never quote the URL or value |
|
|
262
263
|
|
|
263
264
|
Paths are matched and forwarded **literally** — iso4 never percent-decodes
|
|
264
265
|
them, so the path the allowlist approves is byte-for-byte the path that is sent.
|
package/dist/index.mjs
CHANGED
|
@@ -242,7 +242,18 @@ const REDIRECT_STATUSES = new Set([
|
|
|
242
242
|
307,
|
|
243
243
|
308
|
|
244
244
|
]);
|
|
245
|
+
const INVALID_URL = "fetch: invalid URL";
|
|
246
|
+
const URL_CREDENTIALS = "fetch: URL must not contain credentials";
|
|
247
|
+
const INVALID_HEADER = "fetch: invalid header name or value";
|
|
245
248
|
async function httpRequest(url, method, headers, body, agent, maxBodyBytes, signal) {
|
|
249
|
+
const target = URL.parse(url);
|
|
250
|
+
if (target === null) throw new TypeError(INVALID_URL);
|
|
251
|
+
if (target.username !== "" || target.password !== "") throw new TypeError(URL_CREDENTIALS);
|
|
252
|
+
try {
|
|
253
|
+
new Headers(headers);
|
|
254
|
+
} catch {
|
|
255
|
+
throw new TypeError(INVALID_HEADER);
|
|
256
|
+
}
|
|
246
257
|
const response = await fetch(url, {
|
|
247
258
|
method,
|
|
248
259
|
headers,
|
|
@@ -360,6 +371,16 @@ function createSafeFetch(options) {
|
|
|
360
371
|
function createSafeFetcher(options) {
|
|
361
372
|
const run = buildSafeFetchHandler(options);
|
|
362
373
|
return async (input, init) => {
|
|
374
|
+
if (!(input instanceof Request)) {
|
|
375
|
+
const target = URL.parse(input.toString());
|
|
376
|
+
if (target === null) throw new TypeError(INVALID_URL);
|
|
377
|
+
if (target.username !== "" || target.password !== "") throw new TypeError(URL_CREDENTIALS);
|
|
378
|
+
}
|
|
379
|
+
try {
|
|
380
|
+
new Headers(init?.headers);
|
|
381
|
+
} catch {
|
|
382
|
+
throw new TypeError(INVALID_HEADER);
|
|
383
|
+
}
|
|
363
384
|
const request = new Request(input, init);
|
|
364
385
|
const headers = {};
|
|
365
386
|
request.headers.forEach((value, key) => {
|
|
@@ -484,16 +505,9 @@ function buildSafeFetchHandler(options) {
|
|
|
484
505
|
});
|
|
485
506
|
}
|
|
486
507
|
return async (hostRequest) => {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
} catch {
|
|
491
|
-
throw new Error(`fetch: invalid URL "${hostRequest.url}"`);
|
|
492
|
-
}
|
|
493
|
-
if (parsedUrl.username !== "" || parsedUrl.password !== "") {
|
|
494
|
-
parsedUrl.username = "";
|
|
495
|
-
parsedUrl.password = "";
|
|
496
|
-
}
|
|
508
|
+
const parsedUrl = URL.parse(hostRequest.url);
|
|
509
|
+
if (parsedUrl === null) throw new TypeError(INVALID_URL);
|
|
510
|
+
if (parsedUrl.username !== "" || parsedUrl.password !== "") throw new TypeError(URL_CREDENTIALS);
|
|
497
511
|
const baseHeaders = { ...hostRequest.headers };
|
|
498
512
|
if (!allowCompressed) baseHeaders["accept-encoding"] = "identity";
|
|
499
513
|
delete baseHeaders["host"];
|
package/package.json
CHANGED