From 972c83cd52b5f3f9b7bef72bae2c5eb843a6f4c7 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 15 Jul 2021 17:35:03 +0100 Subject: [PATCH 1/3] Fix for #3067 Check if there are any content to the credential object --- .../node_modules/@node-red/nodes/core/network/21-httprequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js index a498d4ac7..2c34b15b8 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js @@ -205,7 +205,7 @@ module.exports = function(RED) { } } } - if (this.credentials) { + if (Object.keys(this.credentials).length != 0) { if (this.authType === "basic") { // Workaround for https://github.com/sindresorhus/got/issues/1169 var cred = "" From 81f0fb3c74213aad776ef2b11b033928a86ab0ac Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 15 Jul 2021 18:32:51 +0100 Subject: [PATCH 2/3] Fix creds in URL --- .../nodes/core/network/21-httprequest.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js index 2c34b15b8..1d8bc643a 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js @@ -205,23 +205,25 @@ module.exports = function(RED) { } } } + var parsedURL = new URL(url) + if (parsedURL.username) { + this.credentials.user = parsedURL.username + } + if (parsedURL.password) { + this.credentials.password = parsedURL.password + } if (Object.keys(this.credentials).length != 0) { if (this.authType === "basic") { // Workaround for https://github.com/sindresorhus/got/issues/1169 var cred = "" - var parsedURL = new URL(url) if (this.credentials.user) { // opts.username = this.credentials.user; cred = this.credentials.user - } else if (parsedURL.username) { - cred = parsedURL.username - } + } if (this.credentials.password) { // opts.password = this.credentials.password; cred += ":" + this.credentials.password - } else if (parsedURL.password) { - cred += ":" + parsedURL.password - } + } // build own basic auth header opts.headers.Authorization = "Basic " + Buffer.from(cred).toString("base64"); } else if (this.authType === "digest") { From 32dd186f4d2dd155c9752d068d914731f85a9a57 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Fri, 16 Jul 2021 08:47:30 +0100 Subject: [PATCH 3/3] Prevent Overwite of configured creds --- .../@node-red/nodes/core/network/21-httprequest.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js index 1d8bc643a..2a8712878 100644 --- a/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/network/21-httprequest.js @@ -206,10 +206,11 @@ module.exports = function(RED) { } } var parsedURL = new URL(url) - if (parsedURL.username) { + this.credentials = this.credentials || {} + if (parsedURL.username && !this.credentials.user) { this.credentials.user = parsedURL.username } - if (parsedURL.password) { + if (parsedURL.password && !this.credentials.password) { this.credentials.password = parsedURL.password } if (Object.keys(this.credentials).length != 0) {