@revenexx/integrations-node-sdk 1.8.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +17 -1
- package/dist/index.js +17 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -572,6 +572,15 @@ async function guardUrl(url, ctxSignal, effectiveMs) {
|
|
|
572
572
|
clearTimeout(timer);
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
|
+
function hasContent(body) {
|
|
576
|
+
if (body == null) return false;
|
|
577
|
+
if (typeof body === "string") return body.length > 0;
|
|
578
|
+
if (body instanceof ArrayBuffer) return body.byteLength > 0;
|
|
579
|
+
if (ArrayBuffer.isView(body)) return body.byteLength > 0;
|
|
580
|
+
if (body instanceof Blob) return body.size > 0;
|
|
581
|
+
if (body instanceof URLSearchParams) return body.toString().length > 0;
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
575
584
|
async function guardedFetch(url, fetchOptions, ctxSignal, effectiveMs) {
|
|
576
585
|
let currentUrl = url;
|
|
577
586
|
let currentInit = { ...fetchOptions, redirect: "manual" };
|
|
@@ -604,7 +613,6 @@ async function guardedFetch(url, fetchOptions, ctxSignal, effectiveMs) {
|
|
|
604
613
|
if (base.protocol === "https:" && nextUrl.protocol !== "https:") {
|
|
605
614
|
throw new NodeError("BLOCKED_ADDRESS", "Blocked https\u2192http downgrade on redirect", { status: 0 });
|
|
606
615
|
}
|
|
607
|
-
await guardUrl(nextUrl, ctxSignal, effectiveMs);
|
|
608
616
|
const headers = new Headers(currentInit.headers);
|
|
609
617
|
let method = (currentInit.method ?? "GET").toUpperCase();
|
|
610
618
|
let body = currentInit.body;
|
|
@@ -614,6 +622,14 @@ async function guardedFetch(url, fetchOptions, ctxSignal, effectiveMs) {
|
|
|
614
622
|
headers.delete("content-type");
|
|
615
623
|
headers.delete("content-length");
|
|
616
624
|
}
|
|
625
|
+
if (hasContent(body) && nextUrl.origin !== base.origin) {
|
|
626
|
+
throw new NodeError(
|
|
627
|
+
"BLOCKED_ADDRESS",
|
|
628
|
+
`Blocked ${redirectStatus} redirect to another origin: it would resend the request body to ${nextUrl.origin}`,
|
|
629
|
+
{ status: 0 }
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
await guardUrl(nextUrl, ctxSignal, effectiveMs);
|
|
617
633
|
if (nextUrl.origin !== base.origin) {
|
|
618
634
|
for (const name of [...headers.keys()]) {
|
|
619
635
|
if (!headerCrossesOrigin(name)) headers.delete(name);
|
package/dist/index.js
CHANGED
|
@@ -480,6 +480,15 @@ async function guardUrl(url, ctxSignal, effectiveMs) {
|
|
|
480
480
|
clearTimeout(timer);
|
|
481
481
|
}
|
|
482
482
|
}
|
|
483
|
+
function hasContent(body) {
|
|
484
|
+
if (body == null) return false;
|
|
485
|
+
if (typeof body === "string") return body.length > 0;
|
|
486
|
+
if (body instanceof ArrayBuffer) return body.byteLength > 0;
|
|
487
|
+
if (ArrayBuffer.isView(body)) return body.byteLength > 0;
|
|
488
|
+
if (body instanceof Blob) return body.size > 0;
|
|
489
|
+
if (body instanceof URLSearchParams) return body.toString().length > 0;
|
|
490
|
+
return true;
|
|
491
|
+
}
|
|
483
492
|
async function guardedFetch(url, fetchOptions, ctxSignal, effectiveMs) {
|
|
484
493
|
let currentUrl = url;
|
|
485
494
|
let currentInit = { ...fetchOptions, redirect: "manual" };
|
|
@@ -512,7 +521,6 @@ async function guardedFetch(url, fetchOptions, ctxSignal, effectiveMs) {
|
|
|
512
521
|
if (base.protocol === "https:" && nextUrl.protocol !== "https:") {
|
|
513
522
|
throw new NodeError("BLOCKED_ADDRESS", "Blocked https\u2192http downgrade on redirect", { status: 0 });
|
|
514
523
|
}
|
|
515
|
-
await guardUrl(nextUrl, ctxSignal, effectiveMs);
|
|
516
524
|
const headers = new Headers(currentInit.headers);
|
|
517
525
|
let method = (currentInit.method ?? "GET").toUpperCase();
|
|
518
526
|
let body = currentInit.body;
|
|
@@ -522,6 +530,14 @@ async function guardedFetch(url, fetchOptions, ctxSignal, effectiveMs) {
|
|
|
522
530
|
headers.delete("content-type");
|
|
523
531
|
headers.delete("content-length");
|
|
524
532
|
}
|
|
533
|
+
if (hasContent(body) && nextUrl.origin !== base.origin) {
|
|
534
|
+
throw new NodeError(
|
|
535
|
+
"BLOCKED_ADDRESS",
|
|
536
|
+
`Blocked ${redirectStatus} redirect to another origin: it would resend the request body to ${nextUrl.origin}`,
|
|
537
|
+
{ status: 0 }
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
await guardUrl(nextUrl, ctxSignal, effectiveMs);
|
|
525
541
|
if (nextUrl.origin !== base.origin) {
|
|
526
542
|
for (const name of [...headers.keys()]) {
|
|
527
543
|
if (!headerCrossesOrigin(name)) headers.delete(name);
|