MCP要塞
用于AI代理MCP(模型上下文协议)的生产级安全防火墙和代理
  
第一个开源MCP安全层,结合了行为异常检测、加密工具完整性验证、爆炸半径估计和跨会话威胁相关性,于2026年为实际现场使用而构建。
______________________________________________________________________
为什么选择MCP堡垒?
MCP生态系统在2025-2026年爆发。袭击也是如此:
- 82% 的MCP实现存在路径遍历漏洞 *(安全研究人员,2026年)*
- 36.7% 在7000多台受访的MCP服务器中,有一台易受SSRF攻击 *(蓝石安保,2026年)*
- 30个CVE 在短短60天内对MCP基础设施提起诉讼 *(2026年1月至2月)*
- 工具中毒、及时注射、证书泄露——均在生产中得到确认
现有网关包括路由、身份验证和速率限制。 MCP Fortress填补了他们留下的安全漏洞:
| 能力 | 其他网关 | MCP堡垒 |
|---|---|---|
| OAuth/API密钥验证 | 是 | 是 |
| 速率限制 | 是 | 是 |
| 工具描述完整性(加密+语义) | 否 | 是 |
| 行为异常检测(序列分析) | 否 | 是 |
| 爆破半径执行前评分0-100 | 否 | 是 |
| 跨会话威胁相关性 | 否 | 是 |
| 策略即代码防火墙(零云依赖) | 否 | 是 |
| 装载时自动检测工具中毒 | 否 | 是 |
| PII和秘密扫描仪(输入+输出) | 否 | 是 |
| 零外部依赖(stdlib核心) | 否 | 是 |
______________________________________________________________________
核心安全模块
1.工具描述完整性验证器(TDIV)
检测工具中毒-2026年的#1 MCP攻击向量。
- 注册时对工具清单进行加密HMAC-SHA256签名
- 检测描述中隐藏的不可见/零宽度Unicode字符
- 语义漂移检测:当工具描述获得危险的新功能时进行标记
- 阴影工具检测:通过Levenshtein距离分析进行打字
- Rug-pull检测:当受信任的工具静默更新其模式时发出警报
2.行为异常检测器(BAD引擎)
通过呼叫序列分析检测受感染的代理。
- 10种内置攻击模式:渗透、枚举、证书获取、外壳注入等。
- 速度检测:呼叫/分钟和突发/秒阈值
- 枚举然后销毁模式检测
- 每次会话风险评分(0.0-1.0),带自动标记
3.爆炸半径估计器(BRE)
答案:“如果这个电话是恶意的,损害有多严重?”
- 在执行前对每个工具调用进行0-100的评分
- 8个风险因素:破坏性、数据范围、可逆性、外部网络、敏感路径、参数、URL、会话历史
- 可配置:AUTO_ALLOW、REQUIR_HUMAN_APPROVAL、BLOCK
4.跨会话威胁相关器(CSTC)
检测跨多个代理会话的协同攻击。
- IP群集:来自同一源的多个会话
- 缓慢的烧伤渗出:阅读分布在许多短时间内
- 全球警报率峰值检测(广泛的扫描活动)
5.作为代码防火墙的策略
带有热重载的声明性YAML安全规则。
rules:
- name: "block_path_traversal"
match: {arg_pattern: '\.\./'}
action: BLOCK
- name: "require_approval_shell"
match: {tool_class: "shell_exec"}
action: REQUIRE_APPROVAL
- name: "allow_workspace_reads"
match: {tool: "read_file", arg_pattern: "^/workspace/"}
action: ALLOW6.个人身份信息和秘密扫描仪
扫描输入和输出中的22多种秘密模式,包括AWS、OpenAI、Anthropic、GitHub、Stripe、Slack、Twilio、SendGrid密钥、JWT令牌、私钥、信用卡和SSNs。可配置的编辑、阻止或警报操作。
______________________________________________________________________
建筑
AI Agent (Claude / GPT / Cursor)
| MCP JSON-RPC
v
+-------------------------------+
| MCP-Fortress Proxy |
| |
| [1] Policy Firewall | <- YAML rules, hot-reload
| [2] PII Scanner (inputs) | <- 22+ secret patterns
| [3] BAD Engine | <- sequence anomaly detection
| [4] Blast Radius Estimator | <- 0-100 pre-exec scoring
| [5] Cross-Session Correlator | <- coordinated attack detection
| [6] PII Scanner (outputs) | <- redact before returning
| |
| Dashboard /dashboard | <- real-time web UI
| Approval /api/v1/approve | <- human-in-the-loop
+-------------------------------+
| (if ALLOW)
v
Upstream MCP Server______________________________________________________________________
快速开始
pip install mcp-fortress在30秒内包装任何MCP服务器:
mcp-fortress proxy \
--upstream "http://localhost:3000" \
--policy examples/policy_enterprise.yaml \
--port 8100打开实时仪表板http://localhost:8100/dashboard
无需服务器即可保护Claude Desktop或Cursor:
{
"mcpServers": {
"filesystem-protected": {
"command": "mcp-fortress-stdio",
"args": [
"--policy", "/path/to/policy_developer.yaml",
"--",
"npx", "-y", "@modelcontextprotocol/server-filesystem", "."
]
}
}
}扫描MCP服务器是否存在漏洞:
mcp-fortress scan --target http://localhost:3000 --report report.html______________________________________________________________________
安装
# Core (zero external dependencies)
pip install mcp-fortress
# With HTTP proxy and dashboard
pip install mcp-fortress[proxy,yaml]
# Full install
pip install mcp-fortress[all]Docker:
docker run -p 8100:8100 \
-v $(pwd)/examples/policy_enterprise.yaml:/app/config/policy.yaml \
-e UPSTREAM_MCP_URL=http://your-mcp-server:3000 \
ghcr.io/Avoceous/mcp-fortress:latest______________________________________________________________________
OWASP MCP十大覆盖范围
| OWASP MCP风险 | MCP堡垒模块 |
|---|---|
| MCP-01:提示注入 | 坏引擎+策略防火墙 |
| MCP-02:工具中毒 | TDIV(全覆盖) |
| MCP-03:权限过大 | 爆炸半径估算器 |
| MCP-04:不安全认证 | API密钥+JWT中间件 |
| MCP-05:供应链风险 | TDIV模式签名 |
| MCP-06:日志记录不足 | 完整的JSONL审计跟踪 |
| MCP-07:影子MCP服务器 | TDIV漂移+影子检测 |
| MCP-08:上下文操纵 | 跨会话相关器 |
| MCP-09:范围蠕变 | 政策作为规范执行 |
| MCP-10:指令注射 | 精氨酸消毒+模式规则 |
______________________________________________________________________
项目结构
mcp-fortress/
├── mcpshield/
│ ├── core/
│ │ ├── models.py <- Data types: ToolCall, SecurityDecision, Alert
│ │ └── pipeline.py <- Unified 6-stage security pipeline
│ ├── detectors/
│ │ ├── tdiv.py <- Tool Description Integrity Verifier
│ │ ├── bad_engine.py <- Behavioral Anomaly Detector
│ │ ├── blast_radius.py <- Blast Radius Estimator
│ │ ├── pii_scanner.py <- PII and Secret Scanner
│ │ └── correlator.py <- Cross-Session Correlator
│ ├── policy/
│ │ └── firewall.py <- Policy-as-Code Firewall
│ ├── transport/
│ │ ├── proxy.py <- HTTP/SSE Proxy (FastAPI)
│ │ ├── stdio_proxy.py <- stdio Proxy (Claude Desktop / Cursor)
│ │ └── dashboard.html <- Real-time security dashboard
│ └── cli/
│ ├── main.py <- CLI: proxy, scan, verify, report
│ └── scanner.py <- Active vulnerability scanner
├── tests/
│ └── test_all.py <- 40 tests across all modules
├── examples/
│ ├── policy_enterprise.yaml <- 15-rule enterprise policy
│ └── policy_developer.yaml <- Lightweight developer policy
├── docs/
│ └── developer_guide.md <- Full API reference and Kubernetes guide
├── scripts/
│ └── setup_github.sh <- One-command GitHub publish
├── Dockerfile
├── docker-compose.yml
└── pyproject.toml______________________________________________________________________
配置
# mcp-fortress.yaml
mcpshield:
proxy:
host: "0.0.0.0"
port: 8100
upstream: "http://localhost:3000"
integrity:
enabled: true
signing_key_env: "MCP_FORTRESS_SIGNING_KEY"
behavioral:
enabled: true
max_calls_per_minute: 60
blast_radius:
enabled: true
auto_allow_threshold: 20
approval_threshold: 60
block_threshold: 90
pii_scanner:
enabled: true
action: "redact"
audit:
enabled: true
log_file: "mcp_fortress_audit.jsonl"______________________________________________________________________
贡献
欢迎捐款。看 贡献.md.
______________________________________________________________________
安全披露
发现漏洞?请使用 私下披露 不要公开问题。
______________________________________________________________________
许可证
MIT许可证-请参阅 许可证 了解详情。
______________________________________________________________________
作者
w1boost1889M —
*旨在保护AI代理及其服务的客户。*
