Path Traversal in DiskKnowledgeStore via Incorrect startswith Path Containment Check
8.1
High
CVSS 3.1 base
My assessment
What to do
If you run ag2 0.12.2 to before 1.1.0, upgrade to 1.1.0 or later.
If you run autogen 0.12.2 to 0.14.1, no fixed version is listed in the advisory.
Anyone who can reach it over the network, with a low-privilege account and no user interaction, can read and change sensitive data.Read from the CVSS 3.1 vector
To exploit it
What it gets
My analysis of this finding: root cause, the vulnerable code, the impact and the fix, in the site’s format. The official advisory of record is linked above.
GitHub published this advisory as High with no CVSS score and no vector, in v3 or v4. The score and vector above are my own assessment of the finding, within the severity band GitHub published. Where GitHub publishes a numeric score, this page shows that one instead.
| Package | Ecosystem | Vulnerable | Fixed in |
|---|---|---|---|
ag2 | pip | >= 0.12.2, < 1.1.0 | 1.1.0 |
autogen | pip | >= 0.12.2, <= 0.14.1 | n/a |
AG2’s beta DiskKnowledgeStore maps agent-supplied virtual paths onto real files under a root directory, and tries to keep every operation inside that root with a single containment check. The check compares the resolved path against the root with str.startswith, which is a classic path-confinement anti-pattern: a sibling directory whose name merely shares a prefix with the root satisfies the test. So a path like ../store_evil/secret.txt resolves outside the intended root yet passes validation, and every read, write, list, delete, and append in the store inherits the hole.
The containment logic is one line in autogen/beta/knowledge/disk.py, inside _resolve():
def _resolve(self, path: str) -> Path: """Map virtual path to real filesystem path.""" normalized = _normalize(path).lstrip("/") resolved = (self._root / normalized).resolve() if normalized else self._root.resolve() if not str(resolved).startswith(str(self._root.resolve())): raise ValueError(f"Path traversal blocked: {path}") return resolvedThe bugstring prefix check lets prefix-sharing sibling directories through
_resolve() is the single gate for the whole store: read, write, list, delete, exists, append, read_range, and on_change all route their path argument through it. Whatever _resolve() lets out, those methods will operate on.
The rest of the codebase already knows the right way to do this. is_relative_to() is the correct, prefix-safe containment check, and it is used elsewhere for exactly this purpose (for example filesystem.py:246 and apply_patch_tool.py:245), making disk.py the outlier.
With root="/data/store", the virtual path ../store_evil/secret.txt resolves to /data/store_evil/secret.txt. The guard asks whether "/data/store_evil/secret.txt".startswith("/data/store"), which is True, so the traversal is “blocked” only in name. The caller then reads, overwrites, or deletes a file in a directory that was never meant to be reachable.
Because _resolve() backs every operation, the primitive is read and write and delete, not read alone. An attacker who influences the path an agent passes to the knowledge store can exfiltrate files from, or clobber files in, any sibling directory sharing the root’s name prefix, escaping the sandbox the store is supposed to provide.
I verified this against a faithful copy of the vulnerable _resolve(): the traversal path was accepted, resolved into a sibling directory, and read back a planted secret file, while the is_relative_to() version rejected the same path.
Replace the startswith test with a true ancestor check:
if not resolved.is_relative_to(self._root.resolve()): raise ValueError(f"Path traversal blocked: {path}")The fixcompares path components instead of string prefixes
Path.is_relative_to compares path components rather than string prefixes, so /data/store_evil is correctly recognized as outside /data/store. This matches what the project already does in filesystem.py and apply_patch_tool.py.
Sanaan Fayaz Wani (GitHub sfwani) reported this vulnerability to the ag2 maintainers under coordinated disclosure and is credited as a reporter in GHSA-qrjx-72xx-xhmh, published 2026-09-25.
All published findings: advisory index.