[bug] Don't allow per user auth with accounts disabled
| @@ -758,7 +758,9 @@ const postSetupTasks = async function (v6Failed, v4Failed) { | ||
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | if (basicAuthMode) { |
| 761 | 761 | if (!perUserBasicAuth && !enableAccounts) { |
| 762 | + console.error(color.red('Per-user basic authentication is enabled, but user accounts are disabled. This configuration may be insecure.')); | |
| 763 | + } else if (!perUserBasicAuth) { | |
| 762 | 764 | const basicAuthUser = getConfigValue('basicAuthUser', {}); |
| 763 | 765 | if (!basicAuthUser?.username || !basicAuthUser?.password) { |
| 764 | 766 | console.warn(color.yellow('Basic Authentication is enabled, but username or password is not set or empty!')); |
| @@ -7,6 +7,7 @@ const { getConfig, getConfigValue } = require('../util.js'); | ||
| 7 | 7 | const storage = require('node-persist'); |
| 8 | 8 | |
| 9 | 9 | const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false); |
| 10 | +const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false); | |
| 10 | 11 | |
| 11 | 12 | const unauthorizedResponse = (res) => { |
| 12 | 13 | res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"'); |
| @@ -27,13 +28,14 @@ const basicAuthMiddleware = async function (request, response, callback) { | ||
| 27 | 28 | return unauthorizedResponse(response); |
| 28 | 29 | } |
| 29 | 30 | |
| 31 | + const usePerUserAuth = PER_USER_BASIC_AUTH && ENABLE_ACCOUNTS; | |
| 30 | 32 | const [username, password] = Buffer.from(credentials, 'base64') |
| 31 | 33 | .toString('utf8') |
| 32 | 34 | .split(':'); |
| 33 | 35 | |
| 34 | 36 | if (!PER_USER_BASIC_AUTHusePerUserAuth && username === config.basicAuthUser.username && password === config.basicAuthUser.password) { |
| 35 | 37 | return callback(); |
| 36 | 38 | } else if (PER_USER_BASIC_AUTHusePerUserAuth) { |
| 37 | 39 | const userHandles = await getAllUserHandles(); |
| 38 | 40 | for (const userHandle of userHandles) { |
| 39 | 41 | if (username === userHandle) { |