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

Open Beginner friendly
#67,532 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend, security

Research direction

Start with apps/settings/lib/SetupChecks/ForwardedForHeaders.php and compare its address lookup and trusted proxy check with Request::getRemoteAddress() and IpUtils::checkIp(). Read apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php, then add coverage for a client-sent Remote-Addr header and a CIDR trusted proxy. Done when the setup check uses the server address, handles CIDR ranges, and the tests pass.

Written by the indexing model from the issue text.

Description

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

Dominant language
PHP
Stars
37.6k
Forks
5.4k
Avg merge
1d 20h
Merged PRs (30d)
605

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

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.

More from nextcloud/server

All issues in nextcloud/server

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.