Bug]: Crawl4aiDockerClient gets 400 with any BrowserConfig: dump() always sends the generated `headers`

Đang mở Phù hợp với người mới
#2,472 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 2 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
72/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
api, backend

Hướng nghiên cứu

Bắt đầu bằng cách đọc BrowserConfig.dump() và phần khởi tạo BrowserConfig được mô tả, phần tạo ra sec-ch-ua; sau đó kiểm tra bước tái hiện việc tải dữ liệu không đáng tin cậy trong issue. Xác minh rằng cấu hình đã được tuần tự hóa không còn gửi trường headers được tạo ra và một yêu cầu với BrowserConfig() được máy chủ chấp nhận.

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

Mô tả

⚙ Done 🐞 Bug 📌 Root caused
crawl4ai version

0.9.5 (also on develop; since 0.9.0)

Expected Behavior

Crawl4aiDockerClient.crawl(..., browser_config=BrowserConfig(headless=True)) is accepted by the server. The user did not set any headers.

Current Behavior

Every request with a BrowserConfig is rejected:

400 Rejected request: field 'headers' is not permitted on BrowserConfig from an untrusted request

BrowserConfig.__init__ always adds a sec-ch-ua header derived from the user agent:

self.browser_hint = UAGen.generate_client_hints(self.user_agent)
self.headers.setdefault("sec-ch-ua", self.browser_hint)

So headers is never empty, and dump() always writes it. The server forbids headers from an untrusted request (UNTRUSTED_FORBIDDEN_FIELDS["BrowserConfig"]) and rejects it whatever its value. The client sends browser_config.dump(), so it fails with any BrowserConfig, even BrowserConfig(). Without a BrowserConfig the request works.

The server rule is right. The problem is that dump() sends a header the user never set, and the server's __init__ derives the same value again from user_agent anyway.

#2262 hit the same 400 in the playground and worked around it there by forwarding only the typed params. The client was not fixed.

Is this reproducible?

Yes

Inputs Causing the Bug

Any BrowserConfig passed to Crawl4aiDockerClient, or any BrowserConfig(...).dump() posted to /crawl, /crawl/stream or /crawl/job.

Steps to Reproduce

Run the snippet below; it reproduces the server's check in-process. Against a running server, Crawl4aiDockerClient().crawl(["https://example.com"], browser_config=BrowserConfig()) returns the same 400.

Code snippets
from crawl4ai import BrowserConfig
from crawl4ai.async_configs import Provenance

data = BrowserConfig(headless=True).dump()
print(data["params"]["headers"])
# {'type': 'dict', 'value': {'sec-ch-ua': '"Chromium";v="116", "Not_A Brand";v="8", "Google Chrome";v="116"'}}

BrowserConfig.load(data, provenance=Provenance.UNTRUSTED)
# UntrustedConfigError: field 'headers' is not permitted on BrowserConfig from an untrusted request
OS

macOS 26.6 (platform-independent)

Python version

3.13

Browser

Not involved

Error logs & Screenshots (if applicable)

See above. I'll open a PR.

Ngôn ngữ chính
Python
Star
86.8k
Fork
9k
Merge trung bình
2 ngày 3 giờ
Pull request đã merge (30 ngày)
26

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 unclecode/crawl4ai

Tất cả issue của unclecode/crawl4ai

Issue tương tự

Thêm issue về Python

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.