How do you safely give an AI agent a GitHub token?
Make the token fine-grained: one repo the agent works on, read-only by default, with an expiration date. Invariant Labs showed a prompt injection in a public GitHub issue that led an agent to pull private repo data into a public pull request. When the token can reach every repo, the injection can too.
The breakdown
The one rule
Before anyone on your team gives an AI agent a GitHub token, make it a fine-grained personal access token. Limit it to the one repository the agent works on, keep permissions read-only by default, and set an expiration date. GitHub's docs say you should choose the minimal repository access that meets your needs.
What researchers showed
In May 2025, Invariant Labs described an attack on a GitHub MCP setup. An attacker put a prompt injection in an issue on a public repo. The user asked their agent to look at the open issues. The agent read the issue, pulled data from the user's private repos, and posted it in a pull request on the public repo.
Why the token was the blast radius
The token could reach every repo, so the injected instruction could too. Invariant's first mitigation is least privilege: limit agent access to only the repositories it needs to interact with. That is the same rule as the fine-grained token form above.
What this is not claiming
Invariant frames this as an architectural issue with how agents use MCP and tokens, not as a bug in a specific GitHub MCP server binary. The on-screen issue in the clip is a labeled re-creation, not the real payload text.
Check tonight
Open the token your agent uses. Can it see more than one repo? Does it have write access it does not need? Does it expire? If the answer to any of those is wrong, replace it before the next run.
The question at the end of the video: Does your agent's GitHub token expire?
Sources
- Invariant Labs: GitHub MCP Exploited (May 26, 2025)
- GitHub docs: Managing your personal access tokens (fine-grained)
FAQ
What settings should an AI agent's GitHub token use?
Fine-grained access, limited to the one repository the agent needs, read-only by default, with an expiration date. GitHub's fine-grained token docs say to choose the minimal repository access that meets your needs.
How did a public GitHub issue leak private repos through an agent?
Per Invariant Labs (May 2025), a prompt injection in a public issue led an agent that was asked to review open issues to pull private repo data into context and publish it in a public pull request.
Is this a bug in GitHub's MCP server?
Invariant describes it as an architectural issue with agent access and prompt injection, not as a bug in a specific server binary. The fix they lead with is least privilege on which repos the agent can reach.
Does a fine-grained GitHub token stop prompt injection?
No. It shrinks what a successful injection can reach. Pair it with policy and human approval for anything destructive, and never give the agent a personal token that can see every repo you own.
































