OpenAI Codex Command Injection: Malicious GitHub Branch Names as a Token-Theft Path
BeyondTrust Phantom Labs reported that OpenAI Codex accepted a GitHub branch name into a container setup shell path, allowing command injection that exposed GitHub OAuth and installation tokens. The issue affected Codex Web and could be replicated through CLI, SDK, and IDE credentials; an automated variant used malicious branch refs to target multiple users working in a shared repository. OpenAI remediated the reported issues, but the defensive lesson remains: repository metadata must be treated as untrusted execution input.
Threat Analysis
- GitHub metadata reached a shell command. BeyondTrust found that the branch parameter in the Codex task request was reflected into setup logic that fetched the selected repository and branch.
- The branch name became command injection. Shell metacharacters in a GitHub branch ref could break out of the expected command context and run attacker-controlled commands inside the Codex container.
- The target was the GitHub token Codex used for the task. During repository clone and review flows, Codex used OAuth or GitHub App installation tokens. The injected command could copy token-bearing remote configuration or logs and send the value outward.
- The attack could scale through the repository. An attacker with branch-control rights could create or modify a malicious branch, hide payloads with Unicode spacing, or make the branch default so other Codex users trigger the payload.
- Local Codex credentials expanded the path. The report also describes Codex CLI, SDK, and IDE credentials in
~/.codex/auth.json, which could be used to call backend APIs and retrieve task history or logs.
Applicable AIDEFEND Defenses (9)
~/.codex/auth.json. Local agent credentials should use platform-native secure storage where possible, short lifetimes, logout cleanup, and server-side deauthorization so a compromised endpoint cannot easily replay Codex backend access.What Defenders Should Do Now
- Confirm that OpenAI's fixes are applied in the Codex products your team uses, then inventory every GitHub organization and repository where Codex or similar coding agents are authorized.
- Audit GitHub App permissions and user OAuth grants for Codex-like agents. Remove broad organization-wide access where a task only needs one repo, one branch, or read-only review capability.
- Treat GitHub branch names, ref names, repository names, PR titles, issue text, and setup parameters as untrusted input before they enter agent containers, shell commands, setup scripts, or logs.
- Restrict Codex container egress during setup and runtime. Allow package registries and GitHub endpoints only when required, and alert on unknown outbound hosts.
- Add repository-side detections for branch refs containing
;,|, backticks,${IFS}, command substitution, or suspicious Unicode whitespace. Review recent default-branch changes. - If exposure is possible, revoke Codex-related GitHub tokens, rotate affected credentials, review GitHub audit logs for token use, and inspect Codex task history or container logs for leaked token material.
1 additional consideration
SCM-side branch naming and default-branch governance for AI agents
Conclusion
This Codex case shows how agent risk can start before the model makes any coding decision. A GitHub branch name is normal repository metadata, but once it is copied into a shell command inside an agent container, it becomes execution input. AIDEFEND maps the defensive baseline clearly: prevent unsafe code execution, stop tokens from flowing into logs or outbound HTTP, scope service credentials tightly, bind each agent task to accountable identity, restrict egress, monitor suspicious repository metadata, and revoke exposed tokens quickly.