Repository navigation
fix(config): leave the auto-added sec-ch-ua header out of BrowserConfig.dump() - #2473
Merged
Merged
Conversation
…ig.dump() The Docker client got 400 with any BrowserConfig because dump() always sent the generated headers field.
ntohidi
approved these changes
Nov 2, 2026
ntohidi
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, nice fix. Checked that both new tests fail on develop and pass here, and the provenance and playground tests are green. Custom headers still hit the gate, so nothing changes on the security side. As a bonus, user_agent_mode="random" now gets a sec-ch-ua that matches the new UA after load. LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2472.
BrowserConfig.__init__always adds asec-ch-uaheader derived fromuser_agent, sodump()always sentheaders. The server forbidsheadersfrom an untrusted request, soCrawl4aiDockerClientgot 400 with anyBrowserConfig, evenBrowserConfig().dump()now leaves outsec-ch-uawhen it is the auto-added value (== self.browser_hint), and dropsheadersif nothing is left.load()runs__init__, which adds the same value back fromuser_agent, so nothing is lost. Headers the user set, including their ownsec-ch-ua, are still sent and still refused by the server. No server code changes.List of files changed and why
crawl4ai/async_configs.py: the change inBrowserConfig.dump().tests/unit/test_config_provenance.py: two tests. A default and a custom-UABrowserConfigdump passes the untrusted load and loads back the same headers; custom headers stay in the dump and are still refused.deploy/docker/tests/test_playground_config_protocol.py: removed the guard that asserted the/config/dumpecho still has a forbidden field. Its message said it could go oncedump()is re-submittable. The check that the page forwards the typed params stays.deploy/docker/static/playground/index.html: the comment said the echo carriesheadersthe gate refuses, which is no longer true. Comment only.How Has This Been Tested?
tests/unit,tests/deep_crawling, the config, serialization, security and playground tests: same failures as develop (environment only: PDF libs, browser TLS flags), plus the two new tests.Crawl4aiDockerClientagainst a local server:BrowserConfig(),verbose=True, customuser_agent,user_agent_mode="random",text_mode,light_mode,enable_stealth, viewport,stream=True: 400 on develop, 200 with the fix.headers={"X-A": "1"}andheaders={"sec-ch-ua": "fake"}still 400.https://httpbin.org/headersthrough the server: the site still gets asec-ch-uathat matches the user agent (default and a Chrome 131 UA).headersor other casings give the same result as before.Checklist: