Summary
Langroid's file tools treat a configured curr_dir as a workspace boundary but fail to enforce that user-supplied file paths stay within that directory.
When exposed to LLM agents or user-controlled tool calls, this can allow reading or writing files outside the intended project directory via path traversal sequences.
Affected context
This vulnerability affects applications built with Langroid that use ReadFileTool and WriteFileTool while assuming curr_dir safely constrains file access.
It becomes relevant when:
- The tools are exposed to LLM agents, delegated coding/documentation agents, or user-driven tool invocation, and
- Those agents can influence the
file_pathparameter, and - The host environment contains sensitive files reachable via parent directory traversal.
In such setups, the process working directory is changed to curr_dir, but the actual paths are never normalized or checked against this boundary.
Exploit preconditions
- Attack surface: File tool interfaces in Langroid-based applications (LLM agent tools, user tool calls, or automation agents).
- Required access: Ability to supply or influence the
file_pathargument toReadFileToolorWriteFileTool. - Trigger point: Execution of a file operation where
file_pathincludes traversal like../or other constructs that reach outsidecurr_dir. - Why exploitation is possible: The code relies solely on changing the process working directory to
curr_dirand does not canonicalize or validate that the resolved file path remains under this directory, enabling path traversal.
Why this happens
The underlying issue is a missing authorization check on filesystem paths, aligning with CWE-22: Improper Limitation of a Pathname to a Restricted Directory and CWE-23: Relative Path Traversal.
Instead of treating curr_dir as a hard boundary and enforcing that resolved paths are descendants of this directory, the tools simply set the process working directory and operate on user-controlled file_path values as-is.
Without canonicalization (e.g., resolving .., symlinks, and absolute paths) and post-checks to confirm the final path remains within curr_dir, an attacker-controlled path can escape the intended workspace and target arbitrary accessible files.
Potential impact
- Reading sensitive files outside the intended workspace directory, such as configuration files, secrets, or source code.
- Writing or overwriting files outside the workspace, potentially altering application behavior or corrupting data.
- Expanding an LLM agent's visibility into the host filesystem beyond what the application designer intended.
- Facilitating further compromise if the accessible files include credentials, API keys, or other security-sensitive material.
General mitigation guidance
Effective mitigation focuses on enforcing a strict directory boundary and reducing trust in user-controlled paths:
- Canonicalize and normalize any user-supplied path (resolving
.., symbolic links, and relative segments) before use. - Enforce that the resolved absolute path is a descendant of the configured
curr_dir(e.g., prefix or common-path checks) and reject any that escape this boundary. - Avoid relying solely on the process working directory for access control; treat directory constraints as explicit authorization checks.
- Limit the file operations exposed to LLM agents or external callers to a narrow, well-defined subset of files or directories where possible.
- Run file-accessing components with least-privilege OS permissions so that even escaped paths cannot reach highly sensitive system locations.
How teams detect issues like this
Organizations can look for this class of issue using:
- Static analysis: Rules that flag file operations using user-controlled paths without prior normalization and directory-boundary checks.
- Code review: Indicators include:
- Direct use of user-provided
file_pathinopen(),read(), orwrite()calls. - Reliance on
chdir()or equivalent as the only mechanism for constraining file access. - Absence of checks comparing resolved paths against an allowed base directory.
- Runtime monitoring: Logging and analyzing file access patterns from LLM tools for unexpected directories or repeated
../usage. - Policy enforcement: CI/CD checks enforcing that file tools must validate paths against declared workspace roots, optionally supported by automated security review tools.

