@@ -34585,9 +34585,17 @@ AbortError.prototype = Object.create(Error.prototype);
3458534585AbortError.prototype.constructor = AbortError;
3458634586AbortError.prototype.name = 'AbortError';
3458734587
34588+ const URL$1 = Url.URL || whatwgUrl.URL;
34589+
3458834590// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
3458934591const PassThrough$1 = Stream.PassThrough;
34590- const resolve_url = Url.resolve;
34592+
34593+ const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
34594+ const orig = new URL$1(original).hostname;
34595+ const dest = new URL$1(destination).hostname;
34596+
34597+ return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
34598+ };
3459134599
3459234600/**
3459334601 * Fetch function
@@ -34675,7 +34683,19 @@ function fetch(url, opts) {
3467534683 const location = headers.get('Location');
3467634684
3467734685 // HTTP fetch step 5.3
34678- const locationURL = location === null ? null : resolve_url(request.url, location);
34686+ let locationURL = null;
34687+ try {
34688+ locationURL = location === null ? null : new URL$1(location, request.url).toString();
34689+ } catch (err) {
34690+ // error here can only be invalid URL in Location: header
34691+ // do not throw when options.redirect == manual
34692+ // let the user extract the errorneous redirect URL
34693+ if (request.redirect !== 'manual') {
34694+ reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
34695+ finalize();
34696+ return;
34697+ }
34698+ }
3467934699
3468034700 // HTTP fetch step 5.5
3468134701 switch (request.redirect) {
@@ -34723,6 +34743,12 @@ function fetch(url, opts) {
3472334743 size: request.size
3472434744 };
3472534745
34746+ if (!isDomainOrSubdomain(request.url, locationURL)) {
34747+ for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
34748+ requestOpts.headers.delete(name);
34749+ }
34750+ }
34751+
3472634752 // HTTP-redirect fetch step 9
3472734753 if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
3472834754 reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
0 commit comments