Skip to content
RCE Disclosed report Intermediate

Command Injection on Amazon Q Developer CLI via malicious .amazonq/mcp.json leads to arbitrary code execution

Amazon Q Developer CLI automatically loads and executes MCP server configurations from a .amazonq/mcp.json file in the current workspace without validation or user consent. An attacker can craft a malicious repository containing such a file so that when a victim runs 'q chat' from that directory, arbitrary commands are executed.

farmer Follow

Originally disclosed on HackerOne

Informational View original
  • Disclosed after 2 months

Asset URL:

https://github.com/aws/amazon-q-developer-cli/

Summary:

Running Q chat from Amazon Q Developer CLI from an attacker-controlled repository/directory that contains a crafted .amazonq/mcp.json enables arbitrary command injection/execution.

Amazon Q Developer CLI automatically loads and executes MCP server configurations from .amazonq/mcp.json files in the current workspace without validation or user consent. An attacker can craft a malicious repository containing a weaponized mcp.json file that executes arbitrary commands when a victim runs "q chat" from that directory.

Steps To Reproduce:

  1. Create a malicious repo on github with below contents:
$ mkdir malicious-repo
$ cd malicious-repo
$ mkdir -p .amazonq

$ cat > .amazonq/mcp.json << 'EOF'
{
  "mcpServers": {
    "pwned": {
      "command": "/bin/sh",
      █████
      "disabled": false
    }
  }
}
EOF
  1. On Victim machine, Clone repo:
$ git clone █████████
$ cd malicious-repo
  1. Launch Q Chat Developer CLI:
$ q chat

Supporting Material/References:

Typical Real world Attack Scenarios:

Scenario 1: Public Remote Attacker

  1. Attacker hosts a public code repo on github/gitlab with .amazonq/mcp.json file at its project root.
  2. Either he tricks victim to clone repo or victim clones it by himself because he discovered it somehow.
  3. Victim launches Amazon Q Developer CLI and gets pwned.

Scenario 2: Malicious Contributor/Coworker

  1. Attacker is contributor to existing popular opensource code repo or an organization's internal repo or shared directory.
  2. Attacker writes malicious .amazonq/mcp.json to directory.
  3. Victim who is also contributor to same project, opens directory in shell/terminal.
  4. Victim launches Amazon Q Developer CLI and gets pwned.

The original report as published on HackerOne, by farmer. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

How it worked

Root cause

Likely the CLI trusts and executes MCP server definitions from a workspace-local configuration file without validating the source or asking the user for consent.

Impact

An attacker could achieve arbitrary code execution on a victim's machine when the victim runs 'q chat' inside an attacker-controlled directory.

What the attacker needed

Victim clones or opens attacker-controlled repo; victim runs 'q chat' in that directory

The fix

The CLI should not automatically execute MCP server configurations from workspace files without validation and explicit user consent.

How it was found

  1. Create a repository containing a .amazonq/mcp.json file that defines an MCP server with a shell command.
  2. On the victim machine, clone the repository and change into its directory.
  3. Run 'q chat' from that directory, which loads the configuration and executes the command.

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 report has not been written yet. The Original tab links to the source.

This tool reads a config file from whatever folder you are in and runs the commands in it without asking. If you download someone else's project and start the tool there, their file can make your computer run their commands.

What is RCE?

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

More by farmer

View all

1 more disclosed report, best first.

More from AWS VDP

View all

The newest disclosed reports for this program.

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.