Skip to content

fix(settings): use CIDR-aware proxy detection in ForwardedForHeaders setup check#60315

Open
algojogacor wants to merge 1 commit into
nextcloud:masterfrom
algojogacor:fix/cidr-trusted-proxies-setup-check
Open

fix(settings): use CIDR-aware proxy detection in ForwardedForHeaders setup check#60315
algojogacor wants to merge 1 commit into
nextcloud:masterfrom
algojogacor:fix/cidr-trusted-proxies-setup-check

Conversation

@algojogacor
Copy link
Copy Markdown

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 IP 172.21.0.7 and the CIDR string 172.16.0.0/12 are never equal.

Root Cause

ForwardedForHeaders.php line 75 used in_array() for exact string matching against the trusted proxies list. While getRemoteAddress() in Request.php correctly uses Symfony's IpUtils::checkIp() for CIDR-aware matching, the setup check did its own non-CIDR-aware comparison. This meant:

  • The success message ("Your IP address was resolved as…") was never shown for CIDR-configured proxies
  • The setup check was effectively blind to whether CIDR-based proxy detection was working

Fix

Replace the in_array()-based check with a direct comparison between $remoteAddress (raw REMOTE_ADDR) and $detectedRemoteAddress (from getRemoteAddress()). Since getRemoteAddress() already uses IpUtils::checkIp() internally for CIDR matching, this comparison correctly reflects whether proxy detection resolved a different client IP.

Added a test case for large /12 CIDR matching in RequestTest.php to prevent regressions.

Changes

  • apps/settings/lib/SetupChecks/ForwardedForHeaders.php: Replace in_array() with direct address comparison (+12 -10 lines)
  • tests/lib/AppFramework/Http/RequestTest.php: Add test case for /12 CIDR proxy detection (+9 -0 lines)

Testing

  • CIDR /12 trusted proxy with valid X-Forwarded-For: Client IP resolved correctly ✅
  • CIDR /24 trusted proxy (existing test preserved): Client IP resolved correctly ✅
  • No trusted proxies configured: Falls through to success (no regression) ✅
  • Trusted proxies configured but X-Forwarded-For missing: Warning shown correctly ✅

…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>
@algojogacor algojogacor requested a review from a team as a code owner May 12, 2026 02:50
@algojogacor algojogacor requested review from Altahrim, ArtificialOwl, CarlSchwan and icewind1991 and removed request for a team May 12, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: trusted_proxies ignoring CIDRs larger than /13

1 participant