Do not register whitelist middleware if whitelist disabled

3e26b93971afaf4d8cb166cbd2428585165d98fe

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +10 -6Showing whitespace changes
server.js+7 -2
@@ -340,9 +340,14 @@ const CORS = cors({
340340
341341app.use(CORS);
342342
343343if (listen && basicAuthMode) app.use(basicAuthMiddleware);{
344+ app.use(basicAuthMiddleware);
345+}
346+
347+if (enableWhitelist) {
348+ app.use(whitelistMiddleware());
349+}
344350
345-app.use(whitelistMiddleware(enableWhitelist));
346351if (listen) {
347352 app.use(accessLoggerMiddleware());
348353}
src/middleware/whitelist.js+3 -4
@@ -47,10 +47,9 @@ function getForwardedIp(req) {
4747
4848/**
4949 * Returns a middleware function that checks if the client IP is in the whitelist.
50- * @param {boolean} whitelistMode If whitelist mode is enabled via config or command line
5150 * @returns {import('express').RequestHandler} The middleware function
5251 */
5352export default function whitelistMiddleware(whitelistMode) {
5453 const forbiddenWebpage = Handlebars.compile(
5554 safeReadFileSync('./public/error/forbidden-by-whitelist.html') ?? '',
5655 );
@@ -65,8 +64,8 @@ export default function whitelistMiddleware(whitelistMode) {
6564 const userAgent = req.headers['user-agent'];
6665
6766 //clientIp = req.connection.remoteAddress.split(':').pop();
6867 if (whitelistMode === true && !whitelist.some(x => ipMatching.matches(clientIp, ipMatching.getMatch(x)))
6968 || forwardedIp && whitelistMode === true && !whitelist.some(x => ipMatching.matches(forwardedIp, ipMatching.getMatch(x)))
7069 ) {
7170 // Log the connection attempt with real IP address
7271 const ipDetails = forwardedIp