Skip to main content
Glama

CodeSafer (cleaner-code)

Model Context Protocol (MCP) サーバーとして動作するAIコードセキュリティスキャナー。 従来のリンターでは見逃される、AI生成コード内の隠れた脅威を検出します。

npm license: ISC Node

ウェブサイト: codesafer.org  ·  MCPクライアント: Claude Code, Cursor, VS Code + Copilot, Cline


CodeSaferを選ぶ理由

AIコーディングアシスタントは高速にコードを生成しますが、その中に隠れた脅威がないか誰がチェックしているのでしょうか?

近年のサプライチェーン攻撃では、人間のレビューアや従来のリンターが日常的に見逃してしまうような方法で悪意のあるコードが隠されることが明らかになっています:

  • 不可視のUnicode文字:識別子に注入される(30種類以上)

  • BiDi / Trojan Source攻撃:コードの表示順序と実行順序を入れ替える(CVE-2021-42574)

  • ホモグラフ:ラテン文字になりすましたキリル文字など(CVE-2021-42694)

  • Glassworm形式のUnicodeステガノグラフィ:空白文字にペイロードを隠蔽

  • ルールファイルのバックドア:.cursorrules、CLAUDE.md、その他のAI設定ファイルに仕込まれる

  • タイポスクワッティングされた依存関係:package.json内

  • 難読化パターン:eval + base64、リバースシェル、パックされたペイロード

CodeSaferは、コードがマシン上で実行される前に、これらすべてをスキャンします。


Related MCP server: guardvibe

仕組み

CodeSaferはローカルのMCPサーバーとして動作します。AIクライアント(Claude Code、Cursorなど)がコードのレビューや生成を行う際にツールを呼び出し、結果がインラインで返されます。

ハイブリッド検出:

  1. 8つの静的解析スキャナー — 既知の攻撃カテゴリに対する決定論的なルール(高速で、対象パターンに対する偽陰性はゼロ)。

  2. CodeBERTディープ解析 — トランスフォーマーモデルがコードチャンクを悪意のあるものか良性のものか、信頼スコア付きで分類。静的ルールでは見逃される難読化されたパターンや新しいパターンを捕捉します。

データがマシンから外部へ送信されることはありません。AI解析はローカルのトークナイザーサーバーに対して実行されます。


機能

機能

詳細

不可視文字検出

ゼロ幅スペース、モンゴル語母音分離記号を含む30以上のUnicodeバリアント

BiDi / Trojan Source

CVE-2021-42574を完全網羅

ホモグラフ検出

キリル文字/ギリシャ文字/ラテン文字の混同(CVE-2021-42694)

Unicodeステガノグラフィ

Glassworm形式の空白文字ペイロード

ルールファイルのバックドア

.cursorrules、CLAUDE.md、.claude/、Cursorルールをスキャン

依存関係スキャン

package.json内のタイポスクワッティングと不審なインストールスクリプト

難読化検出

eval + base64、リバースシェル、パックされたペイロード

AIディープ解析

信頼スコア付きのCodeBERTトランスフォーマー分類器

MCPネイティブ

6つのMCPツール、stdioトランスポート

ローカルファースト

コードのアップロードなし — すべてマシン上で実行


MCPツール

CodeSaferはMCPクライアントに対して6つのツールを提供します:

ツール

目的

scan_file

単一ファイルをスキャンして隠れた悪意のあるコードパターンを検出

scan_directory

ディレクトリ内のすべてのソースファイルを再帰的にスキャン

scan_rules_file

AI設定/ルールファイルをスキャンしてプロンプトインジェクションやルールファイルバックドア攻撃を検出

check_dependencies

package.jsonのタイポスクワッティング、不審なインストールスクリプト、依存関係のリスクをチェック

ai_analyze

学習済みCodeBERTモデルを使用したAIディープ解析(チャンクを悪意/良性に分類し信頼スコアを算出)

explain_finding

特定の脅威カテゴリの詳細な説明、攻撃シナリオ、修正方法を取得


インストール

前提条件

  • 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ディープ解析を実行して。"

  • "Trojan Source攻撃とは何か、そして上記の検出結果をどう修正すればよいか説明して。"

クライアントは適切なMCPツールを呼び出し、重大度、行番号、修正ガイダンスを含む結果を返します。


無料枠とプラン

CodeSaferは無料で使用できます。静的解析(scan_file、scan_directory、scan_rules_file、check_dependencies、explain_finding)には制限がありません。

AIディープ解析(ai_analyze)には、セッションごとに10回の無料実行枠が含まれています。より高いAIクォータが必要な場合は、codesafer.orgで有料プランをご利用いただけます。


検出カテゴリ

CodeSaferは9つのカテゴリにわたる脅威を検出します:

  1. 不可視のUnicode文字 — ゼロ幅スペース、ゼロ幅結合子など30以上のバリアント

  2. BiDi / Trojan Source攻撃 — CVE-2021-42574

  3. ホモグラフ — ラテン文字になりすましたキリル文字/ギリシャ文字(CVE-2021-42694)

  4. Unicodeステガノグラフィ — 空白文字内のGlasswormパターン

  5. ルールファイルのバックドア — .cursorrules、CLAUDE.md等に含まれる悪意のある指示

  6. 依存関係のリスク — タイポスクワッティングおよび不審なインストールスクリプト

  7. 難読化パターン — eval + base64、パックされたペイロード、リバースシェル

  8. 静的解析結果 — 8つの決定論的スキャナー

  9. AIディープ解析 — 新規および難読化された脅威に対するCodeBERTトランスフォーマー


プロジェクト構造

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 ファイルを参照してください。


リンク

Available Tools

6 tools
ai_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

    A3.7/5.0

    Scored across 6 tools

    Disambiguation5/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      Security 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.
      39
      2,686 npm
      6
      Apache 2.0
    • A
      license
      A
      quality
      B
      maintenance
      MCP 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.
      15
      81 npm
      15
      Apache 2.0