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
Signed| @@ -32,9 +32,10 @@ const basicAuthMiddleware = async function (request, response, callback) { | |||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 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(':'); | ||
| 38 | 39 | ||
| 39 | if (!usePerUserAuth && username === basicAuthUserName && password === basicAuthUserPassword) { | 40 | if (!usePerUserAuth && username === basicAuthUserName && password === basicAuthUserPassword) { |
| 40 | return callback(); | 41 | return callback(); |
| @@ -822,9 +822,10 @@ async function basicUserLogin(request) { | |||
| 822 | return false; | 822 | return false; |
| 823 | } | 823 | } |
| 824 | 824 | ||
| 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(':'); | ||
| 828 | 829 | ||
| 829 | const userHandles = await getAllUserHandles(); | 830 | const userHandles = await getAllUserHandles(); |
| 830 | for (const userHandle of userHandles) { | 831 | for (const userHandle of userHandles) { |