Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9442,6 +9442,13 @@ catch (error) {
useNativeURL = error.code === "ERR_INVALID_URL";
}

// HTTP headers to drop across HTTP/HTTPS and domain boundaries
var sensitiveHeaders = [
"Authorization",
"Proxy-Authorization",
"Cookie",
];

// URL fields to preserve in copy operations
var preservedUrlFields = [
"auth",
Expand Down Expand Up @@ -9523,6 +9530,11 @@ function RedirectableRequest(options, responseCallback) {
}
};

// Create filter for sensitive HTTP headers
this._headerFilter = new RegExp("^(?:" +
sensitiveHeaders.concat(options.sensitiveHeaders).map(escapeRegex).join("|") +
")$", "i");

// Perform the first request
this._performRequest();
}
Expand Down Expand Up @@ -9706,6 +9718,9 @@ RedirectableRequest.prototype._sanitizeOptions = function (options) {
if (!options.headers) {
options.headers = {};
}
if (!isArray(options.sensitiveHeaders)) {
options.sensitiveHeaders = [];
}

// Since http.request treats host as an alias of hostname,
// but the url module interprets host as hostname plus port,
Expand Down Expand Up @@ -9888,7 +9903,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
redirectUrl.protocol !== "https:" ||
redirectUrl.host !== currentHost &&
!isSubdomain(redirectUrl.host, currentHost)) {
removeMatchingHeaders(/^(?:(?:proxy-)?authorization|cookie)$/i, this._options.headers);
removeMatchingHeaders(this._headerFilter, this._options.headers);
}

// Evaluate the beforeRedirect callback
Expand Down Expand Up @@ -10081,6 +10096,10 @@ function isSubdomain(subdomain, domain) {
return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
}

function isArray(value) {
return value instanceof Array;
}

function isString(value) {
return typeof value === "string" || value instanceof String;
}
Expand All @@ -10097,6 +10116,10 @@ function isURL(value) {
return URL && value instanceof URL;
}

function escapeRegex(regex) {
return regex.replace(/[\]\\/()*+?.$]/g, "\\$&");
}

// Exports
module.exports = wrap({ http: http, https: https });
module.exports.wrap = wrap;
Expand Down
Loading