# GitHub MCP prompt injection: a public issue could make an agent leak private repository data

Source: https://botpassword.com/incidents/2025-05-github-mcp-prompt-injection
Disclosed: 2025-05-26 · Type: AI agent · Status: Status unknown · Updated: 2026-10-25

In May 2025 Invariant Labs showed that an AI agent connected to the official GitHub MCP server with a broadly scoped GitHub token could be hijacked by a prompt injection hidden in an issue on a public repository. Asked to "look at the open issues", the agent read the issue, pulled data from the owner's private repositories and published it in a pull request on the public repo. The fix is not a patch but a narrower token: give agents fine-grained GitHub tokens limited to the repositories the task needs.

## What was exposed

Whatever the agent's GitHub credential could read. In the demonstration the agent used the owner's token, which covered private repositories, and leaked their names and contents, including details of a private project, the owner's relocation plans and salary, into a public pull request anyone could read. The token itself was not disclosed; the problem is that the agent used its full scope on behalf of text written by an attacker. Any secret committed to a private repository the token can reach, such as a `.env` file or a deployment key, is exposed the same way. The researchers call this pattern a "toxic agent flow": untrusted input, access to private data and a way to publish, all in one agent session.

## Who is affected

You are exposed to this pattern if you run an AI agent (Claude Desktop, Cursor, VS Code agents or similar) with a GitHub MCP server or GitHub tools authenticated by a token that can read private repositories **and** you ask it to process content from public repositories, such as issues, pull requests or comments that anyone can write. The researchers stress it is not specific to one agent or client. Review your GitHub audit log and public repositories for pull requests, comments or branches your agent created that contain private information.

## What to do

1. Give agents a fine-grained GitHub personal access token or GitHub App installation limited to the specific repositories the task needs, with read-only permissions where possible, instead of a classic token covering your whole account.
2. Use separate agent sessions or credentials for public-repository triage and for private-repository work, so one session never holds both untrusted input and private access.
3. Require human confirmation before an agent creates pull requests, issues or comments on public repositories.
4. Search your public repositories for agent-created content that includes private data, delete it, and rotate any secret that appeared in it.
5. Monitor agent tool calls; the researchers recommend runtime policies and scanners that restrict an agent to one repository per session.

## Keys to rotate

- [GitHub](https://botpassword.com/keys/github)

## Timeline

- 2025-05-26: Invariant Labs publishes the attack, demonstrated with Claude Desktop, Claude 4 Opus and the official GitHub MCP server. The researchers say it is not a flaw in the GitHub MCP server code and cannot be fixed by a server-side patch alone. ([source](https://invariantlabs.ai/blog/mcp-github-vulnerability))

## Sources

- https://invariantlabs.ai/blog/mcp-github-vulnerability
