From 8a326a6e7479e11e2bcc4bf462f55f008bd60719 Mon Sep 17 00:00:00 2001 From: ledlamp Date: Wed, 27 Aug 2025 15:42:30 -0700 Subject: [PATCH] Allow setting value of Express 'trust proxy' from config (#13034) * Allow setting value of Express 'trust proxy' from config * Allow config to disable 'trust proxy' if port is 80/443 And show the value of trust_proxy in log * fix errors --- src/webserver.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/webserver.js b/src/webserver.js index c27a4e5d4a..13310bef92 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -277,9 +277,12 @@ async function listen() { } } port = parseInt(port, 10); - if ((port !== 80 && port !== 443) || nconf.get('trust_proxy') === true) { - winston.info('🤝 Enabling \'trust proxy\''); - app.enable('trust proxy'); + + let trust_proxy = nconf.get('trust_proxy'); + if (trust_proxy == null && ![80, 443].includes(port)) trust_proxy = true; + if (trust_proxy) { + winston.info(`🤝 Setting 'trust proxy' to ${JSON.stringify(trust_proxy)}`); + app.set('trust proxy', trust_proxy); } if ((port === 80 || port === 443) && process.env.NODE_ENV !== 'development') {