Introduction
The Secure MCP Gateway implements a comprehensive security architecture designed to protect Model Context Protocol (MCP) communications from a wide range of threats. This page provides an overview of the security model, architecture, and protection mechanisms.Security-First Design: The gateway acts as a security layer between MCP clients (like Claude Desktop, Cursor) and MCP servers, enforcing authentication, authorization, and guardrails on all communications.
Threat Model
The Secure MCP Gateway protects against the following threat categories:Critical Threats (Rank 1-4)
Prompt Injection
Prompt Injection
Risk Level: Critical (Rank #1)Attackers attempt to manipulate AI behavior by injecting malicious instructions through:
- Tool descriptions containing hidden commands
- Server metadata with instruction overrides
- User data embedding system prompts
- Document content with context hijacking
Command Injection
Command Injection
Risk Level: Critical (Rank #2)Exploitation of OS command execution through:
- Unsanitized parameters passed to shell commands
- File paths with embedded shell metacharacters
- Tool arguments containing command separators
Remote Code Execution (RCE)
Remote Code Execution (RCE)
Risk Level: Critical (Rank #4)Direct code execution in application runtime via:
- Unsafe deserialization (pickle, YAML, JSON)
- Template injection (Jinja2, Twig)
- Dynamic code evaluation (eval, exec)
High-Risk Threats (Rank 5-10)
Credential Theft
Unauthorized access to:
- Environment variables with secrets
- Configuration files with API keys
- Authentication tokens and sessions
Path Traversal
Directory traversal attacks:
- Reading arbitrary files (../../etc/passwd)
- Writing to restricted locations
- Zip slip vulnerabilities
Server-Side Request Forgery
Unauthorized network access:
- Internal network scanning
- Cloud metadata service access
- Bypassing network restrictions
Resource Exhaustion
Denial of service through:
- Infinite loops and CPU exhaustion
- Memory bombs and allocation attacks
- Disk space consumption
Security Architecture
Multi-Layer Defense
The gateway implements defense-in-depth with multiple security layers:Security Components
Authentication Layer
API Key Validation: Every request requires a valid gateway API key
- Key-based authentication with project/user context
- Secure key generation (256-character random strings)
- Key rotation and management capabilities
Server Registration Validation
Tool Discovery Protection: Validates MCP servers during discovery
- Server metadata scanning for malicious patterns
- Tool description analysis for injection attempts
- Destructive/OpenWorld hint enforcement
Input Guardrails
Pre-Execution Protection: Validates requests before sending to servers
- Content analysis for threats and policy violations
- PII detection and automatic redaction
- Injection attack prevention
Protection Mechanisms
1. Guardrail System
The guardrail system provides real-time threat detection and prevention:2. Authentication & Authorization
API Key Management:- Unique keys per user-project combination
- Automatic generation with high entropy
- Secure storage and retrieval
- Rotation capabilities
- Separate admin API key (256-char random)
- Bearer token authentication for REST API
- CORS configuration for web access
3. Sensitive Data Protection
- Environment Variables
- HTTP Headers
- Cache Keys
Auto-Masking: Sensitive environment variables are automatically masked in logs
4. Timeout Management
Operation Timeouts: Prevents resource exhaustion attacks| Operation Type | Default Timeout | Purpose |
|---|---|---|
| Guardrail Validation | 15s | Prevent DoS via guardrail API |
| Tool Execution | 60s | Limit long-running tools |
| Discovery | 20s | Bound server discovery time |
| Authentication | 10s | Fast-fail auth checks |
| Cache Operations | 5s | Quick cache access |
- Warn at 80% of timeout
- Hard timeout at 100%
- Failure at 120% (grace period)
Fail-Safe Defaults
Fail-Closed Scenarios
- Guardrail API Errors: If guardrail validation fails due to API errors or timeouts, block the request
- Tool Registration Errors: If tool validation encounters errors, prevent tool registration
- Authentication Failures: If auth validation fails, reject the request
- Unauthorized Access: If API key validation fails with auth errors, block access
Fail-Open Scenarios
- Discovery Errors (non-guardrail): Allow server discovery if not using tool guardrails
- Cache Failures: Fall back to direct queries if cache is unavailable
- Telemetry Errors: Continue operation if logging/tracing fails
Security Best Practices
For Gateway Administrators
For Gateway Administrators
- Use Strong API Keys: Generate keys with high entropy (use built-in generator)
- Enable Guardrails: Always enable guardrails for external/untrusted MCP servers
- Configure Block Lists: Customize block lists based on your threat model
- Monitor Metrics: Track guardrail blocks and violations in Grafana
- Rotate Keys Regularly: Use
secure-mcp-gateway apikey rotateperiodically - Review Logs: Check structured logs for security events
- Use External Cache: Deploy Redis/KeyDB for multi-instance setups
- Backup Configs: Regular backups with
secure-mcp-gateway system backup
For MCP Server Developers
For MCP Server Developers
- Clear Tool Descriptions: Write accurate descriptions without promotional language
- Set Proper Annotations:
destructiveHint: truefor any tool that modifies statereadOnlyHint: trueonly for truly read-only operationsopenWorldHint: trueif tool accesses external networks
- Validate Inputs: Always validate and sanitize tool parameters
- Avoid Dangerous Patterns: Don’t use eval, exec, pickle, or shell commands
- Least Privilege: Request minimum necessary permissions
- Document Security: Clearly document any security considerations
For End Users
For End Users
- Trust But Verify: Review MCP servers before adding to gateway
- Check Tool Descriptions: Look for suspicious or vague descriptions
- Review Permissions: Understand what destructive/openWorld tools do
- Report Issues: Report suspicious servers to gateway administrators
- Use Separate Projects: Isolate high-risk servers in dedicated projects
Security Metrics & Monitoring
Key Metrics
Guardrail Performance:guardrail_blocks_total- Total requests blocked by guardrailsguardrail_violations_by_type- Violations by type (injection, PII, etc.)guardrail_latency_ms- Guardrail evaluation timepii_redactions_total- PII redaction operations
auth_failures_total- Failed authentication attemptsauth_latency_ms- Authentication check durationactive_api_keys- Number of active keys
tool_registrations_blocked- Tools blocked during discoveryserver_registrations_blocked- Servers blocked during validationdestructive_tools_executed- Destructive tool invocations
Grafana Dashboards
The gateway includes pre-built Grafana dashboards for security monitoring:- Security Overview: High-level security posture
- Guardrail Performance: Detailed guardrail metrics
- Threat Detection: Real-time threat indicators
- Audit Trail: Complete request/response audit log
Next Steps
Guardrail Types
Explore all guardrail types and detection mechanisms
PII Handling
Learn about PII detection, redaction, and de-anonymization
Security Testing
Test your security posture with bad_mcps attack scenarios
Configuration
Configure guardrails for your MCP servers
Resources
MCP Security Top 25
Adversa.ai vulnerability ranking
JFrog RCE Research
MCP command injection vulnerability
Enkrypt Blog
How the Gateway prevents top attacks