Exploiting Gemini CLI: How Security Flaws Allow Malicious Command Execution

In less than 48 hours, researchers uncovered a critical flaw in Google's Gemini CLI, an AI coding tool, enabling attackers to covertly siphon sensitive data by compromising its default configurations. This tool, a terminal-integrated coding assistant akin to Gemini Code Assist, is powered by Google's advanced Gemini 2.5 Pro model.
On June 25, the day of Gemini CLI’s launch, a publication highlighted the security breach formulated by Tracebit’s experts by June 27. Their method bypassed safety measures intended to prevent harmful command execution by manipulating users into adding a benign-looking command to an allow list after convincing Gemini to describe a maliciously crafted code package.
These packages, frequently hosted on platforms like NPM, PyPI, or GitHub, masked their intent with common metadata files. Tracebit’s subtle prompt injection targeted the inherent weaknesses of AI models to execute unauthorized commands, causing devices to send variable data to a rogue server, including potentially sensitive information like account credentials.
Particularly alarming was the possible execution of destructive commands such as rm -rf /
or denial-of-service attacks like forkbombs. Tracebit's demo emphasized the potential for severe damage, prompting Google’s swift release of a high-priority fix.
The tendency of AI models to execute user directives, even when intercepted maliciously, presents a significant threat. Here, the indirect prompt injection exploited Gemini CLI's flawed authentication and user interface.
The vulnerability was exacerbated by combining improper validation of commands with deceptive user instructions. Gemini CLI users were misled into approving seemingly safe commands, which secretly included harmful elements. These elements, such as grep
, env
, and curl
, were ingeniously concealed to evade detection.
Researchers took advantage of AI's eagerness to follow commands, known as AI sycophancy, embedding directives that exploited this trait. Similar attempts on other tools like Anthropic Claude and OpenAI Codex proved ineffective, as they had superior safeguard processes.
To mitigate risks, it is essential that users update to the latest Gemini CLI version 0.1.14 and employ sandbox environments for untrusted code.