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

Đang mở Phù hợp với người mới
#67,532 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend, security

Hướng nghiên cứu

Bắt đầu với apps/settings/lib/SetupChecks/ForwardedForHeaders.php và so sánh cách tra cứu địa chỉ cùng bước kiểm tra proxy đáng tin cậy với Request::getRemoteAddress() và IpUtils::checkIp(). Đọc apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php, sau đó bổ sung kiểm thử cho tiêu đề Remote-Addr do client gửi và proxy đáng tin cậy dạng CIDR. Hoàn tất khi bước kiểm tra thiết lập sử dụng địa chỉ máy chủ, xử lý các dải CIDR và các kiểm thử đều chạy đạt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
PHP
Star
37.6k
Fork
5.4k
Merge trung bình
1 ngày 20 giờ
Pull request đã merge (30 ngày)
605

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nextcloud/server

Tất cả issue của nextcloud/server

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.