The vulnerability exists in the 'computed fields' feature of the JsonCssExtractionStrategy class in crawl4ai. The root cause is the direct use of eval() on untrusted user input provided in a crawl request's extraction schema. The function JsonCssExtractionStrategy._compute_field took a user-provided string from the expression key and executed it using eval(), leading to a straightforward remote code execution vulnerability.
An attempt was made to mitigate this with a sandboxed evaluation function, _safe_eval_expression. However, this sandbox was flawed. It relied on a weak blocklist that only prevented access to attributes starting with an underscore. The exploit bypassed this by using a generator expression to gain access to a gi_frame object. From there, it could traverse the call stack via the f_back attribute on frame objects until it reached the top-level frame and its f_builtins, which contains the original, unrestricted __import__ function. This provided a complete sandbox escape, again leading to RCE. The patches correctly identified both _compute_field and _safe_eval_expression as the vulnerable components, first by removing the dangerous eval() call in _compute_field and subsequently by hardening the _safe_eval_expression sandbox with a strict allowlist approach to prevent frame-walking exploits.