fix(tomcat): correct RemoteIpValve internalProxies regex and add CGNAT (#35804)#35805
Merged
Conversation
… coverage (#35804) - Simplify regex escaping in setenv.sh (single \ for readability) - Consolidate 10.*/127.* and 172.16-31 alternations - Add CGNAT 100.64.0.0/10 (RFC 6598) range for cloud/K8s proxies - Replace \d{1,3} with \d\d?\d? in server.xml to avoid Tomcat IntrospectionUtils bare-brace parsing bug (pre-existing) - Retain IPv6 loopback (0:0:0:0:0:0:0:1) in both files Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Aligns with Tomcat 9/10.1 default which includes both expanded (0:0:0:0:0:0:0:1) and compressed (::1) IPv6 loopback forms. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment between attributes is invalid per XML 1.0 STag grammar — Xerces/Digester would reject it. Folded into existing comment block. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setenv.sh— single\(readable, equivalent in sh/bash double quotes)10.*/127.*and172.16-31alternations into grouped patterns100.64.0.0/10(RFC 6598) range — used by cloud load balancers, Kubernetes overlay networks, and Tailscale.IntrospectionUtils.replaceProperties()bug inserver.xml: bare{/}in\d{1,3}broke property resolution (first}closed${...}prematurely). Replaced with\d\d?\d?— regex-equivalent, brace-safeTest plan
The
RemoteIpValveprocesses theX-Forwarded-Forheader and replacesrequest.getRemoteAddr()with the real client IP — but only when the immediate connecting IP matchesinternalProxies. Validation must confirm Tomcat's resolved remote IP, not just header presence.Setup
CMS_REMOTEIP_INTERNALPROXIES(use the default regex)request.getRemoteAddr()returns after the valve processes the request. Options:%{org.apache.catalina.AccessLog.RemoteAddr}r— this logs the IP afterRemoteIpValveprocesses it. Compare against%a(raw remote addr) or add both to the pattern/api/v1/appconfigurationor any endpoint that echoes the client IP in its response/logs$request.getRemoteAddr()in a page to see the resolved IP directlyTest cases
10.x.x.x,192.168.x.x, or172.16-31.x.xproxy withX-Forwarded-For: <real-client-ip>. Verify access log /getRemoteAddr()shows<real-client-ip>, not the proxy IP127.0.0.1with XFF header. Verify real client IP resolved0:0:0:0:0:0:0:1(::1) with XFF header. Verify real client IP resolved100.64.x.xthrough100.127.x.xwith XFF header. Verify real client IP resolved169.254.x.xwith XFF header. Verify real client IP resolved203.0.113.1) withX-Forwarded-For: 1.2.3.4. VerifygetRemoteAddr()still shows203.0.113.1(valve should NOT substitute)100.63.255.255should NOT be trusted (below range).100.128.0.0should NOT be trusted (above range)CMS_REMOTEIP_INTERNALPROXIESto a custom regex. Verify custom value takes precedence over the defaultQuick Docker test
Closes #35804
🤖 Generated with Claude Code
This PR fixes: #35804