Fix setting basic auth creds with env
| @@ -876,8 +876,9 @@ const postSetupTasks = async function (v6Failed, v4Failed, useIPv6, useIPv4) { | |||
| 876 | 'Per-user basic authentication is enabled, but user accounts are disabled. This configuration may be insecure.', | 876 | 'Per-user basic authentication is enabled, but user accounts are disabled. This configuration may be insecure.', |
| 877 | )); | 877 | )); |
| 878 | } else if (!perUserBasicAuth) { | 878 | } else if (!perUserBasicAuth) { |
| 879 | const basicAuthUser = getConfigValue('basicAuthUser', {}); | 879 | const basicAuthUserName = getConfigValue('basicAuthUser.username', ''); |
| 880 | if (!basicAuthUser?.username || !basicAuthUser?.password) { | 880 | const basicAuthUserPassword = getConfigValue('basicAuthUser.password', ''); |
| 881 | if (!basicAuthUserName || !basicAuthUserPassword) { | ||
| 881 | console.warn(color.yellow( | 882 | console.warn(color.yellow( |
| 882 | 'Basic Authentication is enabled, but username or password is not set or empty!', | 883 | 'Basic Authentication is enabled, but username or password is not set or empty!', |
| 883 | )); | 884 | )); |
| @@ -5,7 +5,7 @@ | |||
| 5 | import { Buffer } from 'node:buffer'; | 5 | import { Buffer } from 'node:buffer'; |
| 6 | import storage from 'node-persist'; | 6 | import storage from 'node-persist'; |
| 7 | import { getAllUserHandles, toKey, getPasswordHash } from '../users.js'; | 7 | import { getAllUserHandles, toKey, getPasswordHash } from '../users.js'; |
| 8 | import { getConfig, getConfigValue, safeReadFileSync } from '../util.js'; | 8 | import { getConfigValue, safeReadFileSync } from '../util.js'; |
| 9 | 9 | ||
| 10 | const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false, 'boolean'); | 10 | const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false, 'boolean'); |
| 11 | const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false, 'boolean'); | 11 | const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false, 'boolean'); |
| @@ -17,7 +17,8 @@ const basicAuthMiddleware = async function (request, response, callback) { | |||
| 17 | return res.status(401).send(unauthorizedWebpage); | 17 | return res.status(401).send(unauthorizedWebpage); |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | const config = getConfig(); | 20 | const basicAuthUserName = getConfigValue('basicAuthUser.username'); |
| 21 | const basicAuthUserPassword = getConfigValue('basicAuthUser.password'); | ||
| 21 | const authHeader = request.headers.authorization; | 22 | const authHeader = request.headers.authorization; |
| 22 | 23 | ||
| 23 | if (!authHeader) { | 24 | if (!authHeader) { |
| @@ -35,7 +36,7 @@ const basicAuthMiddleware = async function (request, response, callback) { | |||
| 35 | .toString('utf8') | 36 | .toString('utf8') |
| 36 | .split(':'); | 37 | .split(':'); |
| 37 | 38 | ||
| 38 | if (!usePerUserAuth && username === config.basicAuthUser.username && password === config.basicAuthUser.password) { | 39 | if (!usePerUserAuth && username === basicAuthUserName && password === basicAuthUserPassword) { |
| 39 | return callback(); | 40 | return callback(); |
| 40 | } else if (usePerUserAuth) { | 41 | } else if (usePerUserAuth) { |
| 41 | const userHandles = await getAllUserHandles(); | 42 | const userHandles = await getAllUserHandles(); |