Skip to content

fix: honour forwarded headers outside Kubernetes - #193

Merged
uniqueg merged 4 commits into
devfrom
fix/192-forward-headers
Nov 16, 2026
Merged

uniqueg merged 4 commits into
devfrom
fix/192-forward-headers

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

server.use-forward-headers=true has been ignored since Spring Boot 2.7. With springdoc (#185), the server URL in /v3/api-docs comes from the request, so outside Kubernetes (e.g. Docker behind nginx) it names the internal URL and "Try it out" fails.

  • Replace the dead property with server.forward-headers-strategy=native: the embedded Tomcat honours X-Forwarded-* from proxies on internal addresses only (Spring Boot's default server.tomcat.remoteip.internal-proxies), in and outside Kubernetes.
  • New integration test ForwardedHeadersIT: with X-Forwarded-Host/-Proto, the description's server URL is https://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.
  • Docs: SERVER_FORWARD_HEADERS_STRATEGY in docs/configuration.md (trusted CIDR ranges, SERVER_TOMCAT_REMOTEIP_INTERNAL_PROXIES to change them, none; notes that 2.0.0 lacks it). This ships after 2.0.0, so docs/upgrading.md is 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:check can't run locally (spotless 2.30 crashes on the local JDK 21); CI's Lint job passed.
  • CI: see checks (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

  • Low: proxies that append client-supplied headers (OpenShift router Append, ingress-nginx with use-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-docs without varying on these headers. No code change.
  • Low: routers on public node IPs aren't trusted by default; fails safe and is documented.
  • Low: no test that headers from untrusted addresses are ignored; that is Spring Boot's and Tomcat's behaviour, covered by their tests.

Notes

The Helm chart in elixir-cloud-aai/TESK sets neither use-forward-headers nor SERVER_FORWARD_HEADERS_STRATEGY; nothing to change there.

🤖 Generated with Claude Code

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]>
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Replace the ignored forwarding property with Tomcat’s native forwarded-header handling, which trusts proxies on internal addresses by default.

  • src/main/resources/application.properties L12-14

Documentation

Document the forwarded-header strategy, its trusted-proxy defaults, and how to change or disable it.

  • docs/configuration.md L41

Tests

Add a real-server integration test verifying that the API description uses the forwarded host and scheme.

  • src/integration-test/java/uk/ac/ebi/tsc/tesk/ForwardedHeadersIT.java L1-70

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d013df9) to head (5ac7a03).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 16, 2026 04:01

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread docs/configuration.md Resolved
Comment thread docs/configuration.md Resolved
Comment thread docs/configuration.md Resolved
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]>
@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 5ac7a03

#192 fix: drop the dead server.use-forward-headers property · 3 of 3 met

# Requirement Status Notes
1 Replace the dead property and document trusted proxies and how to change them ✅ Met The application uses server.forward-headers-strategy=native; the configuration reference describes the trusted internal address ranges and SERVER_TOMCAT_REMOTEIP_INTERNAL_PROXIES.
2 Test that the API description's server URL follows the forwarded host and protocol ✅ Met ForwardedHeadersIT sends X-Forwarded-Host and X-Forwarded-Proto to a real server and checks the resulting URL.
3 Document the behavior in the configuration or deployment guide and the upgrade notes ✅ Met The configuration reference documents the default and clarifies that it is not in 2.0.0; the upgrade notes describe forwarded-header behavior and configuration for deployments outside Kubernetes.

uniqueg and others added 2 commits November 16, 2026 05:12
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]>
@uniqueg
uniqueg merged commit 5e23790 into dev Nov 16, 2026
34 checks passed
@uniqueg
uniqueg deleted the fix/192-forward-headers branch November 16, 2026 04:21
uniqueg added a commit that referenced this pull request Nov 16, 2026
The integration test came with #193 after the move.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: drop the dead server.use-forward-headers property

1 participant