AIDEFEND in Action AIA-0181 Validated Research

Codex's Command-Safety Check Misread PowerShell: A 'Read-Only' Git Command Could Change Codex's Configuration

Codex can run certain commands without asking the developer. OpenAI confirmed that some affected versions could mistake a Git command run through PowerShell for a read-only operation. If the operating system permitted the write, the command could change which tools Codex starts on its next launch. OpenAI fixed the issue in Codex CLI 0.131.0 and corresponding Desktop releases.

Permission BypassConfiguration PoisoningHuman-in-the-LoopClient SecurityAI Coding Agent
5 applicable AIDEFEND defenses

Threat Analysis

  • An approval shortcut built on a parser. Codex, OpenAI's coding agent, runs shell commands on the developer's machine. To avoid asking about every routine step, it checks each proposed command and lets those it classifies as safe, such as viewing Git status or history, run without the user's approval. For PowerShell commands, the check reads the line with PowerShell's own parser, flattens the result into a list of words and compares it with a list of read-only uses. Before the fix, that list already rejected Git options that make Git write its output to a file.
  • Where the check and PowerShell disagreed. PowerShell's stop-parsing token, --%, tells PowerShell to stop interpreting the rest of the line and pass it to the external program as literal text; Microsoft's documentation says it substitutes only %VARIABLE% references. OpenAI's fix states that the check's flattening did not model this. In effect, the check saw the text after the token as one block, while Git received it as separate options, so a Git command that writes a file could pass as read-only. The CVE record classifies the flaw as CWE-150 (escape, meta or control sequences that are not correctly neutralized).
  • From a repository to code execution. According to OpenAI's advisory and the CVE record, a user had to open a repository the attacker prepared, and Codex had to follow its instructions to run such a Git command through PowerShell. Because the check called it safe, Codex ran it without asking. If file-system protections allowed the write, the command could change Codex's configuration file and add an attacker-controlled MCP server (Model Context Protocol; locally, a program the client starts to give the agent extra tools). The next time Codex loaded its configuration, it would start that server and run the attacker's code with the user's permissions; OpenAI says that code could read, modify or delete files the account can access.
  • What sets this case apart. In other coding-agent cases, web content rewrites the MCP configuration, or a repository defines servers that start after a trust prompt. Here the failing control is the approval decision itself: Codex's safety check and the real shell read the same line differently, so the user was never asked. The configuration change and the server start can also be separated in time, because the server runs only at the next configuration load.
  • What was demonstrated, and what is not public. A Compass Security team (Emanuele Barbeno, Cyrill Bannwart, Yves Bieri, Lukasz D. and Urs Mueller) used this single bug to exploit Codex on the first day of Pwn2Own Berlin, 14 May 2026, and OpenAI merged the fix in pull request #22643 the same day. ZDI-26-649, the advisory from the Zero Day Initiative (ZDI) that runs Pwn2Own, describes code execution in the context of the current user after the victim opens a malicious folder. The researchers have not published a write-up, so the wording of the repository instructions, the configuration file that was changed and the platform used are not public. OpenAI reports no known abuse in the wild, and the assessment that the US Cybersecurity and Infrastructure Security Agency (CISA) added to the CVE record lists exploitation as none.
  • Platforms, versions and scores. PowerShell is built into Windows; on macOS and Linux the chain needs a separately installed PowerShell Core (pwsh). OpenAI notes that the default macOS and Linux sandbox could stop Git from modifying the configuration file, because skipping approval does not turn the sandbox off, and makes no such statement for Windows. Affected, all ranges inclusive: Codex CLI 0.72.0 to 0.130.0, Codex Desktop for macOS 260202.0859 to 26.513.31313, Desktop for Windows 26.304.38 to 26.513.40821, and the Microsoft Store package 26.304.38.0 to 26.513.4821.0. Fixed: CLI 0.131.0 (published 18 May 2026), Desktop for macOS 26.519.22136, Desktop for Windows 26.519.21041 (Store package 26.519.2081.0). Scores differ: CISA's enrichment in the CVE record gives CVSS 3.1 8.8 with a network attack vector (AV:N), ZDI gives 7.8 with a local vector (AV:L), and OpenAI gives none.

Applicable AIDEFEND Defenses (5)

AID-H-003.010
Deployed AI Software Vulnerability Remediation Lifecycle
Very High
Replacing every affected Codex install with a fixed release removes this misclassification: since pull request #22643 the check treats any command carrying the stop-parsing token as unsupported, so it is no longer passed as safe and goes back to the normal approval flow. Count the CLI, both Desktop builds and the Microsoft Store package, because each has its own fixed version (CLI 0.131.0, Desktop for macOS 26.519.22136, Desktop for Windows 26.519.21041, Store package 26.519.2081.0). Upgrading does not remove an MCP server entry that was already added.
AID-I-004.006
Agent Identity & Persistent State File Write Protection
Very High
The Git command can change Codex only because the account running agent commands can write Codex's configuration. Put the files Codex loads its settings and MCP servers from (config.toml under CODEX_HOME and, for trusted projects, .codex/config.toml) behind an operating-system boundary that this account cannot undo, for example a read-only mount when Codex runs in a dev container or VM, or ownership and ACLs that leave the developer account read-only, and let settings change only through an approved path such as managed configuration. Even if the misclassified command runs, a blocked write leaves nothing for Codex to load next time.
AID-H-021.001
Client-Side Configuration Enforcement
High
Codex's administrator requirements, which user and project settings cannot override, can carry an allowlist of MCP servers: the client then starts only servers whose name and identity match an approved entry and disables any other, so a server added by an unauthorized configuration write is not started. Use the structured identity that pins the executable and its arguments, because the plain form matches only the command, and neither form covers environment variables or the working directory. Where no MCP server is needed, an empty allowlist disables them all. The same requirements can restrict approval policies and sandbox modes, so a changed configuration file cannot relax them.
AID-I-001.002
MicroVM & Low-Level Sandboxing
High
Codex's own sandbox confines the shell commands it runs and the processes they start: by default writes are limited to the active workspace, enforced by Seatbelt on macOS, bubblewrap with seccomp on Linux and a Windows sandbox implementation on Windows. OpenAI's advisory names the default macOS and Linux sandbox as something that could stop Git from modifying the configuration file, because skipping approval does not turn the sandbox off. Enforce a sandboxed profile through administrator requirements so repository or user settings cannot switch to full access, and prefer the stronger Windows implementation. The advisory makes no such statement for Windows, where PowerShell is built in, so test the effective profile there. The server the attacker added runs with the full permissions of the account that runs Codex, outside the command sandbox. Opening unfamiliar repositories with Codex inside a disposable, VM-backed environment that holds no host home directory, long-lived credentials or production access limits what that code can read, change or delete to the contents of that environment, which is discarded afterwards. The guidance's example selects a microVM runtime for Kubernetes workloads; on developer endpoints the equivalent is a VM-backed development environment whose isolation type is read back before use.
AID-E-003.003
Confirmed Malicious Code & Persistence Eviction
High
Removing the injected server entry is what ends the repeat launches. Because the server starts only at the next configuration load, an entry that an investigation finds and removes before then never starts at all. Once an MCP server entry in a Codex configuration file is confirmed as not added by its owner, keep a copy of the file and of any program it points to as evidence, remove the entry from every configuration file Codex loads on that machine (user and trusted project files, plus any backup or dotfile repository that would restore it), and confirm Codex no longer starts it. A server that is already running has to be stopped separately.

What Defenders Should Do Now

  • Find every Codex install and upgrade it. Read the installed version of the CLI, the Desktop app on macOS and Windows, and the Microsoft Store package on developer machines and runners. Any install at or below the last affected version for its product moves to the fixed release or later. Until an install can be upgraded, use Codex there only with repositories you trust and keep the sandbox on, as OpenAI advises.
  • Make Codex's configuration read-only to the agent. Put config.toml under CODEX_HOME (by default ~/.codex) and trusted projects' .codex/config.toml where the account running agent commands cannot change them, for example as read-only mounts in a dev container or VM, and route setting changes through managed configuration. Test it: have Codex run a harmless command that appends a comment to the file; the write must fail.
  • Allow only the MCP servers you approved. In Codex's administrator requirements, list each needed server with its exact executable and arguments, or leave the list empty where no MCP server is needed. Then add an unapproved server to a test machine's configuration and confirm that Codex disables it and that no process for it starts.
  • Keep the sandbox on, and check it on Windows. Require sandboxed profiles through the same requirements so a repository or user setting cannot switch to full access. On each platform, confirm that a command Codex runs cannot write a file next to its configuration file.
  • Look back for signs of use. Review the MCP server entries in Codex configuration files for any that nobody added on purpose. If you find an injected server, keep a copy of the file and of the program it points to as evidence, remove the entry from every configuration file Codex loads, and stop the server if it is still running.
  • Open unfamiliar repositories in a disposable environment. A VM-backed environment without host credentials limits what code started by Codex can reach if a later flaw lets a command skip approval again.

Conclusion

Upgrade Codex so the misclassified command returns to the normal approval process. AIDEFEND  also points to protecting the configuration files Codex actually loads and limiting which MCP servers it may start. Check both boundaries on managed machines so a mistake in command classification cannot silently change what runs.

Last updated: