@@ -26020,7 +26020,7 @@ Object.defineProperty(Response.prototype, Symbol.toStringTag, {
26020
26020
});
26021
26021
26022
26022
const INTERNALS$2 = Symbol('Request internals');
26023
- const URL = whatwgUrl.URL;
26023
+ const URL = Url.URL || whatwgUrl.URL;
26024
26024
26025
26025
// fix an issue where "format", "parse" aren't a named export for node <10
26026
26026
const parse_url = Url.parse;
@@ -26283,9 +26283,17 @@ AbortError.prototype = Object.create(Error.prototype);
26283
26283
AbortError.prototype.constructor = AbortError;
26284
26284
AbortError.prototype.name = 'AbortError';
26285
26285
26286
+ const URL$1 = Url.URL || whatwgUrl.URL;
26287
+
26286
26288
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
26287
26289
const PassThrough$1 = Stream.PassThrough;
26288
- const resolve_url = Url.resolve;
26290
+
26291
+ const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
26292
+ const orig = new URL$1(original).hostname;
26293
+ const dest = new URL$1(destination).hostname;
26294
+
26295
+ return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
26296
+ };
26289
26297
26290
26298
/**
26291
26299
* Fetch function
@@ -26373,7 +26381,19 @@ function fetch(url, opts) {
26373
26381
const location = headers.get('Location');
26374
26382
26375
26383
// HTTP fetch step 5.3
26376
- const locationURL = location === null ? null : resolve_url(request.url, location);
26384
+ let locationURL = null;
26385
+ try {
26386
+ locationURL = location === null ? null : new URL$1(location, request.url).toString();
26387
+ } catch (err) {
26388
+ // error here can only be invalid URL in Location: header
26389
+ // do not throw when options.redirect == manual
26390
+ // let the user extract the errorneous redirect URL
26391
+ if (request.redirect !== 'manual') {
26392
+ reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
26393
+ finalize();
26394
+ return;
26395
+ }
26396
+ }
26377
26397
26378
26398
// HTTP fetch step 5.5
26379
26399
switch (request.redirect) {
@@ -26421,6 +26441,12 @@ function fetch(url, opts) {
26421
26441
size: request.size
26422
26442
};
26423
26443
26444
+ if (!isDomainOrSubdomain(request.url, locationURL)) {
26445
+ for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
26446
+ requestOpts.headers.delete(name);
26447
+ }
26448
+ }
26449
+
26424
26450
// HTTP-redirect fetch step 9
26425
26451
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
26426
26452
reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
0 commit comments