Command Filter Bypass in LocalShellEnvironment via shell=True Allows Arbitrary OS Command Execution
9.9
Critical
CVSS 3.1 base
My assessment
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
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 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.
| Package | Ecosystem | Vulnerable | Fixed in |
|---|---|---|---|
ag2 | pip | >= 1.0.0, < 1.1.2 | 1.1.2 |
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.
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.
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.
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.
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.