Summary
Crawl4AI's computed fields feature includes a flawed expression sandbox that allows crafted schemas to break out of evaluation restrictions and run arbitrary Python code.
Because POST /crawl can be accessed without authentication by default, an attacker can remotely trigger arbitrary code execution on the host running the crawler.
Affected context
The vulnerability occurs in deployments that expose the Crawl4AI HTTP interface and use the computed fields feature for dynamic extraction schemas.
Risk is present when the _safe_eval_expression() function processes user-supplied expressions and relies on an AST-based validator that only blocks attribute names starting with an underscore.
In such setups, expressions delivered via POST /crawl are effectively treated as trusted logic, even if the caller is unauthenticated or the JWT mechanism remains disabled.
Exploit preconditions
- Attack surface: HTTP POST requests to the /crawl endpoint in Crawl4AI.
- Required access: Network reachability to the service; no authentication needed when JWT is disabled (default configuration).
- Trigger point: Submission of a crafted extraction schema that uses computed fields, causing _safe_eval_expression() to evaluate the supplied expression.
- Why exploitation is possible: The AST validator only filters attribute names starting with underscore and does not account for generator and frame object attributes (e.g., gi_frame, f_back, f_builtins), enabling access to runtime internals and arbitrary code execution.
Why this happens
This issue stems from an incomplete sandbox design in the expression evaluation mechanism used by the computed fields feature.
The _safe_eval_expression() routine attempts to secure evaluation by walking the AST and disallowing attributes with names that begin with an underscore, assuming this will block access to sensitive internals.
However, Python generator and frame objects expose powerful attributes (such as gi_frame, f_back, and f_builtins) that do not begin with an underscore but still grant access to interpreter frames, global namespaces, and builtins.
This behavior maps to CWE-94: Improper Control of Code Generation and CWE-913: Improper Control of Dynamically-Managed Code Resources, because untrusted expressions are evaluated under insufficient constraints, allowing them to influence and execute dynamic code.
Potential impact
- An attacker can achieve arbitrary code execution in the Crawl4AI process.
- The host system running Crawl4AI may be fully compromised.
- Crawling infrastructure and collected data can be modified, exfiltrated, or destroyed.
- The compromised instance can be abused as a pivot point for further attacks within the environment.
- Service availability may be affected through destructive payloads or resource exhaustion.
General mitigation guidance
Effective mitigation focuses on removing or strictly hardening dynamic expression evaluation paths and reducing trust in user-provided schemas.
Common defensive patterns include:
- Avoiding generic eval-like mechanisms for user-controlled expressions; prefer declarative, data-only schemas rather than executable code.
- Using whitelisted, domain-specific languages (DSLs) or restricted expression evaluators that expose only safe operations and data.
- Implementing robust AST-based validation that blocks all access to runtime internals, frames, builtins, and reflection APIs, rather than relying on simple name-based checks.
- Running the crawler with least privilege, limiting file system access, network reach, and operating system capabilities to reduce impact if an escape occurs.
- Isolating expression evaluation in separate, locked-down processes or containers to enforce strong sandbox boundaries.
- Requiring authentication and authorization for API endpoints that accept dynamic extraction schemas and computed fields.
How teams detect issues like this
Detection typically involves both code-level analysis and runtime monitoring:
- Static analysis rules that flag any use of eval, exec, or custom evaluators that process user-supplied expressions, especially when tied to HTTP endpoints.
- Code review patterns that call out AST-based "safe eval" implementations, checking for access to frames, builtins, or other interpreter internals.
- Security tests and fuzzing focused on the computed fields mechanism, attempting to access attributes of generators, frames, and builtins.
- Logging and monitoring of extraction schemas and computed field expressions, with anomaly detection for suspicious attribute names or access patterns.
- Policy enforcement in CI/CD pipelines to prevent deployment of new or modified code that introduces unsafe dynamic evaluation.

