fix(tomcat): Regex escaping error in RemoteIpValve internalProxies + missing CGNAT
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 970
- Forks
- 486
- Avg merge
- 3d 33m
- Merged PRs (30d)
- 170
Description
Problem Statement
The default CMS_REMOTEIP_INTERNALPROXIES regex in setenv.sh uses double-backslash escaping (\\) inside double-quoted strings. This produces an incorrect regex pattern that fails to match internal proxy IP addresses, causing RemoteIpValve to not trust proxies and not properly resolve client IPs from X-Forwarded-For headers.
Additionally, the regex does not cover 100.64.0.0/10 (CGNAT, RFC 6598), commonly used by cloud load balancers and Kubernetes overlay networks. Tomcat 10.1+ includes this range by default.
File: dotCMS/src/main/resources/container/tomcat9/bin/setenv.sh:102
Current (broken):
export CMS_REMOTEIP_INTERNALPROXIES=${CMS_REMOTEIP_INTERNALPROXIES:-"10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} |192\\.168\\.\\d{1,3}\\.\\d{1,3}|..."}
The \\ escaping is incorrect — should be single \.
Steps to Reproduce
- Deploy dotCMS without setting
CMS_REMOTEIP_INTERNALPROXIESenv var - Send request through an internal proxy (e.g.,
10.x.x.x,192.168.x.x) - Observe
X-Forwarded-Forheader is not resolved — client IP shows proxy IP instead of real client IP - Requests from CGNAT range (
100.64.x.x) are never trusted regardless of escaping fix
Acceptance Criteria
- Fix
\\double-backslash escaping to single\inCMS_REMOTEIP_INTERNALPROXIESdefault regex insetenv.sh - Add
100.64.0.0/10(CGNAT / RFC 6598) to internal proxies regex - RemoteIpValve correctly matches RFC 1918, CGNAT, loopback, and link-local addresses as internal proxies
-
X-Forwarded-Forheader properly resolved when request traverses internal proxy
dotCMS Version
All versions (evergreen) — present since the regex was added to setenv.sh
Severity
Medium - Some functionality impacted
Links
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at dotCMS/src/main/resources/container/tomcat9/bin/setenv.sh:102 and inspect how the default CMS_REMOTEIP_INTERNALPROXIES value is quoted and passed to Tomcat's RemoteIpValve. Deploy without the environment variable and reproduce the listed internal-proxy requests; done means RFC 1918, CGNAT, loopback, and link-local proxies are trusted and X-Forwarded-For resolves the client IP.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, shell
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100