Fix: HTTP Basic Auth fails when password contains colons (#5153) * Fix: HTTP Basic Auth fails when password contains colons The credentials in HTTP Basic Auth are formatted as base64(username:password). Per RFC 7617, the username must not contain a colon, but the password can. The previous code used `.split(':')` which splits on all colons, truncating passwords that contain ':' characters. Fix by splitting only on the first colon. * Use spread syntax for credential parsing

df0e1256e67276f203bb2dc93ba747bb18df8f26

HimeHina <1545340072@qq.com>

Signed
2 files changed, +4 -2Ignore whitespace
src/middleware/basicAuth.js+2 -1
@@ -32,9 +32,10 @@ const basicAuthMiddleware = async function (request, response, callback) {
32 }32 }
3333
34 const usePerUserAuth = PER_USER_BASIC_AUTH && ENABLE_ACCOUNTS;34 const usePerUserAuth = PER_USER_BASIC_AUTH && ENABLE_ACCOUNTS;
35 const [username, password] = Buffer.from(credentials, 'base64')35 const [username, ...passwordParts] = Buffer.from(credentials, 'base64')
36 .toString('utf8')36 .toString('utf8')
37 .split(':');37 .split(':');
38 const password = passwordParts.join(':');
3839
39 if (!usePerUserAuth && username === basicAuthUserName && password === basicAuthUserPassword) {40 if (!usePerUserAuth && username === basicAuthUserName && password === basicAuthUserPassword) {
40 return callback();41 return callback();
src/users.js+2 -1
@@ -822,9 +822,10 @@ async function basicUserLogin(request) {
822 return false;822 return false;
823 }823 }
824824
825 const [username, password] = Buffer.from(credentials, 'base64')825 const [username, ...passwordParts] = Buffer.from(credentials, 'base64')
826 .toString('utf8')826 .toString('utf8')
827 .split(':');827 .split(':');
828 const password = passwordParts.join(':');
828829
829 const userHandles = await getAllUserHandles();830 const userHandles = await getAllUserHandles();
830 for (const userHandle of userHandles) {831 for (const userHandle of userHandles) {