Repository navigation
fix: honour forwarded headers outside Kubernetes - #193
Conversation
Replace the dead server.use-forward-headers property, which Spring Boot has ignored since 2.7, with server.forward-headers-strategy=native, so that the server URL in the API description follows X-Forwarded-* headers of proxies on internal addresses also outside Kubernetes. Add an integration test and document the setting and its trusted proxies. Closes #192 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideConfigurationReplace the ignored forwarding property with Tomcat’s native forwarded-header handling, which trusts proxies on internal addresses by default.
DocumentationDocument the forwarded-header strategy, its trusted-proxy defaults, and how to change or disable it.
TestsAdd a real-server integration test verifying that the API description uses the forwarded host and scheme.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #193 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 53 53
Lines 2260 2260
Branches 255 255
=========================================
Hits 2260 2260 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docs/configuration.md" line_range="41" />
<code_context>
+`SERVER_FORWARD_HEADERS_STRATEGY` | How TESK API learns its public URL behind a reverse proxy (e.g. for the server URL in the [API description](api.md), which the Swagger UI uses for "Try it out"). `native` (default): the embedded Tomcat takes scheme, host and port from the `X-Forwarded-Proto`, `X-Forwarded-Host` and `X-Forwarded-Port` headers, and the client address from `X-Forwarded-For`, but only of requests from internal addresses (`10/8`, `172.16/12`, `192.168/16`, `169.254/16`, `127/8`, `100.64/10` and their IPv6 counterparts); headers from other addresses are ignored. If your proxy has another address, list it (and only it) in `SERVER_TOMCAT_REMOTEIP_INTERNAL_PROXIES`, a regular expression of IP addresses. `none`: ignores the headers. Since 2.0.0; before, Springfox read `X-Forwarded-Host` itself.
</code_context>
<issue_to_address>
**Strategy setting is ignored**
When an operator sets the documented environment variable to `none` to disable forwarded-header handling, spring Boot maps underscores in environment-variable names to property separators, so `SERVER_FORWARD_HEADERS_STRATEGY` does not bind to `server.forward-headers-strategy`. The configured `none` value is ignored and the application’s `native` default remains active, so forwarded headers continue to be processed.
Document the environment variable as `SERVER_FORWARD_HEADERSSTRATEGY` (or provide an equivalent property-based configuration).
Also at `docs/upgrading.md:44`.
</issue_to_address>
### Comment 2
<location path="docs/configuration.md" line_range="41" />
<code_context>
+`SERVER_FORWARD_HEADERS_STRATEGY` | How TESK API learns its public URL behind a reverse proxy (e.g. for the server URL in the [API description](api.md), which the Swagger UI uses for "Try it out"). `native` (default): the embedded Tomcat takes scheme, host and port from the `X-Forwarded-Proto`, `X-Forwarded-Host` and `X-Forwarded-Port` headers, and the client address from `X-Forwarded-For`, but only of requests from internal addresses (`10/8`, `172.16/12`, `192.168/16`, `169.254/16`, `127/8`, `100.64/10` and their IPv6 counterparts); headers from other addresses are ignored. If your proxy has another address, list it (and only it) in `SERVER_TOMCAT_REMOTEIP_INTERNAL_PROXIES`, a regular expression of IP addresses. `none`: ignores the headers. Since 2.0.0; before, Springfox read `X-Forwarded-Host` itself.
</code_context>
<issue_to_address>
**Trusted proxies are ignored**
When the proxy is outside Tomcat’s default trusted ranges and an operator uses the documented environment variable, `SERVER_TOMCAT_REMOTEIP_INTERNAL_PROXIES` does not bind to Tomcat’s `server.tomcat.remoteip.internal-proxies`, so Tomcat keeps its default trust list, ignores the forwarded headers, and the API description exposes the internal URL.
Document a Spring Boot-compatible environment-variable name or another supported way to set `server.tomcat.remoteip.internal-proxies`.
</issue_to_address>
### Comment 3
<location path="docs/configuration.md" line_range="41" />
<code_context>
+`SERVER_FORWARD_HEADERS_STRATEGY` | How TESK API learns its public URL behind a reverse proxy (e.g. for the server URL in the [API description](api.md), which the Swagger UI uses for "Try it out"). `native` (default): the embedded Tomcat takes scheme, host and port from the `X-Forwarded-Proto`, `X-Forwarded-Host` and `X-Forwarded-Port` headers, and the client address from `X-Forwarded-For`, but only of requests from internal addresses (`10/8`, `172.16/12`, `192.168/16`, `169.254/16`, `127/8`, `100.64/10` and their IPv6 counterparts); headers from other addresses are ignored. If your proxy has another address, list it (and only it) in `SERVER_TOMCAT_REMOTEIP_INTERNAL_PROXIES`, a regular expression of IP addresses. `none`: ignores the headers. Since 2.0.0; before, Springfox read `X-Forwarded-Host` itself.
</code_context>
<issue_to_address>
**Some proxy addresses are not trusted**
When the proxy connects from `100.64/10` or a private IPv6 address other than loopback, tomcat’s default `internal-proxies` pattern excludes those addresses, so `RemoteIpValve` ignores the forwarded headers and the API description exposes the internal URL.
Configure Tomcat’s `internal-proxies` pattern to include the documented trusted address ranges.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: docs/configuration.md:41, docs/configuration.md:41, docs/configuration.md:41
Spring Boot 4 sets the internal proxies as CIDR ranges, not as Tomcat's regular expression; list its default and the format. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Linked issuesChecked at commit 5ac7a03 #192 fix: drop the dead server.use-forward-headers property · 3 of 3 met
|
2.0.0 is tagged without this change: restore its upgrade notes and say in the configuration reference that 2.0.0 lacks the setting. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The integration test came with #193 after the move. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
server.use-forward-headers=truehas been ignored since Spring Boot 2.7. With springdoc (#185), the server URL in/v3/api-docscomes from the request, so outside Kubernetes (e.g. Docker behind nginx) it names the internal URL and "Try it out" fails.server.forward-headers-strategy=native: the embedded Tomcat honoursX-Forwarded-*from proxies on internal addresses only (Spring Boot's defaultserver.tomcat.remoteip.internal-proxies), in and outside Kubernetes.ForwardedHeadersIT: withX-Forwarded-Host/-Proto, the description's server URL ishttps://tesk.example.org. It needs a real server, as MockMvc doesn't run Tomcat's remote-IP handling; JUnit 4 like the current dev tests.SERVER_FORWARD_HEADERS_STRATEGYindocs/configuration.md(trusted CIDR ranges,SERVER_TOMCAT_REMOTEIP_INTERNAL_PROXIESto change them,none; notes that 2.0.0 lacks it). This ships after 2.0.0, sodocs/upgrading.mdis unchanged; the repo has no place for unreleased changes, so the next release's upgrade notes must mention it.Closes #192
Verification
./mvnw verify(JDK 21): BUILD SUCCESS, 122 integration tests incl.ForwardedHeadersIT, coverage check passed.mkdocs build --strict: OK.spotless:checkcan't run locally (spotless 2.30 crashes on the local JDK 21); CI's Lint job passed.CI passed).Review
Security-relevant (trust in
X-Forwarded-*), so full review: adversarial reviewer found no high or medium findings. No auth logic reads the request's scheme, host or address (issuer/JWKS/userinfo checks use configured URLs), the/redirect is relative, nothing logs or decides on client IPs. Forged headers only change the API description returned to the forging client. Sourcery: 3 threads answered and resolved (env var names bind via Spring Boot's legacy mapping; trusted ranges now listed exactly).Declined review findings
Append, ingress-nginx withuse-forwarded-headers) let a client change the server URL in its own API description; no effect on others unless a shared cache stores/v3/api-docswithout varying on these headers. No code change.Notes
The Helm chart in elixir-cloud-aai/TESK sets neither
use-forward-headersnorSERVER_FORWARD_HEADERS_STRATEGY; nothing to change there.🤖 Generated with Claude Code