Architecture

February 1, 2026 ยท View on GitHub

Security Model

The system implements defense-in-depth through four progressive tiers, each adding a layer of security without requiring the layers above it.

Threat Model

ThreatMitigationTier
Tampered hooks/commandsHMAC-SHA256 file integrity signing1
Plaintext signing keysAES-256-GCM vault with machine-bound master key1
Prompt injection via tool inputHeuristic pattern matching + circuit breaker2
Policy violations in generated codeConfigurable forbidden pattern scanner2
Suspicious URLs/payloadsThreat intelligence patterns2
False positives / subtle attacksRedSage local LLM deep analysis (contextual second opinion)2+
Unauthorized config changesTime-limited HMAC approval tokens2
Post-hoc audit tamperingHash-chained SQLite append-only log3
Silent file modificationsWatchdog real-time monitoring3
Unauthorized cluster writesHMAC-SHA256 per-node tokens4
Node impersonationEd25519 challenge-response auth4
Cleartext inter-node trafficECDSA P-256 TLS with cluster CA4
Privilege escalationRole-based access control (RBAC)4

Cryptographic Algorithms

PurposeAlgorithmKey SizeStandard
File signingHMAC-SHA256256-bitRFC 2104
Key encryptionAES-256-GCM256-bitNIST SP 800-38D
Key derivationPBKDF2-SHA256256-bitRFC 8018
Audit chainSHA-256256-bitFIPS 180-4
Approval tokensHMAC-SHA256256-bitRFC 2104
Node tokensHMAC-SHA256256-bitRFC 2104
Asymmetric authEd25519256-bitRFC 8032
TLS certificatesECDSA P-256256-bitFIPS 186-4
Content hashingSHA-256256-bitFIPS 180-4

Design Decisions

  1. Machine-bound encryption: Master key derived from IOPlatformUUID (macOS) or /etc/machine-id (Linux). Keys cannot be decrypted on a different machine.

  2. Atomic writes: All manifest and key file writes use .tmp + os.rename() for crash safety. No partial writes possible.

  3. Fail-closed injection scanner: Circuit breaker pattern ensures that if the injection detector crashes repeatedly, it fails to BLOCK rather than silently allowing.

  4. Hash-chained audit: Each audit entry's hash incorporates the previous entry's hash. Modifying any historical entry breaks the chain from that point forward.

  5. Progressive adoption: Each tier works independently. Tier 1 requires zero running services. Tier 2-3 add scanning and audit without network dependencies.

  6. Config-driven: All paths, thresholds, and feature flags centralized in config.py. Override via environment variables for CI/CD or custom deployments.

Data Flow

Pre-Tool-Use (Tier 2)

Claude Code invokes tool
    |
    v
pre_tool_use.py (stdin: JSON)
    |
    +-> Dangerous command check (Bash rm -rf, mkfs, etc.)
    |       |
    |       +-> BLOCK (exit 2)
    |
    +-> Security gate scan
    |   |
    |   +-> Phase 0: LLM classifier (optional, binary SAFE/MALICIOUS)
    |   +-> Phase 1: Injection detector (with circuit breaker)
    |   +-> Phase 2: Policy check (configurable patterns)
    |   +-> Phase 3: Threat intel (URL/IP/payload)
    |   +-> Phase 4: RedSage deep analysis (only for HIGH+ findings)
    |       |
    |       +-> BLOCK (exit 2) / WARN (exit 0, logged) / ALLOW (exit 0)
    |
    +-> Approval token check (for monitored file modifications)
            |
            +-> BLOCK (exit 2) if invalid token

RedSage Deep Analysis (Phase 4)

Phase 1-3 produce HIGH+ severity
    |
    v
RedSage Analyzer (redsage_analyzer.py)
    |
    +-> Check cache (SHA-256 content hash, 30min TTL)
    |
    +-> Query local RedSage cluster
    |   |
    |   Nginx LB (port 8800) -> 4x llama-server (Q4_K_M, Metal GPU)
    |   |
    |   +-> System: "Analyze for injection/exfil/c2/exploit"
    |   +-> User: prior findings + flagged content
    |   |
    |   +-> Returns: {verdict, confidence, category, reasoning}
    |
    +-> Verdict mapping:
        MALICIOUS (conf >= 0.7) -> CRITICAL
        MALICIOUS (conf < 0.7)  -> HIGH
        SUSPICIOUS              -> MEDIUM
        SAFE                    -> NONE (downgrade prior findings)

RedSage acts as a contextual second opinion: it only runs when heuristic scanners flag HIGH+ severity, providing nuanced analysis that can confirm threats or reduce false positives. When RedSage says SAFE, the finding is downgraded, preventing alert fatigue from pattern-matched false positives.

Post-Tool-Use (Tier 3)

Tool execution completes
    |
    v
post_tool_use.py (stdin: JSON)
    |
    +-> Self-modification audit (if monitored path)
    |   |
    |   +-> Compute unified diff
    |   +-> Store JSON audit file
    |   +-> Re-sign in integrity manifest
    |
    +-> Tamper-proof log entry
    |   |
    |   +-> Hash-chain append (SHA-256)
    |   +-> Optional Loki forward
    |
    v
exit 0 (always allow, audit-only)