From 34b2ca720079ffd3cd15e6632d41146a1639819e Mon Sep 17 00:00:00 2001 From: Florian BRUNIAUX Date: Thu, 15 Jan 2026 07:39:53 +0100 Subject: [PATCH] feat(security): add security hardening guide and hooks v3.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add guide/security-hardening.md (~10K) covering: - MCP vetting workflow with CVE-2025-53109/53110, 54135, 54136 - Prompt injection evasion techniques (Unicode, ANSI, null bytes) - Secret detection tool comparison (Gitleaks, TruffleHog, GitGuardian) - Incident response procedures - Add 3 new security hooks: - unicode-injection-scanner.sh: zero-width, RTL, ANSI escape detection - repo-integrity-scanner.sh: scan README/package.json for injection - mcp-config-integrity.sh: verify MCP config hash - Update existing hooks: - prompt-injection-detector.sh: +ANSI, +null bytes, +nested cmd - output-secrets-scanner.sh: +env leakage, +generic tokens - Update cross-references in ultimate-guide.md (§7.4, §8.6) - Move MCP Security Hardening to Done in IDEAS.md Co-Authored-By: Claude Opus 4.5 --- IDEAS.md | 30 +- README.md | 7 +- examples/README.md | 8 +- examples/hooks/README.md | 6 +- examples/hooks/bash/mcp-config-integrity.sh | 118 +++++ examples/hooks/bash/output-secrets-scanner.sh | 11 +- .../hooks/bash/prompt-injection-detector.sh | 32 ++ examples/hooks/bash/repo-integrity-scanner.sh | 215 +++++++++ .../hooks/bash/unicode-injection-scanner.sh | 141 ++++++ guide/cheatsheet.md | 2 +- guide/security-hardening.md | 434 ++++++++++++++++++ guide/ultimate-guide.md | 4 + 12 files changed, 986 insertions(+), 22 deletions(-) create mode 100755 examples/hooks/bash/mcp-config-integrity.sh create mode 100755 examples/hooks/bash/repo-integrity-scanner.sh create mode 100755 examples/hooks/bash/unicode-injection-scanner.sh create mode 100644 guide/security-hardening.md diff --git a/IDEAS.md b/IDEAS.md index ab994fe..ec02dc9 100644 --- a/IDEAS.md +++ b/IDEAS.md @@ -2,25 +2,25 @@ > Research topics for future guide improvements. Curated and validated. -## High Priority +## Done -### MCP Security Hardening +### MCP Security Hardening ✅ Unified security research covering MCP vulnerabilities, prompt injection, and secret detection. -**Topics:** -- Real-world Tool Shadowing and Confused Deputy incidents -- Prompt injection bypass techniques (Unicode, encoding, obfuscation) -- Secret detection regex patterns (compare GitHub, Gitleaks, TruffleHog) -- Supply chain risks in MCP server ecosystem +**Completed**: [Security Hardening Guide](./guide/security-hardening.md) covers: +- CVE-2025-53109/53110, 54135, 54136 with mitigations +- MCP vetting workflow with 5-minute audit checklist +- MCP Safe List (community vetted) +- Prompt injection evasion techniques (Unicode, ANSI, null bytes) +- Secret detection tool comparison (Gitleaks, TruffleHog, GitGuardian) +- Incident response procedures (secret exposed, MCP compromised) +- 3 new hooks: `unicode-injection-scanner.sh`, `repo-integrity-scanner.sh`, `mcp-config-integrity.sh` -**Perplexity Query:** -``` -MCP Model Context Protocol security vulnerabilities 2024-2025: -- Tool shadowing attacks -- Prompt injection bypass techniques for coding assistants -- Secret detection regex patterns comparison (GitHub vs Gitleaks vs TruffleHog) -Include real incidents if documented. -``` +--- + +## High Priority + +*(No items currently)* --- diff --git a/README.md b/README.md index 10570bd..b3f178b 100644 --- a/README.md +++ b/README.md @@ -405,11 +405,14 @@ Copy-paste templates from [`examples/`](./examples/) for immediate use: |------|-------|---------| | [dangerous-actions-blocker.sh](./examples/hooks/bash/dangerous-actions-blocker.sh) | PreToolUse | Block `rm -rf /`, force push, secrets | | [prompt-injection-detector.sh](./examples/hooks/bash/prompt-injection-detector.sh) | PreToolUse | Detect injection attempts | +| [unicode-injection-scanner.sh](./examples/hooks/bash/unicode-injection-scanner.sh) | PreToolUse | Detect zero-width, RTL, ANSI escape | +| [repo-integrity-scanner.sh](./examples/hooks/bash/repo-integrity-scanner.sh) | PreToolUse | Scan README/package.json for injection | +| [mcp-config-integrity.sh](./examples/hooks/bash/mcp-config-integrity.sh) | SessionStart | Verify MCP config hash (CVE protection) | | [output-secrets-scanner.sh](./examples/hooks/bash/output-secrets-scanner.sh) | PostToolUse | Detect exposed secrets | | [notification.sh](./examples/hooks/bash/notification.sh) | Notification | macOS sound alerts | | [auto-format.sh](./examples/hooks/bash/auto-format.sh) | PostToolUse | Auto-format with Prettier | -**[See All 11 Hooks](./examples/hooks/)** — Includes session-logger, security-check, claudemd-scanner, and more +**[See All 14 Hooks](./examples/hooks/)** — Includes session-logger, security-check, claudemd-scanner, and more ### GitHub Actions (CI/CD) @@ -554,7 +557,7 @@ If this guide saved you time, helped you master Claude Code, or inspired your wo --- -*Version 3.5.0 | January 2026 | Crafted with Claude* +*Version 3.6.0 | January 2026 | Crafted with Claude* '; then + echo "BLOCKED: Hidden HTML comment with suspicious instructions in: $file" >&2 + return 1 + fi + + # === ROLE OVERRIDE PATTERNS === + if echo "$content" | grep -qiE 'ignore (previous|all|your) instructions|you are now|pretend (you are|to be)|from now on|new instructions:'; then + echo "BLOCKED: Prompt injection pattern detected in: $file" >&2 + return 1 + fi + + # === BASE64 IN COMMENTS === + # Long base64 strings in comments could be encoded instructions + if echo "$content" | grep -qE '(#|//|