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 | 34 | const usePerUserAuth = PER_USER_BASIC_AUTH && ENABLE_ACCOUNTS; |
| 35 | 35 | const [username, password...passwordParts] = Buffer.from(credentials, 'base64') |
| 36 | 36 | .toString('utf8') |
| 37 | 37 | .split(':'); |
| 38 | + const password = passwordParts.join(':'); | |
| 38 | 39 | |
| 39 | 40 | if (!usePerUserAuth && username === basicAuthUserName && password === basicAuthUserPassword) { |
| 40 | 41 | return callback(); |
| @@ -822,9 +822,10 @@ async function basicUserLogin(request) { | ||
| 822 | 822 | return false; |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | const [username, password...passwordParts] = Buffer.from(credentials, 'base64') |
| 826 | 826 | .toString('utf8') |
| 827 | 827 | .split(':'); |
| 828 | + const password = passwordParts.join(':'); | |
| 828 | 829 | |
| 829 | 830 | const userHandles = await getAllUserHandles(); |
| 830 | 831 | for (const userHandle of userHandles) { |