Summary
A path traversal vulnerability in PraisonAI's CODE_TOOLS wrappers can allow prompt-influenced operations to access files outside the intended project workspace. When a workspace has not been configured, exposed file-reading and file-modification helpers may process paths without containment checks.
Affected context
The vulnerability occurs in PraisonAI deployments that expose code_read_file, code_search_replace, or code_apply_diff before set_workspace establishes a valid project directory. In this state, the wrappers retain a null workspace and pass it to helpers that enforce path containment only when a workspace value is present. Explicitly configured workspaces can continue to provide effective path restrictions.
Exploit preconditions
- Attack surface: CODE_TOOLS file-access and file-editing helpers exposed to an agent or application
- Required access: Ability to influence prompts or tool calls processed by the application
- Trigger point: Invocation of file-reading or file-modification operations before workspace initialization
- Why exploitation is possible: A missing workspace disables the intended path-containment check, allowing supplied paths to resolve outside the project directory
Why this happens
The underlying bug is an unsafe authorization and path-validation pattern. The CODE_TOOLS wrappers preserve _workspace_root as None and pass workspace=None to helper functions whose containment checks are conditional on a truthy workspace value. As a result, file paths are not consistently constrained to an approved directory when initialization is skipped. This primarily maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, with related exposure and authorization concerns represented by CWE-200 and CWE-863.
Potential impact
- An attacker may read sensitive files accessible to the application process.
- An attacker could modify, replace, or delete files outside the intended project directory.
- Exposed credentials, configuration data, or source code may be disclosed.
- Application integrity could be undermined through unauthorized workspace changes.
- Further compromise may be possible if modified files are later executed or trusted by another process.
General mitigation guidance
Mitigation generally focuses on making workspace initialization mandatory and enforcing path containment independently of optional configuration values.
Common defensive patterns include:
- Fail closed when no valid workspace has been configured.
- Resolve and canonicalize paths before comparing them with an approved workspace root.
- Apply containment checks to every file operation, including reads, writes, replacements, and diffs.
- Avoid deriving tool paths directly from prompt-controlled values without validation.
- Expose file-modification tools only to trusted workflows and use least-privilege process accounts.
- Restrict accessible directories through sandboxing, filesystem permissions, and policy enforcement.
How teams detect issues like this
Organizations can detect similar issues through:
- Static analysis rules that identify optional or null path-validation guards.
- Code review checks for file operations that accept user- or prompt-influenced paths.
- Tests that invoke tools before initialization and verify that they fail closed.
- Policy checks requiring canonicalization and containment validation for filesystem access.
- Runtime monitoring for tool calls accessing paths outside approved project roots.
Automated code review and security scanning tools may help identify missing authorization checks and unsafe filesystem patterns.

