sophiacave/mcp-shield

GitHub: sophiacave/mcp-shield

一款用于扫描 MCP 服务器代码安全漏洞的开源静态分析工具,内置 20 条检测规则并提供 A-F 安全评级。

Stars: 0 | Forks: 0

# MCP Shield [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/47fab426db183005.svg)](https://github.com/sophiacave/mcp-shield/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-purple.svg)](https://opensource.org/licenses/MIT) [![Python 3.10+](https://img.shields.io/badge/Python-3.10+-blue.svg)](https://www.python.org/) [![Tests: 28 passing](https://img.shields.io/badge/Tests-28%20passing-green.svg)](tests/) [![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-orange.svg)](https://modelcontextprotocol.io) **用于 MCP 服务器的开源安全扫描器。** 涵盖 6 大类的 20 条规则。几秒钟内扫描任意服务器。获取从 A 到 F 的评级。 ## 快速开始 ``` git clone https://github.com/sophiacave/mcp-shield cd mcp-shield # 扫描文件 python3 src/cli.py scan path/to/mcp_server.py # 扫描项目 python3 src/cli.py scan path/to/mcp-project/ ``` ## 检查内容(20 条规则) | 规则 | 严重程度 | 检测目标 | |------|----------|----------------| | SSRF-01 | Critical | HTTP 请求 URL 中的用户输入 | | SSRF-02 | Medium | 未经验证的动态 URL | | SSRF-03 | Medium | DNS 重绑定(URL 已验证但无 IP 绑定) | | PATH-01 | High | 文件路径中的用户输入 | | PATH-02 | Medium | 无路径遍历保护 | | PATH-03 | Medium | 未检查即跟随 Symlink | | INJ-01 | Critical | 对用户输入使用 eval/exec | | INJ-02 | Critical | SQL 字符串插值 | | INJ-03 | High | subprocess 使用 shell=True | | INJ-04 | High | 通过 .format() 进行模板注入 | | INJ-05 | Critical | 不安全的反序列化(pickle/yaml) | | AUTH-01 | Medium | 工具处理器无身份验证 | | AUTH-02 | Critical | 硬编码的 secrets/API 密钥(OpenAI、Stripe、GitHub、AWS) | | AUTH-03 | Low | 工具 endpoint 无速率限制 | | SEC-01 | High | SSL 验证被禁用 | | SEC-02 | Medium | 通配符 CORS | | SEC-03 | Medium | 向客户端暴露堆栈跟踪/错误详情 | | SEC-04 | Low | 无输入长度验证(DoS 风险) | | LOG-01 | Low | 工具调用无日志/审计跟踪 | ## 测试 ``` python3 tests/test_integration.py # 28 个测试,0 个失败 ``` ## MCP 服务器集成 添加到 `~/.claude/mcp.json`: ``` { "mcpServers": { "mcp-shield": { "command": "python3", "args": ["/path/to/mcp-shield/src/mcp_server.py"] } } } ``` Claude Code 工具:`shield_scan_file`、`shield_scan_directory`、`shield_scan_code` ## 示例输出 ``` MCP Shield: my-server/ — 3 finding(s) [CRIT] SSRF-01: Potential SSRF: Dynamic URL from user input requests call with dynamic URL that may include user input Location: server.py:45 Fix: Validate URL against allowlist. Block internal IPs. CWE: CWE-918 [HIGH] INJ-03: Command injection: subprocess with shell=True subprocess called with shell=True. User input in args = RCE. Location: tools.py:112 Fix: Use subprocess with shell=False and pass args as list. CWE: CWE-78 [MED] AUTH-01: No authentication detected on tool handlers MCP tool handlers found but no auth logic detected Fix: Add authentication middleware. CWE: CWE-306 Grade: F | 1 critical, 1 high, 1 medium ``` ## 功能 - **零依赖** — 纯 Python,无需 pip 安装 - **20 条安全规则** — 涵盖 SSRF、路径遍历、注入、身份验证、配置和日志 - **CWE 参考** — 每个发现都映射到一个通用缺陷枚举(CWE)ID - **可操作的修复建议** — 每个发现都包含具体的补救步骤 - **A-F 评级** — 即时安全态势评估 - **双模式** — 可作为 CLI 或在 Claude Code 内作为 MCP 服务器运行 - **快速** — 不到 1 秒即可扫描典型的 MCP 服务器 ## 诞生背景 MCP 生态系统拥有 9,400 多台服务器和每月 9700 万次 SDK 下载量。但安全工具的发展却未能跟上。我们开发 MCP Shield 是因为,每台未经安全扫描就部署的 MCP 服务器都是一个隐患。 由 [Like One](https://likeone.ai)(一家 501(c)(3) 非营利组织)开发。安全工具应当是免费的。 ## 许可证 MIT — [Like One](https://likeone.ai)
标签:CISA项目, GraphQL安全矩阵, MCP, Python, Web报告查看器, 安全扫描器, 文档结构分析, 无后门, 逆向工具