fix(middleware): skip logging for blocked connections to specific paths

42f850239fa59e627ee420d4bd6a09cadc18ebcb

KevinSun <paver.mails+github@gmail.com>

Signed
1 files changed, +13 -5Ignore whitespace
src/middleware/whitelist.js+13 -5
@@ -55,6 +55,10 @@ export default function whitelistMiddleware(whitelistMode) {
55 safeReadFileSync('./public/error/forbidden-by-whitelist.html') ?? '',55 safeReadFileSync('./public/error/forbidden-by-whitelist.html') ?? '',
56 );56 );
5757
58 const noLogPaths = [
59 '/favicon.ico',
60 ];
61
58 return function (req, res, next) {62 return function (req, res, next) {
59 const clientIp = getIpFromRequest(req);63 const clientIp = getIpFromRequest(req);
60 const forwardedIp = getForwardedIp(req);64 const forwardedIp = getForwardedIp(req);
@@ -68,11 +72,15 @@ export default function whitelistMiddleware(whitelistMode) {
68 const ipDetails = forwardedIp72 const ipDetails = forwardedIp
69 ? `${clientIp} (forwarded from ${forwardedIp})`73 ? `${clientIp} (forwarded from ${forwardedIp})`
70 : clientIp;74 : clientIp;
71 console.warn(75
72 color.red(76 if (!noLogPaths.includes(req.path)) {
73 `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`,77 console.warn(
74 ),78 color.red(
75 );79 `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`,
80 ),
81 );
82 }
83
76 return res.status(403).send(forbiddenWebpage({ ipDetails }));84 return res.status(403).send(forbiddenWebpage({ ipDetails }));
77 }85 }
78 next();86 next();