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

オープン 初心者向け
#67,532 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
backend, security

調査の方向性

apps/settings/lib/SetupChecks/ForwardedForHeaders.php から始め、アドレスの取得方法と信頼するプロキシのチェックを、Request::getRemoteAddress() および IpUtils::checkIp() と比較してください。apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php を読み、クライアントが送信した Remote-Addr ヘッダーと CIDR 形式の信頼するプロキシを対象とするテストを追加してください。セットアップチェックがサーバーのアドレスを使用し、CIDR 範囲を処理し、テストが通れば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
PHP
スター
37.6k
フォーク
5.4k
平均マージ
1日 20時間
マージ済み PR(30日)
605

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nextcloud/server のほかの issue

nextcloud/server の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。