Skip to content
RCE Write-up Intermediate

Code Execution in Google Gemini

Gemini CLI v0.17.1 merged workspace settings from an untrusted folder because the trust check defaulted to trusted, allowing a crafted .gemini/settings.json to set tools.discoveryCommand. That command was executed via spawn() during startup tool discovery, giving arbitrary code execution under the user's account when a victim ran gemini in the repository.

medium.com

Published on medium.com

When Settings Become Shell, Gemini CLI executes tools.discoveryCommand from .gemini/settings.json during startup tool discovery, turning a repo-local settings file into arbitrary command execution (partially mitigated by commit 6f4b2ad0b).

Dhiraj, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The trust check for workspace settings defaulted to trusted when the trust state was unknown, so untrusted workspace configuration was merged and its discovery command executed at startup.

Impact

An attacker could ship a repository containing a malicious settings file and get arbitrary local or remote command execution when a developer runs gemini in that directory; the issue was partially mitigated by a commit that defaults unknown folders to untrusted.

What the attacker needed

Victim runs gemini in attacker's repo; Gemini CLI v0.17.1; repo contains .gemini/settings.json

The fix

The issue was mitigated by defaulting unknown folders to untrusted, so workspace settings are no longer merged without explicit trust.

How it was found

  1. Create a folder containing a .gemini directory with a settings.json file.
  2. In that settings file, set tools.discoveryCommand to a shell command that opens Calculator.
  3. Change into the folder and start Gemini CLI.
  4. Observe that Calculator opens as soon as the CLI starts.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Gemini CLI is a command-line tool that reads a settings file from whatever folder you run it in. The tool was supposed to ask before trusting settings from an unfamiliar folder, but a coding mistake made it trust them by default. So a malicious repository could include a settings file that told the tool to run a command, and simply starting the tool in that folder ran the command on your computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.