[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 | if (basicAuthMode) { | 760 | if (basicAuthMode) { |
| 761 | if (!perUserBasicAuth) { | 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 | const basicAuthUser = getConfigValue('basicAuthUser', {}); | 764 | const basicAuthUser = getConfigValue('basicAuthUser', {}); |
| 763 | if (!basicAuthUser?.username || !basicAuthUser?.password) { | 765 | if (!basicAuthUser?.username || !basicAuthUser?.password) { |
| 764 | console.warn(color.yellow('Basic Authentication is enabled, but username or password is not set or empty!')); | 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 | const storage = require('node-persist'); | 7 | const storage = require('node-persist'); |
| 8 | 8 | ||
| 9 | const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false); | 9 | const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false); |
| 10 | const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false); | ||
| 10 | 11 | ||
| 11 | const unauthorizedResponse = (res) => { | 12 | const unauthorizedResponse = (res) => { |
| 12 | res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"'); | 13 | res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"'); |
| @@ -27,13 +28,14 @@ const basicAuthMiddleware = async function (request, response, callback) { | |||
| 27 | return unauthorizedResponse(response); | 28 | return unauthorizedResponse(response); |
| 28 | } | 29 | } |
| 29 | 30 | ||
| 31 | const usePerUserAuth = PER_USER_BASIC_AUTH && ENABLE_ACCOUNTS; | ||
| 30 | const [username, password] = Buffer.from(credentials, 'base64') | 32 | const [username, password] = Buffer.from(credentials, 'base64') |
| 31 | .toString('utf8') | 33 | .toString('utf8') |
| 32 | .split(':'); | 34 | .split(':'); |
| 33 | 35 | ||
| 34 | if (!PER_USER_BASIC_AUTH && username === config.basicAuthUser.username && password === config.basicAuthUser.password) { | 36 | if (!usePerUserAuth && username === config.basicAuthUser.username && password === config.basicAuthUser.password) { |
| 35 | return callback(); | 37 | return callback(); |
| 36 | } else if (PER_USER_BASIC_AUTH) { | 38 | } else if (usePerUserAuth) { |
| 37 | const userHandles = await getAllUserHandles(); | 39 | const userHandles = await getAllUserHandles(); |
| 38 | for (const userHandle of userHandles) { | 40 | for (const userHandle of userHandles) { |
| 39 | if (username === userHandle) { | 41 | if (username === userHandle) { |