fetch: --allowed-hosts accepts wildcard IP entries (e.g. *.0.0.1) and matches any IPv4 ending with that suffix

Đang mở Phù hợp với người mới
#5,521 1 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
78/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ệ
python
Lĩnh vực
backend, security

Hướng nghiên cứu

Bắt đầu tại src/fetch/src/mcp_server_fetch/allowlist.py và đọc normalize_allowed_host cùng host_is_allowed, là các điểm truy cập bị ảnh hưởng theo issue. Kiểm tra các bài kiểm thử hiện có về chuẩn hóa và khớp host được cho phép, sau đó bổ sung kiểm thử cho địa chỉ IP dạng literal có wildcard, hậu tố số và host là địa chỉ IP. Hoàn thành khi các đầu vào đó bị từ chối hoặc không bao giờ khớp với địa chỉ IP dạng literal, trong khi wildcard cho tên miền con của hostname vẫn hoạt động.

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

Mô tả

Problem

mcp-server-fetch's --allowed-hosts allowlist (src/fetch/src/mcp_server_fetch/allowlist.py) documents two valid entry forms:

Two entry forms only, to keep the semantics obvious: an exact host (a name or an IP literal), and *.example.com, which matches any subdomain at any depth of example.com...

However, normalize_allowed_host only checks ipaddress.ip_address(...) when not wildcard (line 37). When a wildcard prefix *. is given before an IP literal or numeric IP suffix (such as *.10.0.0.1 or *.0.0.1), httpx.URL(f"http://{name}/") parses name without error and returns *.10.0.0.1 / *.0.0.1.

Then in host_is_allowed(host, allowed_hosts), host.endswith(entry[1:]) matches any IPv4 literal ending with .0.0.1 (for example, *.0.0.1 matches both 10.0.0.1 and 127.0.0.1).

from mcp_server_fetch.allowlist import host_is_allowed, normalize_allowed_hosts

entries = normalize_allowed_hosts(["*.0.0.1"])  # returns ('*.0.0.1',)
assert host_is_allowed("127.0.0.1", entries) is True
assert host_is_allowed("10.0.0.1", entries) is True

Expected

  • normalize_allowed_host rejects wildcard IP literals and numeric-TLD wildcard suffixes (*.10.0.0.1, *.0.0.1, *.[::1]) with ValueError.
  • host_is_allowed does not match *. subdomain wildcards against IP address literals.
Ngôn ngữ chính
TypeScript
Star
91.9k
Fork
11.9k
Merge trung bình
3 giờ 10 phút
Pull request đã merge (30 ngày)
178

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

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 modelcontextprotocol/servers

Tất cả issue của modelcontextprotocol/servers

Issue tương tự

Thêm issue về TypeScript

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.