fix: added trust proxy config (#2751)

This commit is contained in:
Wyatt Johnson
2019-12-12 22:50:00 +00:00
committed by GitHub
parent 5580e14bf3
commit 637605a002
3 changed files with 30 additions and 3 deletions
+26 -2
View File
@@ -11,7 +11,12 @@ const { HELMET_CONFIGURATION } = require('./config');
const { MOUNT_PATH } = require('./url');
const routes = require('./routes');
const debug = require('debug')('talk:app');
const { ENABLE_TRACING, APOLLO_ENGINE_KEY, PORT } = require('./config');
const {
ENABLE_TRACING,
APOLLO_ENGINE_KEY,
PORT,
TRUST_PROXY,
} = require('./config');
const app = express();
@@ -58,7 +63,26 @@ if (ENABLE_TRACING && APOLLO_ENGINE_KEY) {
// Trust the first proxy in front of us, this will enable us to trust the fact
// that SSL was terminated correctly.
app.set('trust proxy', 1);
app.set(
'trust proxy',
(function() {
if (!TRUST_PROXY) {
return null;
}
const lowercase = TRUST_PROXY.toLowerCase();
if (lowercase === 'true' || lowercase === 'false') {
return lowercase === 'true';
}
const parsed = Number(TRUST_PROXY);
if (!isNaN(parsed)) {
return parsed;
}
return TRUST_PROXY;
})()
);
// Enable a suite of security good practices through helmet. We disable
// frameguard to allow crossdomain injection of the embed.
+3
View File
@@ -85,6 +85,9 @@ const CONFIG = {
// as report CSP violations.
ENABLE_STRICT_CSP: process.env.TALK_ENABLE_STRICT_CSP === 'TRUE',
// TRUST_PROXY allows control over the `trust proxy` configuration on express.
TRUST_PROXY: process.env.TALK_TRUST_PROXY || '1',
// LOGGING_LEVEL specifies the logging level used by the bunyan logger.
LOGGING_LEVEL: ['fatal', 'error', 'warn', 'info', 'debug', 'trace'].includes(
process.env.TALK_LOGGING_LEVEL
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "talk",
"version": "4.11.2",
"version": "4.11.3",
"description": "A better commenting experience from Vox Media.",
"main": "app.js",
"private": true,