Summary
Crawl4AI before version 0.8.8 contains a path traversal issue in its screenshot and PDF export endpoints, allowing arbitrary file writes through the output_path parameter.
When combined with symlink and TOCTOU tricks, unauthenticated remote attackers can write files outside the intended directory and potentially achieve code execution if they reach executable or scheduled task locations.
Affected context
This vulnerability appears in deployments of Crawl4AI that expose the screenshot and PDF HTTP endpoints over the network and rely on the output_path parameter to control where generated files are stored.
It is most relevant in environments where the service runs with a user account that has write access beyond a tightly scoped export directory, such as application, script, or cron folders.
The risk increases when file path validation is minimal, symlinks inside the export directory are possible, and concurrent or high-load operations create TOCTOU windows around filesystem checks and writes.
Exploit preconditions
- Attack surface: Public or internal HTTP API endpoints for screenshot and PDF generation.
- Required access: Network reachability to the Crawl4AI service; no authentication required in affected configurations.
- Trigger point: Submission of a crafted output_path parameter that leverages path traversal and symlink behavior during file creation.
- Why exploitation is possible: The code performs insufficient validation and canonicalization of output_path, trusts directory checks that can be invalidated by TOCTOU races, and follows symlinks that may point outside the intended export directory.
Why this happens
The underlying issue aligns with CWE-22 (Improper Limitation of a Pathname to a Restricted Directory), where user-controlled filesystem paths are not robustly confined to an allowed directory.
Crawl4AI's screenshot and PDF endpoints trust the output_path parameter for where to write generated files, but they do not fully normalize, validate, or enforce that the final resolved path stays within a safe base directory.
Combined with symlink following and race conditions between checking and using paths, this creates a generic arbitrary file write pattern: attackers can redirect file writes into sensitive locations, such as configuration or executable directories, by manipulating symlinks or traversal segments.
Potential impact
- Attackers may write arbitrary files anywhere the runtime user has write permissions.
- They could place or modify scripts, binaries, or cron jobs, leading to code execution on subsequent runs.
- They may deface or corrupt application configuration, logs, or data files.
- They could introduce backdoors or persistence mechanisms by altering startup scripts or scheduled tasks.
- They may interfere with system stability by overwriting critical but writable files.
General mitigation guidance
Effective mitigation focuses on constraining and hardening filesystem interactions rather than any specific product version.
Common defensive patterns include:
- Enforcing a strict, static base directory for all generated files, and rejecting any output_path that escapes this directory after full canonicalization and resolution.
- Normalizing paths (e.g., resolving ".." segments) and validating the final absolute path against an allowlist or prefix check.
- Disabling symlink following for export directories where possible, or verifying that the final resolved path does not traverse through or terminate at symlinks outside allowed locations.
- Eliminating TOCTOU windows by performing atomic filesystem operations (e.g., open with flags that create and lock files in a single step) and avoiding separate check-then-use sequences.
- Running the service under a dedicated low-privilege account that lacks write access to executable, configuration, or cron directories, thereby limiting the impact of any file write misbehavior.
How teams detect issues like this
Organizations can identify this class of vulnerability through a combination of static, dynamic, and review-based approaches:
- Static analysis rules that flag direct use of user-controlled paths in file write operations without prior normalization and directory confinement checks.
- Code reviews that look for patterns such as concatenating user-supplied strings into filesystem paths, reliance on simple string prefixes for validation, or use of separate access checks followed by open/write calls.
- Security tests and fuzzing that attempt path traversal payloads (e.g., "../" sequences) and symlink redirections in APIs that accept file paths or output locations.
- Policy enforcement in CI/CD requiring explicit path canonicalization routines, use of secure filesystem APIs, and documented constraints around directories used for generated artifacts.
- Periodic runtime monitoring or file integrity checks on sensitive directories to detect unexpected files created by application processes, which can signal exploitation attempts.

