Sanaan Fayaz Wani

ag2ai/ag2

GHSA-qrjx-72xx-xhmh

Path Traversal in DiskKnowledgeStore via Incorrect startswith Path Containment Check

GHSA-qrjx-72xx-xhmh

8.1

High

CVSS 3.1 base

My assessment

  1. 2026-05-22Reported privately
  2. 126 days later2026-09-25Published by the maintainer

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

CVSS 3.1 metrics

To exploit it

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None

What it gets

Confidentiality
High
Integrity
High
Availability
None
Scope
Unchanged

Open this vector in the FIRST calculator ↗

Weakness
CWE-22 Improper Limitation of a Pathname to a Restricted Directory
CVE
not assigned
Vector
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N
Also in ag2
GHSA-42mf-vpmr-gw5r 9.9
2026-05-22Reported privately
126 days
2026-09-25Published by the maintainer

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.

Affected versions

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

Summary

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.

Where it lives

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 resolved

The 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.

Impact

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.

Fix

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.

The record

Weakness
CWE-22 Improper Limitation of a Pathname to a Restricted Directory
Affected
ag2 0.12.2 to before 1.1.0fixed in 1.1.0autogen 0.12.2 to 0.14.1no fix listed
Disclosure
2026-05-22 Reported privately
126 days later2026-09-25 Published
Advisory
GHSA-qrjx-72xx-xhmh
Also in ag2
GHSA-42mf-vpmr-gw5r 9.9

About this writeup

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.