Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ app.use(pinoHttp({
// Operators opt in via TRUST_PROXY (true|false|<hop count>). Default
// false to avoid the security pitfall of trusting X-Forwarded-For
// from a non-proxied client.
//
// The hop-count branch uses a strict regex match (^\d+$) rather than
// `parseInt + !isNaN`, because parseInt is lenient — it would happily
// turn `TRUST_PROXY=1abc` (an operator typo) into `1` and silently
// trust one hop. With the regex an invalid value falls through to
// the implicit Express default (no trust) instead of partially
// honoring a malformed setting.
const trustProxy = process.env.TRUST_PROXY;
if (trustProxy === 'true') {
app.set('trust proxy', true);
} else if (trustProxy && !isNaN(parseInt(trustProxy, 10))) {
} else if (typeof trustProxy === 'string' && /^\d+$/.test(trustProxy)) {
app.set('trust proxy', parseInt(trustProxy, 10));
}

Expand Down