Question
Limits on Trusting Proxy Headers in CakePHP 4.x/5.x
Rahul Echo
0 reputation · 07 Mar 2021, 01:43 UTC
129K views0
Goal
Ensure that Request::getClientIp() and Request::is('ssl') return correct values when the application sits behind a reverse proxy such as an AWS ALB or Nginx.
Constraints
- Local development runs without a proxy; the default
trustProxy => falseworks. - Production introduces
X-Forwarded-For,X-Forwarded-Proto, andX-Forwarded-Hostheaders that must be interpreted. - Enabling
trustProxy => truewithout restrictingtrustedProxiescould allow header spoofing. - The framework requires explicit
trustedHeadersbitmask configuration; the documentation lists four constants but does not recommend a default for common cloud load balancers.
Unresolved Decision
Which combination of trustedHeaders bits should be enabled, and how should trustedProxies be scoped, to achieve accurate client IP and SSL detection while preventing security risks?
Specific Questions
- Should
trustedHeadersincludeHEADER_X_FORWARDED_PROTOto correctly detect SSL behind an ALB? - Is trusting all
X-Forwarded-Forvalues from a single ALB safe, or musttrustedProxiesbe limited to the ALB’s IP ranges? - Does CakePHP 5.x automatically recognize ALB headers, or does it still require manual
trustedProxiesconfiguration?