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

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

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

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

評価

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

調査の方向性

まず BrowserConfig.dump() と、sec-ch-ua を生成する BrowserConfig の説明された初期化処理を読み、次に issue にある信頼できないデータのロードの再現を確認してください。シリアライズされた設定が生成された headers フィールドを送信しなくなっていること、および BrowserConfig() を使ったリクエストがサーバーに受け入れられることを確認してください。

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

説明

⚙ 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.

主要言語
Python
スター
86.8k
フォーク
9k
平均マージ
2日 3時間
マージ済み PR(30日)
26

環境構築

はじめの一歩

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

unclecode/crawl4ai のほかの issue

unclecode/crawl4ai の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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