dotCMS / dotCMS/core

fix(tomcat): Regex escaping error in RemoteIpValve internalProxies + missing CGNAT

Open Beginner friendly
#35,804 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

dotCMS : Containerization OKR : Customer Support stale Team : Falcon Type : Defect
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

  1. Deploy dotCMS without setting CMS_REMOTEIP_INTERNALPROXIES env var
  2. Send request through an internal proxy (e.g., 10.x.x.x, 192.168.x.x)
  3. Observe X-Forwarded-For header is not resolved — client IP shows proxy IP instead of real client IP
  4. Requests from CGNAT range (100.64.x.x) are never trusted regardless of escaping fix

Acceptance Criteria

  • Fix \\ double-backslash escaping to single \ in CMS_REMOTEIP_INTERNALPROXIES default regex in setenv.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-For header 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

https://helpdesk.dotcms.com/a/tickets/37123

https://dotcms.slack.com/archives/C06TM536N9J/p1779411185740119?thread_ts=1779390915.869349&cid=C06TM536N9J

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.