codesafer
CodeSafer (cleaner-code)
作为模型上下文协议 (MCP) 服务器的 AI 代码安全扫描器。 检测 AI 生成代码中传统代码检查工具(linter)无法发现的隐藏威胁。
网站: codesafer.org · MCP 客户端: Claude Code, Cursor, VS Code + Copilot, Cline
为什么选择 CodeSafer?
AI 编码助手生成代码的速度很快,但谁在检查其中隐藏的威胁呢?
近期的供应链攻击表明,恶意代码可以通过人类审查者和传统代码检查工具经常忽略的方式隐藏:
注入标识符的不可见 Unicode 字符(30 多种变体)
BiDi / 特洛伊源(Trojan Source)攻击,改变代码显示与执行顺序(CVE-2021-42574)
同形异义字(Homoglyphs) — 伪装成拉丁字母的西里尔字母(CVE-2021-42694)
Glassworm 风格的 Unicode 隐写术,将有效载荷隐藏在空白字符中
规则文件后门,植入在
.cursorrules、CLAUDE.md及其他 AI 配置文件中拼写劫持依赖项,存在于
package.json中混淆模式 —
eval+ base64、反向 Shell、打包的有效载荷
CodeSafer 会在代码在您的机器上运行之前扫描所有这些威胁。
Related MCP server: guardvibe
工作原理
CodeSafer 作为本地 MCP 服务器运行。您的 AI 客户端(Claude Code、Cursor 等)在审查或生成代码时会调用其工具,并将发现结果内联返回。
混合检测:
8 个静态分析扫描器 — 针对已知攻击类别的确定性规则(速度快,对所覆盖模式的误报率为零)。
CodeBERT 深度分析 — Transformer 模型以置信度评分将代码块分类为恶意/良性。能够捕获静态规则无法发现的混淆或新型模式。
没有任何内容会离开您的机器。AI 分析在本地针对分词器服务器运行。
功能特性
功能 | 详情 |
不可见字符检测 | 30 多种 Unicode 变体,包括零宽空格、蒙古文元音分隔符 |
BiDi / 特洛伊源 | 完全覆盖 CVE-2021-42574 |
同形异义字检测 | 西里尔/希腊/拉丁字母混淆(CVE-2021-42694) |
Unicode 隐写术 | Glassworm 风格的空白字符有效载荷 |
规则文件后门 | 扫描 |
依赖项扫描 |
|
混淆检测 |
|
AI 深度分析 | 带有置信度评分的 CodeBERT Transformer 分类器 |
MCP 原生 | 6 个 MCP 工具,stdio 传输 |
本地优先 | 无代码上传 — 完全在您的机器上运行 |
MCP 工具
CodeSafer 向您的 MCP 客户端公开了六个工具:
工具 | 用途 |
| 扫描单个文件以查找隐藏的恶意代码模式 |
| 递归扫描目录中的所有源文件 |
| 扫描 AI 配置文件/规则文件,查找提示词注入和规则文件后门攻击 |
| 检查 |
| 使用训练好的 CodeBERT 模型进行深度 AI 分析(将代码块分类为恶意/良性并给出置信度) |
| 获取特定威胁类别的详细解释,包括攻击场景和补救措施 |
安装
先决条件
Node.js 18 或更高版本
支持 MCP 的客户端(Claude Code, Cursor, VS Code + Copilot, Cline)
从源码安装
git clone https://github.com/goldmembrane/cleaner-code.git
cd cleaner-code
npm install
npm run build配置您的 MCP 客户端
Claude Code (~/.claude.json 或项目 .mcp.json):
{
"mcpServers": {
"codesafer": {
"command": "node",
"args": ["/absolute/path/to/cleaner-code/dist/index.js"]
}
}
}Cursor (.cursor/mcp.json):
{
"mcpServers": {
"codesafer": {
"command": "node",
"args": ["/absolute/path/to/cleaner-code/dist/index.js"]
}
}
}重启您的客户端,CodeSafer 工具将出现在工具选择器中。
使用方法
配置完成后,您可以向 AI 客户端询问如下内容:
“扫描此文件以查找隐藏的安全问题。”
“检查 package.json 中的依赖项是否存在拼写劫持。”
“扫描
.cursorrules以查找规则文件后门。”“对
src/auth.ts进行深度 AI 分析。”“解释什么是特洛伊源攻击,以及如何修复上述发现的问题。”
客户端将调用相应的 MCP 工具,并返回包含严重性、行号和补救指导的发现结果。
免费层级与计划
CodeSafer 可免费使用。静态分析(scan_file、scan_directory、scan_rules_file、check_dependencies、explain_finding)没有限制。
AI 深度分析(ai_analyze)包含 每会话 10 次免费运行。更高 AI 配额的付费计划可在 codesafer.org 获取。
检测类别
CodeSafer 检测 9 个类别 的威胁:
不可见 Unicode 字符 — 30 多种变体,包括零宽空格、零宽连接符
BiDi / 特洛伊源攻击 — CVE-2021-42574
同形异义字 — 伪装成拉丁字母的西里尔/希腊字母(CVE-2021-42694)
Unicode 隐写术 — 空白字符中的 Glassworm 模式
规则文件后门 —
.cursorrules、CLAUDE.md等中的恶意指令依赖项风险 — 拼写劫持和可疑安装脚本
混淆模式 —
eval+ base64、打包的有效载荷、反向 Shell静态分析发现 — 8 个确定性扫描器
AI 深度分析 — 用于新型和混淆威胁的 CodeBERT Transformer
项目结构
cleaner-code/
├── src/
│ ├── index.ts # MCP server entry point
│ ├── api-server.ts # Optional HTTP API server
│ ├── types.ts # Scanner interfaces
│ ├── utils.ts # File collection, summary formatting
│ └── scanner/
│ ├── invisible.ts # Invisible Unicode scanner
│ ├── bidi.ts # BiDi / Trojan Source scanner
│ ├── homoglyph.ts # Homoglyph scanner
│ ├── encoding.ts # Encoding / charset scanner
│ ├── obfuscation.ts # Obfuscation pattern scanner
│ ├── steganography.ts # Unicode steganography scanner
│ ├── rules-backdoor.ts # Rules file backdoor scanner
│ ├── dependency.ts # Dependency risk scanner
│ └── ai-analyzer.ts # CodeBERT deep analyzer
├── ml/ # ML model assets and tokenizer
├── functions/ # Cloud function deployments
├── deploy/ # Deployment manifests
└── web/ # Landing page assets许可证
ISC — 详情请参阅 LICENSE 文件。
链接
网站: codesafer.org
模型上下文协议: modelcontextprotocol.io
报告问题: GitHub Issues
Available Tools
6 toolsai_analyzeA
Deep AI analysis of code using the trained CodeBERT model. Classifies code chunks as malicious or benign with confidence scores. Detects obfuscated payloads, novel attack patterns, and threats that static rules may miss.
Inputs: file_path (required).
check_dependenciesB
Check package.json for typosquatting, suspicious install scripts, and dependency risks
Inputs: file_path (required).
explain_findingA
Get detailed explanation of a specific threat category including attack scenarios, real-world examples, and remediation steps
Inputs: category (required).
scan_directoryB
Recursively scan a directory for hidden malicious code patterns across all source files
Inputs: dir_path (required), extensions.
scan_fileB
Scan a single file for hidden malicious code patterns (invisible chars, BiDi, homoglyphs, steganography, obfuscation, etc.)
Inputs: file_path (required).
scan_rules_fileA
Scan an AI configuration/rules file for prompt injection and Rules File Backdoor attacks
Inputs: file_path (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: scan_file vs scan_directory differ by scope, ai_analyze uses ML, check_dependencies focuses on dependencies, and scan_rules_file is for configuration files. No ambiguity.
Tools mostly follow verb_noun snake_case pattern (e.g., scan_file, check_dependencies). The outlier is ai_analyze, which uses a prefix instead of a verb-noun structure, but it's still clear and consistent overall.
With 6 tools covering scanning, AI analysis, dependency checks, and explanations, the count is well-scoped for a focused security analysis server. Not too many or too few.
The tools cover core scanning and analysis tasks well, including file/directory scanning, dependency risks, AI-based analysis, and explanations. A minor gap is the lack of a tool for aggregated reporting or finding management, but the surface is largely complete for detection and explanation.
Maintenance
Related MCP Connectors
Audit your MCP servers for poisoned tools and leaked secrets, and check AI-generated code for flaws.
Zero-config MCP security scanner for AI-generated apps. 25K+ vulnerability patterns.
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
Security scanner for AI agents and MCP servers: injection, jailbreak, tool abuse.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceSecurity scanner for MCP servers and AI-generated code. Detects leaked API keys, PII, prompt injection, and MCP misconfigs with A-F security grades.MIT
- AlicenseBqualityBmaintenanceSecurity MCP server with 300+ rules for AI-generated code. Scans Next.js, Supabase, Clerk, Stripe, Prisma, Hono, GraphQL and 20+ modules. Zero config, runs locally.392,686 npm6Apache 2.0
- AlicenseAqualityBmaintenanceMCP security server for AI coding agents. 12 tools: pre-install guardian, vulnerability audit, supply-chain attack detection via static code analysis, and CycloneDX 1.6 SBOM generation. Zero runtime dependencies.1581 npm15Apache 2.0
- AlicenseNot gradedqualityCmaintenanceScans MCP servers, AI agent skills, and plugins for 68+ malicious patterns including credential exfiltration, prompt injection, and code execution.65 npm5MIT