feat: Add support for configurable proxy IP header in environment settings (#11595)

* feat: Add support for configurable proxy IP header in environment settings

* Update server/env.ts

Remove mention of Koa from docs

Co-authored-by: Tom Moor <tom.moor@gmail.com>

* Update .env.sample

Remove mention of Koa from env sample.

Co-authored-by: Tom Moor <tom.moor@gmail.com>

---------

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Ashley Sommer
2026-02-28 10:27:24 +10:00
committed by GitHub
parent d54167dbdf
commit 8048b7e530
3 changed files with 18 additions and 0 deletions
+5
View File
@@ -119,6 +119,11 @@ SSL_CERT=
# false if you can be sure that SSL is terminated at an external loadbalancer.
FORCE_HTTPS=true
# When behind a reverse proxy, the header to use for the client IP.
# The default value is "X-Forwarded-For", common values are "X-Real-IP"
# and "X-Client-IP".
# PROXY_IP_HEADER=
# ––––––––––––––––––––––––––––––––––––––
# –––––––––– AUTHENTICATION ––––––––––
+10
View File
@@ -341,6 +341,16 @@ export class Environment {
@IsBoolean()
public FORCE_HTTPS = this.toBoolean(environment.FORCE_HTTPS ?? "true");
/**
* When the app is behind a proxy, sets the HTTP header used for the client IP.
* The default value is "X-Forwarded-For", common values are "X-Real-IP"
* and "X-Client-IP".
*/
@IsOptional()
public PROXY_IP_HEADER = this.toOptionalString(
environment.PROXY_IP_HEADER
);
/**
* Should the installation send anonymized statistics to the maintainers.
* Defaults to true.
+3
View File
@@ -47,6 +47,9 @@ export default function init(app: Koa = new Koa(), server?: Server) {
// trust header fields set by our proxy. eg X-Forwarded-For
app.proxy = true;
if (env.PROXY_IP_HEADER) {
app.proxyIpHeader = env.PROXY_IP_HEADER;
}
}
// Make `ctx.userAgent` available