"Forwarded for headers" setup check trusts a client-sent Remote-Addr header and ignores CIDR proxies

Aperta Adatta ai principianti
#67,532 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
backend, security

Direzione di ricerca

Inizia da apps/settings/lib/SetupChecks/ForwardedForHeaders.php e confronta la ricerca dell’indirizzo e il controllo dei proxy attendibili con Request::getRemoteAddress() e IpUtils::checkIp(). Leggi apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php, quindi aggiungi test per un’intestazione Remote-Addr inviata dal client e per un proxy attendibile in formato CIDR. Il lavoro è completato quando il controllo di configurazione usa l’indirizzo del server, gestisce gli intervalli CIDR e i test passano.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug feature: settings
Bug description

The ForwardedForHeaders setup check reads the connecting address with getHeader('REMOTE_ADDR'):

https://github.com/nextcloud/server/blob/3a68340a6c806a18cdd0d9667a3b9ec5f096b135/apps/settings/lib/SetupChecks/ForwardedForHeaders.php#L41

Request::getHeader() first looks at HTTP_REMOTE_ADDR, i.e. a Remote-Addr: request header sent by the client, and only falls back to the real REMOTE_ADDR server variable afterwards:

https://github.com/nextcloud/server/blob/3a68340a6c806a18cdd0d9667a3b9ec5f096b135/lib/private/AppFramework/Http/Request.php#L280-L300

So the check result depends on a client-controlled header (or on a proxy forwarding such a header). Furthermore the trusted proxy comparison is an exact in_array():

https://github.com/nextcloud/server/blob/3a68340a6c806a18cdd0d9667a3b9ec5f096b135/apps/settings/lib/SetupChecks/ForwardedForHeaders.php#L75

so for proxies configured in CIDR notation (e.g. 172.16.0.0/12), which Request::getRemoteAddress() supports, the check never reports the resolved address nor the misconfiguration warning.

This only affects the setup check, not Request::getRemoteAddress() itself.

Steps to reproduce

Found by code reading.

  1. Configure trusted_proxies with a CIDR range, e.g. ['172.16.0.0/12'], behind a reverse proxy in that range.
  2. Open Administration settings → Overview: the "Your IP address was resolved as …" success / warning is never shown.
  3. Send the setup check request with an additional Remote-Addr: 1.2.3.4 header: the check evaluates 1.2.3.4 as the connecting address.
Expected behavior

The check uses the real REMOTE_ADDR server variable (not a client header with the same name) and matches it against trusted_proxies the same way Request::getRemoteAddress() does (CIDR aware, IpUtils::checkIp()), covered by tests in apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php.

Nextcloud version

master

Lingua principale
PHP
Stelle
37.6k
Fork
5.4k
Merge medio
1g 20h
PR unite (30g)
605

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nextcloud/server

Tutte le issue di nextcloud/server

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.