@@ -7768,7 +7768,7 @@ Object.defineProperty(Response.prototype, Symbol.toStringTag, {
7768
7768
});
7769
7769
7770
7770
const INTERNALS$2 = Symbol('Request internals');
7771
- const URL = whatwgUrl.URL;
7771
+ const URL = Url.URL || whatwgUrl.URL;
7772
7772
7773
7773
// fix an issue where "format", "parse" aren't a named export for node <10
7774
7774
const parse_url = Url.parse;
@@ -8031,9 +8031,17 @@ AbortError.prototype = Object.create(Error.prototype);
8031
8031
AbortError.prototype.constructor = AbortError;
8032
8032
AbortError.prototype.name = 'AbortError';
8033
8033
8034
+ const URL$1 = Url.URL || whatwgUrl.URL;
8035
+
8034
8036
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
8035
8037
const PassThrough$1 = Stream.PassThrough;
8036
- const resolve_url = Url.resolve;
8038
+
8039
+ const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
8040
+ const orig = new URL$1(original).hostname;
8041
+ const dest = new URL$1(destination).hostname;
8042
+
8043
+ return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
8044
+ };
8037
8045
8038
8046
/**
8039
8047
* Fetch function
@@ -8121,7 +8129,19 @@ function fetch(url, opts) {
8121
8129
const location = headers.get('Location');
8122
8130
8123
8131
// HTTP fetch step 5.3
8124
- const locationURL = location === null ? null : resolve_url(request.url, location);
8132
+ let locationURL = null;
8133
+ try {
8134
+ locationURL = location === null ? null : new URL$1(location, request.url).toString();
8135
+ } catch (err) {
8136
+ // error here can only be invalid URL in Location: header
8137
+ // do not throw when options.redirect == manual
8138
+ // let the user extract the errorneous redirect URL
8139
+ if (request.redirect !== 'manual') {
8140
+ reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
8141
+ finalize();
8142
+ return;
8143
+ }
8144
+ }
8125
8145
8126
8146
// HTTP fetch step 5.5
8127
8147
switch (request.redirect) {
@@ -8169,6 +8189,12 @@ function fetch(url, opts) {
8169
8189
size: request.size
8170
8190
};
8171
8191
8192
+ if (!isDomainOrSubdomain(request.url, locationURL)) {
8193
+ for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
8194
+ requestOpts.headers.delete(name);
8195
+ }
8196
+ }
8197
+
8172
8198
// HTTP-redirect fetch step 9
8173
8199
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
8174
8200
reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
0 commit comments