@@ -9167,6 +9167,13 @@ catch (error) {
91679167 useNativeURL = error.code === "ERR_INVALID_URL";
91689168}
91699169
9170+ // HTTP headers to drop across HTTP/HTTPS and domain boundaries
9171+ var sensitiveHeaders = [
9172+ "Authorization",
9173+ "Proxy-Authorization",
9174+ "Cookie",
9175+ ];
9176+
91709177// URL fields to preserve in copy operations
91719178var preservedUrlFields = [
91729179 "auth",
@@ -9248,6 +9255,11 @@ function RedirectableRequest(options, responseCallback) {
92489255 }
92499256 };
92509257
9258+ // Create filter for sensitive HTTP headers
9259+ this._headerFilter = new RegExp("^(?:" +
9260+ sensitiveHeaders.concat(options.sensitiveHeaders).map(escapeRegex).join("|") +
9261+ ")$", "i");
9262+
92519263 // Perform the first request
92529264 this._performRequest();
92539265}
@@ -9431,6 +9443,9 @@ RedirectableRequest.prototype._sanitizeOptions = function (options) {
94319443 if (!options.headers) {
94329444 options.headers = {};
94339445 }
9446+ if (!isArray(options.sensitiveHeaders)) {
9447+ options.sensitiveHeaders = [];
9448+ }
94349449
94359450 // Since http.request treats host as an alias of hostname,
94369451 // but the url module interprets host as hostname plus port,
@@ -9613,7 +9628,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
96139628 redirectUrl.protocol !== "https:" ||
96149629 redirectUrl.host !== currentHost &&
96159630 !isSubdomain(redirectUrl.host, currentHost)) {
9616- removeMatchingHeaders(/^(?:(?:proxy-)?authorization|cookie)$/i , this._options.headers);
9631+ removeMatchingHeaders(this._headerFilter , this._options.headers);
96179632 }
96189633
96199634 // Evaluate the beforeRedirect callback
@@ -9806,6 +9821,10 @@ function isSubdomain(subdomain, domain) {
98069821 return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
98079822}
98089823
9824+ function isArray(value) {
9825+ return value instanceof Array;
9826+ }
9827+
98099828function isString(value) {
98109829 return typeof value === "string" || value instanceof String;
98119830}
@@ -9822,6 +9841,10 @@ function isURL(value) {
98229841 return URL && value instanceof URL;
98239842}
98249843
9844+ function escapeRegex(regex) {
9845+ return regex.replace(/[\]\\/()*+?.$]/g, "\\$&");
9846+ }
9847+
98259848// Exports
98269849module.exports = wrap({ http: http, https: https });
98279850module.exports.wrap = wrap;
0 commit comments