Fix setting basic auth creds with env

00bb36f764e7fe232043347978badf32cc1cd639

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +7 -5Ignore whitespace
server.js+3 -2
@@ -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 ));
src/middleware/basicAuth.js+4 -3
@@ -5,7 +5,7 @@
5import { Buffer } from 'node:buffer';5import { Buffer } from 'node:buffer';
6import storage from 'node-persist';6import storage from 'node-persist';
7import { getAllUserHandles, toKey, getPasswordHash } from '../users.js';7import { getAllUserHandles, toKey, getPasswordHash } from '../users.js';
8import { getConfig, getConfigValue, safeReadFileSync } from '../util.js';8import { getConfigValue, safeReadFileSync } from '../util.js';
99
10const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false, 'boolean');10const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false, 'boolean');
11const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false, 'boolean');11const 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 };
1919
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;
2223
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(':');
3738
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();