mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-07 07:06:05 +01:00
Whitelist to check listen mode via console
This commit is contained in:
parent
4d98310848
commit
c94460714d
@ -123,7 +123,7 @@ app.use(CORS);
|
||||
|
||||
if (listen && getConfigValue('basicAuthMode', false)) app.use(basicAuthMiddleware);
|
||||
|
||||
app.use(whitelistMiddleware);
|
||||
app.use(whitelistMiddleware(listen));
|
||||
|
||||
// CSRF Protection //
|
||||
if (!cliArguments.disableCsrf) {
|
||||
|
@ -8,7 +8,6 @@ const { color, getConfigValue } = require('../util');
|
||||
const whitelistPath = path.join(process.cwd(), './whitelist.txt');
|
||||
let whitelist = getConfigValue('whitelist', []);
|
||||
let knownIPs = new Set();
|
||||
const listen = getConfigValue('listen', false);
|
||||
const whitelistMode = getConfigValue('whitelistMode', true);
|
||||
|
||||
if (fs.existsSync(whitelistPath)) {
|
||||
@ -34,7 +33,13 @@ function getIpFromRequest(req) {
|
||||
return clientIp;
|
||||
}
|
||||
|
||||
const whitelistMiddleware = function (req, res, next) {
|
||||
/**
|
||||
* Returns a middleware function that checks if the client IP is in the whitelist.
|
||||
* @param {boolean} listen If listen mode is enabled via config or command line
|
||||
* @returns {import('express').RequestHandler} The middleware function
|
||||
*/
|
||||
function whitelistMiddleware(listen) {
|
||||
return function (req, res, next) {
|
||||
const clientIp = getIpFromRequest(req);
|
||||
|
||||
if (listen && !knownIPs.has(clientIp)) {
|
||||
@ -58,6 +63,7 @@ const whitelistMiddleware = function (req, res, next) {
|
||||
return res.status(403).send('<b>Forbidden</b>: Connection attempt from <b>' + clientIp + '</b>. If you are attempting to connect, please add your IP address in whitelist or disable whitelist mode in config.yaml in root of SillyTavern folder.');
|
||||
}
|
||||
next();
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = whitelistMiddleware;
|
||||
|
Loading…
Reference in New Issue
Block a user