fix(settings): use CIDR-aware proxy detection in ForwardedForHeaders setup check - #60315
fix(settings): use CIDR-aware proxy detection in ForwardedForHeaders setup check#60315algojogacor wants to merge 1 commit into
Conversation
…setup check The setup check used in_array() with strict comparison to determine if REMOTE_ADDR matched a trusted proxy entry. This cannot match CIDR ranges (e.g., 172.16.0.0/12) because the raw IP and the CIDR string are never equal. Replace in_array() with a check that compares the raw REMOTE_ADDR against the resolved address from getRemoteAddress(), which already handles CIDR matching internally via IpUtils::checkIp(). Also add a test case for large CIDR (/12) matching to prevent future regressions. Fixes: nextcloud#60287 Signed-off-by: Arya Rizky <arya@algojogacor.dev>
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
Summary
Fixes #60287
The ForwardedForHeaders setup check used
in_array($remoteAddress, $trustedProxies, true)to determine if the connecting proxy was trusted. This strict comparison cannot match CIDR ranges (e.g.,172.16.0.0/12) because the raw IP172.21.0.7and the CIDR string172.16.0.0/12are never equal.Root Cause
ForwardedForHeaders.phpline 75 usedin_array()for exact string matching against the trusted proxies list. WhilegetRemoteAddress()inRequest.phpcorrectly uses Symfony'sIpUtils::checkIp()for CIDR-aware matching, the setup check did its own non-CIDR-aware comparison. This meant:Fix
Replace the
in_array()-based check with a direct comparison between$remoteAddress(rawREMOTE_ADDR) and$detectedRemoteAddress(fromgetRemoteAddress()). SincegetRemoteAddress()already usesIpUtils::checkIp()internally for CIDR matching, this comparison correctly reflects whether proxy detection resolved a different client IP.Added a test case for large
/12CIDR matching inRequestTest.phpto prevent regressions.Changes
apps/settings/lib/SetupChecks/ForwardedForHeaders.php: Replacein_array()with direct address comparison (+12 -10lines)tests/lib/AppFramework/Http/RequestTest.php: Add test case for/12CIDR proxy detection (+9 -0lines)Testing
/12trusted proxy with valid X-Forwarded-For: Client IP resolved correctly ✅/24trusted proxy (existing test preserved): Client IP resolved correctly ✅