@@ -52870,9 +52870,17 @@ AbortError.prototype = Object.create(Error.prototype);
52870
52870
AbortError.prototype.constructor = AbortError;
52871
52871
AbortError.prototype.name = 'AbortError';
52872
52872
52873
+ const URL$1 = Url.URL || whatwgUrl.URL;
52874
+
52873
52875
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
52874
52876
const PassThrough$1 = Stream.PassThrough;
52875
- const resolve_url = Url.resolve;
52877
+
52878
+ const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
52879
+ const orig = new URL$1(original).hostname;
52880
+ const dest = new URL$1(destination).hostname;
52881
+
52882
+ return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
52883
+ };
52876
52884
52877
52885
/**
52878
52886
* Fetch function
@@ -52960,7 +52968,19 @@ function fetch(url, opts) {
52960
52968
const location = headers.get('Location');
52961
52969
52962
52970
// HTTP fetch step 5.3
52963
- const locationURL = location === null ? null : resolve_url(request.url, location);
52971
+ let locationURL = null;
52972
+ try {
52973
+ locationURL = location === null ? null : new URL$1(location, request.url).toString();
52974
+ } catch (err) {
52975
+ // error here can only be invalid URL in Location: header
52976
+ // do not throw when options.redirect == manual
52977
+ // let the user extract the errorneous redirect URL
52978
+ if (request.redirect !== 'manual') {
52979
+ reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
52980
+ finalize();
52981
+ return;
52982
+ }
52983
+ }
52964
52984
52965
52985
// HTTP fetch step 5.5
52966
52986
switch (request.redirect) {
@@ -53008,6 +53028,12 @@ function fetch(url, opts) {
53008
53028
size: request.size
53009
53029
};
53010
53030
53031
+ if (!isDomainOrSubdomain(request.url, locationURL)) {
53032
+ for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
53033
+ requestOpts.headers.delete(name);
53034
+ }
53035
+ }
53036
+
53011
53037
// HTTP-redirect fetch step 9
53012
53038
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
53013
53039
reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
0 commit comments