Sanaan Fayaz Wani

ag2ai/ag2

GHSA-42mf-vpmr-gw5r

Command Filter Bypass in LocalShellEnvironment via shell=True Allows Arbitrary OS Command Execution

GHSA-42mf-vpmr-gw5r

9.9

Critical

CVSS 3.1 base

My assessment

  1. 2026-05-22Reported privately
  2. 134 days later2026-10-03Published by the maintainer

What to do

If you run ag2 1.0.0 to before 1.1.2, upgrade to 1.1.2 or later.

Anyone who can reach it over the network, with a low-privilege account and no user interaction, can read and change sensitive data and make it unavailable, and the impact reaches beyond the vulnerable component.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
High
Scope
Changed

Open this vector in the FIRST calculator ↗

Weakness
CWE-78 Improper Neutralization of Special Elements used in an OS Command
CVE
not assigned
Vector
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H
Also in ag2
GHSA-qrjx-72xx-xhmh 8.1
2026-05-22Reported privately
134 days
2026-10-03Published 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 Critical 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 >= 1.0.0, < 1.1.2 1.1.2

Summary

AG2’s beta LocalShellEnvironment (formerly Microsoft AutoGen) advertises three ways to constrain what an agent can run in a shell: an allowed whitelist, a blocked blacklist, and a readonly mode backed by a curated READONLY_COMMANDS list. Every one of them is a prefix check applied to the raw command string, and the command is then handed to subprocess.run(..., shell=True). Because the OS shell, not the filter, decides where one command ends and the next begins, any allowed prefix can be followed by ;, &&, |, or $(...) to run arbitrary commands. The restriction is cosmetic.

Where it lives

The filter, in autogen/beta/tools/shell/environment/base.py, only looks at how the string begins:

def matches(pattern: str, command: str) -> bool:    stripped = command.strip()    if not stripped.startswith(pattern):        return False    rest = stripped[len(pattern):]    return rest == "" or rest[0] == " "

The bugonly checks how the command string begins

LocalShellEnvironment.run() in environment/local.py runs whatever passes that check through a full shell:

if self._allowed is not None and not any(matches(p, command) for p in self._allowed):    return f"Command not allowed: {command!r}"...result = subprocess.run(    command,    shell=True,    cwd=self._workdir,    ...)

The bugruns the filtered string through a full shell

The code already knows. The comment above READONLY_COMMANDS in base.py calls the list “best-effort” and notes that “echo can still redirect output (echo x > file), because shell=True processing happens inside the OS shell after our prefix check.” That caveat understates it: the same mechanism allows arbitrary execution, not just redirection.

Impact

The security boundary the API promises does not exist. A caller who trusts readonly=True, or an allow list, to pen in an LLM-driven or otherwise untrusted command string gets full OS command execution under the process’s privileges instead.

readonly / allow list bypass. echo x; id begins with the allowed echo, so it passes, and the shell then runs id. git --version && id passes an allowed=["git"] gate the same way. cat /dev/null | id passes readonly=True and pipes into an arbitrary program.

blocklist bypass. blocked=["rm", "curl"] is evaded by echo $(rm -rf /), which never starts with a blocked prefix yet executes rm inside a subshell.

I confirmed each of these against a faithful copy of matches() and READONLY_COMMANDS driving a real subprocess.run(..., shell=True): in every case the filter returned “allowed” and the injected id produced uid= output.

Fix

Stop treating a prefix of a shell string as a security boundary. Either tokenize with shlex.split() and execute argv-style with shell=False, validating the resolved program against the allow list, or run inside a real sandbox. If shell=True must stay, reject any command containing shell metacharacters (;, &, |, $, backticks, redirections, newlines) before it reaches subprocess.run, and document that the prefix lists are not a privilege boundary.

The record

Weakness
CWE-78 Improper Neutralization of Special Elements used in an OS Command
Affected
ag2 1.0.0 to before 1.1.2
Fixed in
1.1.2
Disclosure
2026-05-22 Reported privately
134 days later2026-10-03 Published
Advisory
GHSA-42mf-vpmr-gw5r
Also in ag2
GHSA-qrjx-72xx-xhmh 8.1

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-42mf-vpmr-gw5r, published 2026-10-03.

All published findings: advisory index.