From 84b8a6020a35073452619afe2f481a4dc30f8706 Mon Sep 17 00:00:00 2001 From: Terry Rogers Date: Thu, 5 Dec 2024 14:13:49 -0500 Subject: [PATCH] Handle redirects to invalid URLs that break the parser Cherry-pick 00526e2cab551c7904c6e5e7a6418a7d3ac1d526 --- lib/redirect.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/redirect.js b/lib/redirect.js index a27026869..3c98495fa 100644 --- a/lib/redirect.js +++ b/lib/redirect.js @@ -123,7 +123,11 @@ Redirect.prototype.onResponse = function (response, callback) { } var uriPrev = request.uri - request.uri = urlParser.parse(redirectTo) + try { + request.uri = urlParser.parse(redirectTo) + } catch (e) { + return callback(new Error('Failed to parse url: ' + request.uri.href)) + } // handle the case where we change protocol from https to http or vice versa if (request.uri.protocol !== uriPrev.protocol && self.allowInsecureRedirect) {