Repository navigation
Trust forwarded headers only from configured proxies - #620
MichaelLeeHobbs wants to merge 2 commits into
Conversation
Add server.api.trustedproxies. When set, both connectors apply Jetty's ForwardedRequestCustomizer to requests whose peer address is in the list, so a TLS-terminating proxy's X-Forwarded-Proto marks the request secure and its X-Forwarded-For sets the remote address. Headers from other clients are ignored. Blank, the default, keeps the current behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Michael Hobbs <michael.lee.hobbs@gmail.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified for the opt-in trusted-proxy change.
No open issues 🎉
What changed in this PR
Adds opt-in trusted-proxy handling to Jetty, allowing requests behind TLS-terminating proxies to report the original client address and secure scheme. Audit-IP support depends on #600.
Changes:
- Applies forwarded headers only for configured proxy peers on HTTP and HTTPS connectors.
- Documents
server.api.trustedproxies, preserving existing behavior when blank. - Adds connector tests for blank, trusted, and untrusted proxy configurations.
| File | Description |
|---|---|
| server/src/test/java/com/mirth/connect/server/MirthWebServerTrustedProxyTest.java | Tests forwarded-header handling against a live Jetty connector. |
| server/src/main/java/com/mirth/connect/server/MirthWebServer.java | Adds peer-address validation before applying forwarded headers. |
| server/conf/mirth.properties | Documents trusted-proxy configuration and header-replacement requirements. |
Review effort: Balanced
pacmano1
left a comment
There was a problem hiding this comment.
One fix before merge. A bad value in server.api.trustedproxies takes the whole admin API down. InetAddressSet.add throws IllegalArgumentException: Bad pattern on anything that isn't an IP, CIDR or range, a hostname, or a plain typo like 172.30.0.10x, and TrustedProxyCustomizer adds each entry with no guard, so it throws out of the MirthWebServer constructor. Both connectors then fail to start, HTTP and HTTPS both refuse connections and a fronting proxy gets 502, but the engine logs "server successfully started" and keeps running: channels deploy and process messages fine. So one typo in this new property leaves the engine moving traffic while nobody can reach the API, the Administrator or the web admin, with only a bare stack trace in the log, not an ERROR.
Measured on a PR build behind an nginx TLS proxy: 172.30.0.10 works (cookie gets Secure through the proxy, forged headers from untrusted clients ignored, direct access unchanged); 172.30.0.10x or a hostname downs both connectors with the engine still reporting started.
Please validate each entry and either skip the bad one or fail fast, with a clear ERROR naming the value, rather than letting it kill the web server. Hostnames aren't supported (InetAddressSet doesn't resolve them), which matches the IP/CIDR/range comment, so rejecting a non-IP value with that message would read better than a raw "Bad pattern".
Co-authored with Claude Code.
|
One more: add a test for a bad value. The three tests only feed valid IPs and CIDR, so the unparseable path, the one that throws and takes the web server down, has no coverage. A case that feeds a bad entry and asserts the server still starts (or the value is rejected cleanly) would lock it in. |
An entry InetAddressSet can't parse (a typo or a hostname) threw out of the MirthWebServer constructor, so neither connector started. Log it as an ERROR and skip it; the valid entries still apply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Michael Hobbs <michael.lee.hobbs@gmail.com>
|
@pacmano1 Thanks for testing it behind nginx. Fixed in 8739881: an entry
|
Closes #619
Adds
server.api.trustedproxies, a comma-separated list of addresses, CIDR blocks or ranges. When it's set, the HTTP and HTTPS connectors apply Jetty'sForwardedRequestCustomizeronly to requests whose connection comes from a listed address. So behind a TLS-terminating proxy,X-Forwarded-Proto: httpsmarks the request secure (the session cookie getsSecure) andX-Forwarded-Forsets the remote address. Forwarded headers from any other client are ignored. Blank, the default, keeps the current behavior.Jetty takes the first
X-Forwarded-Forentry, so the property comment says the proxy must replace that header rather than append to it.The audit-IP part depends on #600: on
main,getRequestIpAddress()still readsX-Forwarded-Fordirectly.How to verify
./gradlew :server:test --tests "*MirthWebServerTrustedProxyTest"starts a Jetty connector and sendsX-Forwarded-For: 10.0.0.5andX-Forwarded-Proto: httpsfrom 127.0.0.1. With the property blank, or listing only10.0.0.0/8, the request reports127.0.0.1and not secure. Listing127.0.0.1or127.0.0.0/8makes it report10.0.0.5and secure. I ran this test; I did not run the full suite or test behind a real proxy.🤖 Generated with Claude Code