From 87af31de202b56b6804803a3f14ed6fabefe5089 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 28 Oct 2021 09:18:17 +0100 Subject: [PATCH 1/2] HTTP Basic Auth should always add : to username fix for #3235 --- .../@node-red/nodes/core/network/21-httprequest.js | 4 ++-- 1 file changed, 2 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 3fe58d772..86c9ac2c7 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 @@ -302,11 +302,11 @@ in your Node-RED user directory (${RED.settings.userDir}). var cred = "" if (this.credentials.user) { // opts.username = this.credentials.user; - cred = this.credentials.user + cred = this.credentials.user + ":" } if (this.credentials.password) { // opts.password = this.credentials.password; - cred += ":" + this.credentials.password + cred += this.credentials.password } // build own basic auth header opts.headers.Authorization = "Basic " + Buffer.from(cred).toString("base64"); From b77a2dc35327b5492076bd069e2ce44ae834663a Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 28 Oct 2021 10:08:28 +0100 Subject: [PATCH 2/2] Better fix --- .../nodes/core/network/21-httprequest.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 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 86c9ac2c7..e9bf49d68 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 @@ -298,18 +298,14 @@ in your Node-RED user directory (${RED.settings.userDir}). } if (Object.keys(this.credentials).length != 0) { if (this.authType === "basic") { - // Workaround for https://github.com/sindresorhus/got/issues/1169 - var cred = "" - if (this.credentials.user) { - // opts.username = this.credentials.user; - cred = this.credentials.user + ":" - } - if (this.credentials.password) { - // opts.password = this.credentials.password; - cred += this.credentials.password + // Workaround for https://github.com/sindresorhus/got/issues/1169 (fixed in got v12) + // var cred = "" + if (this.credentials.user || this.credentials.password) { + // cred = `${this.credentials.user}:${this.credentials.password}`; + opts.headers.Authorization = "Basic " + Buffer.from(`${this.credentials.user}:${this.credentials.password}`).toString("base64"); } // build own basic auth header - opts.headers.Authorization = "Basic " + Buffer.from(cred).toString("base64"); + // opts.headers.Authorization = "Basic " + Buffer.from(cred).toString("base64"); } else if (this.authType === "digest") { let digestCreds = this.credentials; let sentCreds = false;