Socket
Socket
Sign inDemoInstall

follow-redirects

Package Overview
Dependencies
Maintainers
2
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

follow-redirects - npm Package Compare versions

Comparing version 1.14.4 to 1.14.5

58

index.js

@@ -21,3 +21,3 @@ var url = require("url");

"ERR_FR_REDIRECTION_FAILURE",
""
"Redirected request failed"
);

@@ -173,2 +173,3 @@ var TooManyRedirectsError = createErrorType(

function clearTimer() {
// Clear the timeout
if (self._timeout) {

@@ -178,2 +179,7 @@ clearTimeout(self._timeout);

}
// Clean up all attached listeners
self.removeListener("abort", clearTimer);
self.removeListener("error", clearTimer);
self.removeListener("response", clearTimer);
if (callback) {

@@ -202,4 +208,5 @@ self.removeListener("timeout", callback);

this.on("socket", destroyOnTimeout);
this.once("response", clearTimer);
this.once("error", clearTimer);
this.on("abort", clearTimer);
this.on("error", clearTimer);
this.on("response", clearTimer);

@@ -368,7 +375,21 @@ return this;

// Drop the Host header, as the redirect might lead to a different host
var previousHostName = removeMatchingHeaders(/^host$/i, this._options.headers) ||
url.parse(this._currentUrl).hostname;
var currentHostHeader = removeMatchingHeaders(/^host$/i, this._options.headers);
// If the redirect is relative, carry over the host of the last request
var currentUrlParts = url.parse(this._currentUrl);
var currentHost = currentHostHeader || currentUrlParts.host;
var currentUrl = /^\w+:/.test(location) ? this._currentUrl :
url.format(Object.assign(currentUrlParts, { host: currentHost }));
// Determine the URL of the redirection
var redirectUrl;
try {
redirectUrl = url.resolve(currentUrl, location);
}
catch (cause) {
this.emit("error", new RedirectionError(cause));
return;
}
// Create the redirected request
var redirectUrl = url.resolve(this._currentUrl, location);
debug("redirecting to", redirectUrl);

@@ -379,4 +400,4 @@ this._isRedirect = true;

// Drop the Authorization header if redirecting to another host
if (redirectUrlParts.hostname !== previousHostName) {
// Drop the Authorization header if redirecting to another domain
if (!(redirectUrlParts.host === currentHost || isSubdomainOf(redirectUrlParts.host, currentHost))) {
removeMatchingHeaders(/^authorization$/i, this._options.headers);

@@ -403,5 +424,3 @@ }

catch (cause) {
var error = new RedirectionError("Redirected request failed: " + cause.message);
error.cause = cause;
this.emit("error", error);
this.emit("error", new RedirectionError(cause));
}

@@ -516,3 +535,3 @@ }

if (regex.test(header)) {
lastValue = headers[header];
lastValue = headers[header].toString().trim();
delete headers[header];

@@ -525,5 +544,11 @@ }

function createErrorType(code, defaultMessage) {
function CustomError(message) {
function CustomError(cause) {
Error.captureStackTrace(this, this.constructor);
this.message = message || defaultMessage;
if (!cause) {
this.message = defaultMessage;
}
else {
this.message = defaultMessage + ": " + cause.message;
this.cause = cause;
}
}

@@ -545,4 +570,9 @@ CustomError.prototype = new Error();

function isSubdomainOf(subdomain, domain) {
const dot = subdomain.length - domain.length - 1;
return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
}
// Exports
module.exports = wrap({ http: http, https: https });
module.exports.wrap = wrap;
{
"name": "follow-redirects",
"version": "1.14.4",
"version": "1.14.5",
"description": "HTTP and HTTPS modules that follow redirects.",

@@ -5,0 +5,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc