Skip to content

Node.js based forum software built for the modern web

fix: closes #14510

Barış Soner Uşaklı0b0de8a46323
diff --git a/src/upgrades/4.14.3/trust_proxy.js b/src/upgrades/4.14.3/trust_proxy.js
new file mode 100644
index 0000000000..bb9812325d
--- /dev/null
+++ b/src/upgrades/4.14.3/trust_proxy.js
@@ -0,0 +1,20 @@
+'use strict';
+
+const install = require('../../install');
+
+module.exports = {
+ name: 'Backfill trust_proxy for upgraded installs',
+ timestamp: Date.UTC(2026, 6, 28),
+ method: async function () {
+ let configJSON;
+ try {
+ configJSON = require('../../../config.json') || {};
+ } catch (err) {
+ configJSON = {};
+ }
+
+ if (!Object.hasOwn(configJSON, 'trust_proxy')) {
+ await install.save({ trust_proxy: true });
+ }
+ },
+};
\ No newline at end of file
diff --git a/src/webserver.js b/src/webserver.js
index f16d2b35eb..c84f32a579 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -312,11 +312,13 @@ async function listen() {
port = parseInt(port, 10);
let trust_proxy = nconf.get('trust_proxy');
- if (trust_proxy == null && ![80, 443].includes(port)) {
- trust_proxy = true;
+ if (trust_proxy == null) {
+ trust_proxy = false;
+ winston.warn("[startup] 'trust_proxy' is not configured, so Express proxy trust is disabled by default. Set 'trust_proxy' in config.json only when NodeBB is behind a reverse proxy that strips or overwrites X-Forwarded-For from untrusted clients.");
}
- if (trust_proxy) {
- winston.info(`🤝 Setting 'trust proxy' to ${JSON.stringify(trust_proxy)}`);
+ if (trust_proxy != null) {
+ const trustProxyPrefix = trust_proxy === true ? '🤝' : '❌';
+ winston.info(`${trustProxyPrefix} Setting 'trust proxy' to ${JSON.stringify(trust_proxy)}`);
app.set('trust proxy', trust_proxy);
}