Skip to content

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

GitHub MCP Security: Interceptor-Based Attack Prevention

This repository provides a complete, tested demonstration of how Docker MCP Gateway interceptors successfully prevent the GitHub MCP Data Heist attack discovered by Invariant Labs.

List of security scripts:

  • cross-repo-blocker.sh implements session locking
  • audit-logger.sh detects sensitive data patterns
  • attack-pattern-detector.sh identifies suspicious tool call sequences

Prerequisites

  • Docker Desktop 4.43.0+ with MCP support
  • GitHub Personal Access Token (create one here)
  • 5 minutes to see security in action

1. Clone and Setup

git clone https://github.com/ajeetraina/github-mcp-security.git
cd github-mcp-security

# Make scripts executable
cd scripts && chmod +x *.sh

# Set your GitHub token
export GITHUB_PERSONAL_ACCESS_TOKEN="your_github_token_here"

2. Test Core Interceptor Logic Locally

# Demonstrate the core security blocking in action
./test-local.sh

** (Real results from our testing):

πŸ§ͺ Testing GitHub MCP Security Interceptors

1️⃣ Testing cross-repo blocking with mock data...
Testing first repository access:
πŸ” Tool: get_file_contents, Repo: testuser/public-repo
πŸ”’ Session locked to repository: testuser/public-repo
Exit code: 0

Testing same repository again:
πŸ” Tool: list_issues, Repo: testuser/public-repo  
Exit code: 0

Testing different repository (should block):
πŸ” Tool: get_file_contents, Repo: testuser/private-repo
🚨 BLOCKING CROSS-REPO ACCESS!
   Session locked to: testuser/public-repo
   Blocked attempt: testuser/private-repo
{
  "content": [
    {
      "text": "πŸ›‘οΈ SECURITY BLOCK: Cross-repository access prevented..."
    }
  ],
  "isError": true
}
Exit code: 0

βœ… Test completed!

🎯 What This Proves:

  • βœ… First repository access: ALLOWED (legitimate use)
  • βœ… Same repository access: ALLOWED (normal workflow)
  • πŸ›‘οΈ Cross-repository attack: BLOCKED (security working!)

3. Full Docker Security Test

# Start the protected MCP Gateway with interceptors
docker compose up mcp-gateway

# In another terminal, simulate the GitHub MCP Data Heist attack
docker compose run test-client

βœ… PROVEN SECURITY RESULTS (Actual output from our system):

🎯 GitHub MCP Horror Story: Attack Simulation
==============================================
πŸ”Œ Connecting to MCP Gateway: http://mcp-gateway:8080/mcp
βœ… Connected to protected MCP Gateway

πŸ›‘οΈ INTERCEPTOR DEMO: Testing Cross-Repository Blocking
============================================================

1️⃣ LOCKING SESSION: Access first repository...
βœ… First repository access: SUCCESS
πŸ”’ Session locked to: ajeetraina/github-mcp-security

2️⃣ 🚨 ATTACK ATTEMPT: Cross-repository data theft...
   πŸ’‰ Simulating prompt injection: 'Access ALL repositories!'
βœ… πŸ›‘οΈ Access blocked by security system!
   πŸ”’ Blocked with: executing interceptor...

3️⃣ 🚨 SECOND ATTACK: Another cross-repo attempt...
βœ… Second attack also blocked - interceptors working!

πŸŽ‰ HORROR STORY PREVENTION DEMO COMPLETE!
==================================================
πŸ“Š SECURITY COMPARISON:
❌ Traditional MCP: Cross-repo access succeeds β†’ Data theft
βœ… Docker MCP Gateway: Cross-repo access blocked β†’ Attack failed
πŸ›‘οΈ Interceptors successfully prevented the GitHub MCP Data Heist!

🎯 PROVEN: Attack Prevention Results

Traditional MCP (Vulnerable):

1. AI reads malicious GitHub issue βœ…
2. Gets prompt injected βœ…  
3. Accesses private repositories βœ… ← CATASTROPHIC FAILURE
4. Exfiltrates salary data βœ…     ← DATA STOLEN
5. Publishes to public repo βœ…    ← BREACH COMPLETE
Result: Complete data breach πŸ’₯

Our Docker MCP Gateway (Protected):

1. AI reads malicious GitHub issue βœ…
2. Gets prompt injected βœ…
3. Attempts private repo access ❌ ← πŸ›‘οΈ BLOCKED BY INTERCEPTOR
Result: Attack neutralized, data protected βœ…

πŸ” Technical: How the Interceptors Work

Core Protection: Cross-Repository Blocker (cross-repo-blocker.sh)

# Simple, reliable JSON parsing (no dependencies)
repo=$(echo "$input" | grep -o '"repo":"[^"]*"' | cut -d'"' -f4)
owner=$(echo "$input" | grep -o '"owner":"[^"]*"' | cut -d'"' -f4)

# Session-based protection
repo_id="${owner}/${repo}"
if [[ "$repo_id" != "$locked_repo" ]]; then
    echo "🚨 BLOCKING CROSS-REPO ACCESS!" >&2
    # Return security error that blocks the attack
    cat << 'JSON'
{
  "content": [{"text": "πŸ›‘οΈ SECURITY BLOCK: Cross-repository access prevented"}],
  "isError": true
}
JSON
    exit 0
fi

Advanced Protection: Sensitive Data Filter (sensitive-data-filter.sh)

# Scan for sensitive data patterns in any response
if echo "$RESPONSE_TEXT" | grep -qiE '(salary|compensation|\$[0-9]{4,}|confidential|secret|internal)'; then
    echo "🚨 BLOCKED: Sensitive data pattern detected in response" >&2
    # Return filtered response
    cat << 'JSON'
{
  "content": [{"text": "πŸ›‘οΈ RESPONSE FILTERED: Sensitive data detected and blocked"}],
  "isError": false
}
JSON
    exit 0
fi

Behavioral Analysis: Attack Pattern Detector (attack-pattern-detector.sh)

# Pattern 1: Issue reading followed by repository enumeration
if echo "$RECENT_CALLS" | grep -q "list_issues" && [[ "$tool_name" == "get_repositories" ]]; then
    echo "🚨 ATTACK PATTERN DETECTED: Issue reading β†’ Repository enumeration" >&2
    echo "This matches the Invariant Labs attack pattern!" >&2
    # Block the suspicious sequence
fi

Content Analysis: Sequence Analyzer (sequence-analyzer.sh)

# Look for prompt injection indicators from the Invariant Labs attack
if echo "$RESPONSE_TEXT" | grep -qiE '(read.*README.*all.*repos|add.*chapter.*author|does not care about privacy)'; then
    echo "🚨 PROMPT INJECTION DETECTED in issue content!" >&2
    # Return sanitized response
fi

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages