@@ -32647,7 +32647,7 @@ Object.defineProperty(Response.prototype, Symbol.toStringTag, {
32647
32647
});
32648
32648
32649
32649
const INTERNALS$2 = Symbol('Request internals');
32650
- const URL = whatwgUrl.URL;
32650
+ const URL = Url.URL || whatwgUrl.URL;
32651
32651
32652
32652
// fix an issue where "format", "parse" aren't a named export for node <10
32653
32653
const parse_url = Url.parse;
@@ -32910,9 +32910,17 @@ AbortError.prototype = Object.create(Error.prototype);
32910
32910
AbortError.prototype.constructor = AbortError;
32911
32911
AbortError.prototype.name = 'AbortError';
32912
32912
32913
+ const URL$1 = Url.URL || whatwgUrl.URL;
32914
+
32913
32915
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
32914
32916
const PassThrough$1 = Stream.PassThrough;
32915
- const resolve_url = Url.resolve;
32917
+
32918
+ const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
32919
+ const orig = new URL$1(original).hostname;
32920
+ const dest = new URL$1(destination).hostname;
32921
+
32922
+ return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
32923
+ };
32916
32924
32917
32925
/**
32918
32926
* Fetch function
@@ -33000,7 +33008,19 @@ function fetch(url, opts) {
33000
33008
const location = headers.get('Location');
33001
33009
33002
33010
// HTTP fetch step 5.3
33003
- const locationURL = location === null ? null : resolve_url(request.url, location);
33011
+ let locationURL = null;
33012
+ try {
33013
+ locationURL = location === null ? null : new URL$1(location, request.url).toString();
33014
+ } catch (err) {
33015
+ // error here can only be invalid URL in Location: header
33016
+ // do not throw when options.redirect == manual
33017
+ // let the user extract the errorneous redirect URL
33018
+ if (request.redirect !== 'manual') {
33019
+ reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
33020
+ finalize();
33021
+ return;
33022
+ }
33023
+ }
33004
33024
33005
33025
// HTTP fetch step 5.5
33006
33026
switch (request.redirect) {
@@ -33048,6 +33068,12 @@ function fetch(url, opts) {
33048
33068
size: request.size
33049
33069
};
33050
33070
33071
+ if (!isDomainOrSubdomain(request.url, locationURL)) {
33072
+ for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
33073
+ requestOpts.headers.delete(name);
33074
+ }
33075
+ }
33076
+
33051
33077
// HTTP-redirect fetch step 9
33052
33078
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
33053
33079
reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
0 commit comments