Skip to content

Commit 912f79f

Browse files
author
DynamoFox
committed
Add optional support to trust reverse proxies (via X-Forwarded-For)
1 parent b6f1611 commit 912f79f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

config-sample.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ https=false
2121
# path to certificate (run "bash bin/generate-cert.sh" to generate self-signed certificate). Relevant only if https=true
2222
certPath=
2323
keyPath=
24+
# setting to give trust to reverse proxies, a comma-separated list of trusted rev. proxy IPs can be specified (CIDR notation is permitted),
25+
# alternatively 'true' will make use of the leftmost IP in X-Forwarded-For, ultimately an integer can be used to tell about the number of hops between
26+
# Trilium (which is hop 0) and the first trusted rev. proxy.
27+
# once set, expressjs will use the X-Forwarded-For header set by the rev. proxy to determinate the real IPs of clients.
28+
# expressjs shortcuts are supported: loopback(127.0.0.1/8, ::1/128), linklocal(169.254.0.0/16, fe80::/10), uniquelocal(10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7)
29+
trustedReverseProxy=false

src/www

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ async function startTrilium() {
4444
app.set('port', usedPort);
4545
app.set('host', usedHost);
4646

47+
// Check from config whether to trust reverse proxies to supply user IPs, hostnames and protocols
48+
if (config['Network']['trustedReverseProxy']) {
49+
if (config['Network']['trustedReverseProxy'] === true || config['Network']['trustedReverseProxy'].trim().length) {
50+
app.set('trust proxy', config['Network']['trustedReverseProxy'])
51+
}
52+
}
53+
log.info('Trusted reverse proxy: ' + app.get('trust proxy'))
54+
4755
if (config['Network']['https']) {
4856
if (!config['Network']['keyPath'] || !config['Network']['keyPath'].trim().length) {
4957
throw new Error("keyPath in config.ini is required when https=true, but it's empty");

0 commit comments

Comments
 (0)