Github MCP Attacks

A security team (Invariant Labs) discovered a critical vulnerability in the GitHub MCP integration used by AI coding agents (like Claude 4, ChatGPT, etc.). This flaw allows attackers to trick an AI agent into leaking private code by using a fake GitHub issue in a public repository.


⚙️ How It Works — In Simple Steps

  1. User Setup:

    • You have a public GitHub repo (anyone can submit issues).

    • You also have a private repo (contains sensitive code).

  2. Attacker Action:

    • Creates a fake issue in the public repo containing hidden instructions (prompt injection).

  3. User Request:

    • User asks the agent:"Can you check open issues in my public repo?"

  4. Agent Behavior:

    • Agent reads the issue and unknowingly follows the malicious instructions.

  5. Data Leak:

    • Agent fetches data from the private repo and unintentionally posts it publicly (e.g., via a pull request).


💥 Why This Happens

  • AI agents can be manipulated via prompt injections.

  • Agents trust external inputs (like GitHub issues).

  • Automated tool usage — users often don’t approve each step.

  • No system-level boundary to stop cross-repo data flow.


🔓 What Makes It Exploitable

  • Public GitHub issues = untrusted input.

  • Agent uses GitHub MCP = reads and acts on those issues.

  • "Always allow" mode = no human confirmation.

  • Agent has access to both public and private repos.

  • No policy restrictions on multi-repo access.


🔐 What Makes It Non-Exploitable

  • Require manual approval for every agent action.

  • Restrict access to one repo per session.

  • Use Guardrails or other runtime permission controls.

  • Implement real-time monitoring with a security scanner.


⚠️ Risks

  • Leakage of private source code or IP.

  • Exposure of confidential business plans, salary data, internal tools.

  • Loss of trust in AI-powered developer tools.

  • Risk of supply chain attacks on codebases.

  • Widespread threat as more developers adopt coding agents.


🧬 Can It Be Scaled?

Yes. The attack is highly scalable:

  • Any GitHub user with public + private repos is vulnerable.

  • Any AI coding agent using GitHub MCP is a target.

  • Can be automated to attack many users at once.


🧑‍💼 Leadership Takeaways

  • AI systems can be tricked — even aligned models are vulnerable.

  • The core issue is architectural, not just about bad actors or bugs.

  • Organizations need proactive security tooling, not reactive fixes.

  • Securing agent environments must be a core engineering concern.

  • Embrace least privilege and runtime monitoring.


✅ How to Fix It — Mitigation Summary

1. Enforce One-Repo Rule

Limit agents to one repo per session using dynamic rules:

raise Violation("You can access only one repo per session.") if: (
    call_before.function.arguments["repo"] != call_after.function.arguments["repo"]
)

2. Use Guardrails

Tools like Invariant Guardrails allow you to:

  • Set custom access rules.

  • Prevent cross-repo data leaks.


3. Real-Time Monitoring

Use tools like MCP-scan in proxy mode to:

  • Audit all agent activity.

  • Catch data leaks in real time.

  • Create alerts or block unsafe actions.


📊 Agent Attack Flow

Here’s a plaintext flowchart you can draw or diagram:

User → Public GitHub Repo 

Attacker adds malicious Issue 

Agent queries issues → Gets injected prompt 

Agent accesses Private Repo (unauthorized) 

Agent posts data in Public Repo (via PR) 

Attacker downloads leaked data

✍️ Final Summary

As AI agents get deeply integrated into developer workflows, new classes of vulnerabilities are emerging—like prompt-based attacks on GitHub MCP. This post breaks down how a simple GitHub issue can hijack an AI assistant and leak private code.

We show:

  • How the attack works

  • Why it’s possible

  • What risks it poses

  • What leaders and devs must do

Spoiler: It’s not just about making AI safer. It’s about rearchitecting the system for security.

Last updated