mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
fix(middleware): skip logging for blocked connections to specific paths
This commit is contained in:
@@ -55,6 +55,10 @@ export default function whitelistMiddleware(whitelistMode) {
|
|||||||
safeReadFileSync('./public/error/forbidden-by-whitelist.html') ?? '',
|
safeReadFileSync('./public/error/forbidden-by-whitelist.html') ?? '',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const noLogPaths = [
|
||||||
|
'/favicon.ico',
|
||||||
|
];
|
||||||
|
|
||||||
return function (req, res, next) {
|
return function (req, res, next) {
|
||||||
const clientIp = getIpFromRequest(req);
|
const clientIp = getIpFromRequest(req);
|
||||||
const forwardedIp = getForwardedIp(req);
|
const forwardedIp = getForwardedIp(req);
|
||||||
@@ -68,11 +72,15 @@ export default function whitelistMiddleware(whitelistMode) {
|
|||||||
const ipDetails = forwardedIp
|
const ipDetails = forwardedIp
|
||||||
? `${clientIp} (forwarded from ${forwardedIp})`
|
? `${clientIp} (forwarded from ${forwardedIp})`
|
||||||
: clientIp;
|
: clientIp;
|
||||||
|
|
||||||
|
if (!noLogPaths.includes(req.path)) {
|
||||||
console.warn(
|
console.warn(
|
||||||
color.red(
|
color.red(
|
||||||
`Blocked connection from ${clientIp}; User Agent: ${userAgent}\n\tTo allow this connection, add its IP address to the whitelist or disable whitelist mode by editing config.yaml in the root directory of your SillyTavern installation.\n`,
|
`Blocked connection from ${clientIp}; User Agent: ${userAgent}\n\tTo allow this connection, add its IP address to the whitelist or disable whitelist mode by editing config.yaml in the root directory of your SillyTavern installation.\n`,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return res.status(403).send(forbiddenWebpage({ ipDetails }));
|
return res.status(403).send(forbiddenWebpage({ ipDetails }));
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
|
Reference in New Issue
Block a user