mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix setting basic auth creds with env
This commit is contained in:
@@ -876,8 +876,9 @@ const postSetupTasks = async function (v6Failed, v4Failed, useIPv6, useIPv4) {
|
|||||||
'Per-user basic authentication is enabled, but user accounts are disabled. This configuration may be insecure.',
|
'Per-user basic authentication is enabled, but user accounts are disabled. This configuration may be insecure.',
|
||||||
));
|
));
|
||||||
} else if (!perUserBasicAuth) {
|
} else if (!perUserBasicAuth) {
|
||||||
const basicAuthUser = getConfigValue('basicAuthUser', {});
|
const basicAuthUserName = getConfigValue('basicAuthUser.username', '');
|
||||||
if (!basicAuthUser?.username || !basicAuthUser?.password) {
|
const basicAuthUserPassword = getConfigValue('basicAuthUser.password', '');
|
||||||
|
if (!basicAuthUserName || !basicAuthUserPassword) {
|
||||||
console.warn(color.yellow(
|
console.warn(color.yellow(
|
||||||
'Basic Authentication is enabled, but username or password is not set or empty!',
|
'Basic Authentication is enabled, but username or password is not set or empty!',
|
||||||
));
|
));
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
import { Buffer } from 'node:buffer';
|
import { Buffer } from 'node:buffer';
|
||||||
import storage from 'node-persist';
|
import storage from 'node-persist';
|
||||||
import { getAllUserHandles, toKey, getPasswordHash } from '../users.js';
|
import { getAllUserHandles, toKey, getPasswordHash } from '../users.js';
|
||||||
import { getConfig, getConfigValue, safeReadFileSync } from '../util.js';
|
import { getConfigValue, safeReadFileSync } from '../util.js';
|
||||||
|
|
||||||
const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false, 'boolean');
|
const PER_USER_BASIC_AUTH = getConfigValue('perUserBasicAuth', false, 'boolean');
|
||||||
const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false, 'boolean');
|
const ENABLE_ACCOUNTS = getConfigValue('enableUserAccounts', false, 'boolean');
|
||||||
@@ -17,7 +17,8 @@ const basicAuthMiddleware = async function (request, response, callback) {
|
|||||||
return res.status(401).send(unauthorizedWebpage);
|
return res.status(401).send(unauthorizedWebpage);
|
||||||
};
|
};
|
||||||
|
|
||||||
const config = getConfig();
|
const basicAuthUserName = getConfigValue('basicAuthUser.username');
|
||||||
|
const basicAuthUserPassword = getConfigValue('basicAuthUser.password');
|
||||||
const authHeader = request.headers.authorization;
|
const authHeader = request.headers.authorization;
|
||||||
|
|
||||||
if (!authHeader) {
|
if (!authHeader) {
|
||||||
@@ -35,7 +36,7 @@ const basicAuthMiddleware = async function (request, response, callback) {
|
|||||||
.toString('utf8')
|
.toString('utf8')
|
||||||
.split(':');
|
.split(':');
|
||||||
|
|
||||||
if (!usePerUserAuth && username === config.basicAuthUser.username && password === config.basicAuthUser.password) {
|
if (!usePerUserAuth && username === basicAuthUserName && password === basicAuthUserPassword) {
|
||||||
return callback();
|
return callback();
|
||||||
} else if (usePerUserAuth) {
|
} else if (usePerUserAuth) {
|
||||||
const userHandles = await getAllUserHandles();
|
const userHandles = await getAllUserHandles();
|
||||||
|
Reference in New Issue
Block a user