fix: add allowlist for from_serializable_dict type instantiation#1856
Open
jannahopp wants to merge 1 commit intounclecode:mainfrom
Open
fix: add allowlist for from_serializable_dict type instantiation#1856jannahopp wants to merge 1 commit intounclecode:mainfrom
jannahopp wants to merge 1 commit intounclecode:mainfrom
Conversation
from_serializable_dict resolves any class name exported by crawl4ai from a user-supplied "type" string, enabling arbitrary class instantiation via crafted JSON (reachable through MCP /crawl endpoint via BrowserConfig.load() and CrawlerRunConfig.load()). Add CRAWL4AI_DESERIALIZE_ALLOW env var: a comma-separated list of class names permitted for deserialization. Empty or unset = deny all typed deserialization (default-deny). Operators configure exactly the types their deployment needs. Example: CRAWL4AI_DESERIALIZE_ALLOW=BrowserConfig,CrawlerRunConfig,CacheMode Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Why
from_serializable_dictinstantiates any class exported bycrawl4ai(~100+ classes) based on a user-supplied"type"string in JSON. When crawl4ai runs as an MCP server, this input comes from untrusted MCP clients via the/crawlendpoint — an attacker can trigger instantiation of classes never intended for deserialization (crawlers, dispatchers, Docker clients, etc.).Rather than guessing which classes are safe, this fix lets operators declare exactly which types their deployment needs via an environment variable. Empty or unset = deny all (default-deny).
Changes
CRAWL4AI_DESERIALIZE_ALLOWenv var: comma-separated list of permitted class names.load()call sites inserver.pyandapi.pyto return HTTP 400 (instead of 500) for disallowed typesTest plan
TestDeserializationAllowlisttests pass (8 tests)/crawlreturns HTTP 400 with clear error message/crawlwith default (empty) config works normally/md,/screenshotendpoints unaffected🤖 Generated with Claude Code