# Security Audit Report **Date:** 2026-02-02 (Updated) **Version:** 0.3.3 **Status:** ✅ COMPREHENSIVE SECURITY HARDENING COMPLETE --- ## Executive Summary | Category | Critical | High | Medium | Low | Total | Fixed | |----------|----------|------|--------|-----|-------|-------| | npm Dependencies | 0 | 0 | 0 | 0 | 0 | ✅ 34/34 | | Code Vulnerabilities | 0 | 0 | 0 | 0 | 0 | ✅ ALL FIXED | | **Total** | **0** | **0** | **0** | **0** | **0** | ✅ | **Result:** All security issues fixed. Production-ready with comprehensive hardening. --- ## 1. npm Dependency Vulnerabilities - ALL FIXED ### Fixed via npm overrides in package.json: | Vulnerability | Severity | Original Package | Fix Applied | |---------------|----------|------------------|-------------| | axios CSRF/SSRF | HIGH | @orca-so/whirlpool-sdk | Override to axios ^1.7.4 | | bigint-buffer overflow | HIGH | Solana packages | Override to @vekexasia/bigint-buffer2 ^1.0.4 | | elliptic crypto risk | HIGH | secp256k1 | Replaced with @noble/secp256k1 ^3.0.0 | | nanoid predictable | MODERATE | @drift-labs/sdk | Override to nanoid ^3.3.8 | | nodemailer DoS | MODERATE | Direct dependency | Updated to ^7.0.13 | | undici DoS | MODERATE | discord.js | Override to undici ^6.23.0 | | @cosmjs/crypto | HIGH | @wormhole-foundation/sdk | Override to ^0.38.1 (uses @noble/curves) | ### npm audit result: ``` found 0 vulnerabilities ``` --- ## 2. Code Vulnerabilities ### ✅ FIXED - HIGH Risk #### 2.1 Command Injection - Multiple Files ✅ FIXED - **Original:** `execSync()` with string interpolation allowing shell injection - **Fix:** Replaced with `execFileSync()` with array arguments across all files: - `src/nodes/index.ts` - notifications, clipboard, say, open, commandExists - `src/process/index.ts` - commandExists - `src/permissions/index.ts` - resolveCommandPath - `src/hooks/index.ts` - checkRequirements - `src/daemon/index.ts` - launchctl commands - `src/macos/index.ts` - runAppleScriptSync - `src/agents/index.ts` - exec_python - **Status:** ALL FIXED - 15+ injection points remediated #### 2.2 Unsafe Sandbox - `src/security/index.ts` ✅ FIXED - **Original:** `new Function()` sandbox is bypassable - **Fix:** Sandbox now DISABLED by default. Requires `ALLOW_UNSAFE_SANDBOX=true` env var to enable. - **Status:** ✅ FIXED - Secure by default #### 2.3 Weak Random ID Generation ✅ FIXED (Feb 2026) - **Original:** `Math.random().toString(36)` used for IDs across 21+ files - **Fix:** Created `src/utils/id.ts` with `crypto.randomBytes()` based generators - **Files Fixed:** alerts, usage, memory, media, cron, hooks, arbitrage, canvas, embeddings, agents, all extensions - **Status:** ✅ FIXED - All IDs now cryptographically secure #### 2.4 Canvas eval() Remote Code Execution ✅ FIXED (Feb 2026) - **Original:** Browser-side `eval()` executed arbitrary JS from WebSocket - **Fix:** JS eval disabled by default. Requires `CANVAS_ALLOW_JS_EVAL=true` to enable. - **Status:** ✅ FIXED - Secure by default #### 2.5 Task Runner Shell Injection ✅ FIXED (Feb 2026) - **Original:** `spawn()` with `shell: true` allowed command injection - **Fix:** Replaced with `execFile()`, added command validation, restricted env vars - **Status:** ✅ FIXED - No shell interpretation #### 2.6 XSS in Canvas Components ✅ FIXED (Feb 2026) - **Original:** User input rendered via `innerHTML` without sanitization - **Fix:** Added `escapeHtml()` and `sanitizeStyle()` to all component renderers - **Status:** ✅ FIXED - All output escaped #### 2.7 CORS Misconfiguration ✅ FIXED (Feb 2026) - **Original:** `Access-Control-Allow-Credentials: true` sent with wildcard origin - **Fix:** Credentials only allowed with specific origin allowlist - **Status:** ✅ FIXED - Proper CORS handling #### 2.8 Missing Rate Limiting ✅ FIXED (Feb 2026) - **Original:** No IP-based rate limiting on gateway - **Fix:** Added sliding window rate limiter (100 req/min default, configurable) - **Status:** ✅ FIXED - `CLODDS_IP_RATE_LIMIT` env var #### 2.9 Missing Security Headers ✅ FIXED (Feb 2026) - **Original:** No HSTS, X-Frame-Options, etc. - **Fix:** Added all recommended security headers + HTTPS enforcement option - **Status:** ✅ FIXED - `CLODDS_HSTS_ENABLED`, `CLODDS_FORCE_HTTPS` env vars #### 2.10 WebSocket Message Validation ✅ FIXED (Feb 2026) - **Original:** No validation of incoming WebSocket message structure - **Fix:** Added `isValidWebMessage()` validator + 1MB size limit - **Status:** ✅ FIXED - Type + size validation #### 2.11 Weak Session IDs ✅ FIXED (Feb 2026) - **Original:** Session IDs used `Math.random()` - **Fix:** Now uses `crypto.randomBytes(16).toString('hex')` - **Status:** ✅ FIXED - Cryptographically secure sessions #### 2.12 Escrow Keypairs In-Memory Only ✅ FIXED (Feb 2026) - **Original:** Escrow keypairs stored only in memory (`Map`) - **Risk:** Server restart = lost keypairs = funds unrecoverable - **Fix:** Keypairs now encrypted (AES-256-GCM) and stored in SQLite database - **Encryption:** Uses `CLODDS_ESCROW_KEY` or `CLODDS_CREDENTIAL_KEY` env var - **Status:** ✅ FIXED - Keypairs survive server restarts ### All Previously Accepted Risks - NOW FIXED | Risk | Original Status | New Status | |------|-----------------|------------| | Rate limiting | Recommended | ✅ IMPLEMENTED | | Math.random() IDs | Accepted | ✅ FIXED | | Input validation | Accepted | ✅ IMPROVED | | Security headers | Recommended | ✅ IMPLEMENTED | --- ## 3. Remediation Summary ### All Issues - FIXED | # | Issue | Fix | Status | |---|-------|-----|--------| | 1 | nodemailer | Updated to 7.0.13 | ✅ DONE | | 2 | Command injection | execFileSync with array args | ✅ DONE | | 3 | Unsafe sandbox | Disabled by default | ✅ DONE | | 4 | elliptic/secp256k1 | Replaced with @noble/secp256k1 | ✅ DONE | | 5 | bigint-buffer | Override to @vekexasia/bigint-buffer2 | ✅ DONE | | 6 | axios in orca-sdk | Override to axios ^1.7.4 | ✅ DONE | | 7 | discord.js undici | Override to undici ^6.23.0 | ✅ DONE | | 8 | nanoid | Override to nanoid ^3.3.8 | ✅ DONE | | 9 | @cosmjs/* elliptic | Override to ^0.38.1 | ✅ DONE | | 10 | Math.random() IDs | crypto.randomBytes() in 21 files | ✅ DONE | | 11 | Canvas eval() | Disabled by default | ✅ DONE | | 12 | Task runner shell injection | execFile + validation | ✅ DONE | | 13 | XSS in canvas | HTML escaping | ✅ DONE | | 14 | CORS misconfiguration | Proper credential handling | ✅ DONE | | 15 | Missing rate limiting | IP-based sliding window | ✅ DONE | | 16 | Missing security headers | HSTS, X-Frame-Options, etc. | ✅ DONE | | 17 | WebSocket validation | Type + size validation | ✅ DONE | | 18 | Weak session IDs | crypto.randomBytes() | ✅ DONE | ### No Remaining Issues All previously identified issues have been remediated. --- ## 4. Security Best Practices Implemented ✅ **Encrypted credentials** - AES-256-GCM at rest ✅ **No hardcoded secrets** - All from environment ✅ **HTTPS enforced** - For all API calls ✅ **Webhook signature verification** - HMAC validation ✅ **SQL injection prevention** - Parameterized queries ✅ **Audit logging** - All trades logged ✅ **Modern crypto libraries** - @noble/* instead of deprecated elliptic ✅ **Security Shield** - Code scanner (75 rules/9 categories), scam DB (70+ addresses from Etherscan/Mandiant/CertiK), multi-chain address checker, pre-trade tx validator, input sanitizer (zero-width/RTL/homoglyph/prompt injection detection) --- ## 5. Security Headers - IMPLEMENTED The following headers are now automatically added by the gateway: ```typescript // Always added: 'X-Content-Type-Options': 'nosniff' 'X-Frame-Options': 'DENY' 'X-XSS-Protection': '1; mode=block' // When CLODDS_HSTS_ENABLED=true or connection is HTTPS: 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains' ``` ### Configuration ```bash # Enable HSTS header CLODDS_HSTS_ENABLED=true # Force HTTP to HTTPS redirect CLODDS_FORCE_HTTPS=true # IP rate limiting (requests per minute) CLODDS_IP_RATE_LIMIT=100 ``` ### MCP Server Security The MCP stdio server includes 5 security layers, all opt-in via environment variables: | Layer | Env Var | Default | Description | |-------|---------|---------|-------------| | Tool allowlist | `CLODDS_MCP_ALLOWED_TOOLS` | _(all)_ | Comma-separated list of allowed tool names | | Tool blocklist | `CLODDS_MCP_BLOCKED_TOOLS` | _(none)_ | Comma-separated list of blocked tool names | | Tool profiles | `CLODDS_MCP_TOOL_PROFILE` | `full` | Predefined access: `read-only`, `trading`, `full` | | Rate limiting | `CLODDS_MCP_RATE_LIMIT` | `60` | Max calls per minute per client | | Audit logging | `CLODDS_MCP_AUDIT` | `true` | Structured JSON audit logs to stderr | Input sanitization runs automatically on all tool calls — string arguments are scanned for SQL injection, command injection, XSS, and path traversal patterns using the existing `detectInjection()` function. ```bash # Example: restrict MCP to read-only tools with audit logging CLODDS_MCP_TOOL_PROFILE=read-only CLODDS_MCP_RATE_LIMIT=30 CLODDS_MCP_AUDIT=true ``` --- ## 6. Publishing Checklist ✅ - [x] Fix nodemailer vulnerability - [x] Fix command injection in nodes/index.ts - [x] Add sandbox warning - [x] Fix all npm audit vulnerabilities (34 → 0) - [x] Replace elliptic with @noble/secp256k1 - [x] Override bigint-buffer with secure fork - [x] Test all trading functions work after updates - [x] Run `npm audit` - shows 0 vulnerabilities --- ## 7. Disclosure Policy Security issues should be reported to: security@clodds.dev (or GitHub Security Advisories) Do NOT create public issues for security vulnerabilities. --- *Security audit completed on 2026-01-30* *All 34 npm vulnerabilities fixed* *Ready for npm publish* --- ## 8. Server Hardening CLI Clodds includes a built-in server hardening command for production deployments. ### Usage ```bash # Apply all hardening with interactive prompts clodds secure # Preview changes without modifying clodds secure --dry-run # Run security audit only clodds secure audit # Non-interactive mode (skip prompts) clodds secure --yes # Custom SSH port clodds secure --ssh-port=2222 # Skip specific components clodds secure --skip-firewall --skip-fail2ban ``` ### What it hardens | Component | Changes Applied | |-----------|-----------------| | **SSH** | Disable password auth, root login, MaxAuthTries=3 | | **Firewall (ufw)** | Allow SSH + custom ports, deny incoming by default | | **fail2ban** | Protect against brute force (5 failures = 1hr ban) | | **Auto-updates** | Enable unattended-upgrades for security patches | | **Kernel** | sysctl hardening (SYN cookies, ICMP redirects, etc.) | ### Security Audit Output ``` $ clodds secure audit 🔒 Clodds Server Security Hardening ℹ === Security Audit === ✔ SSH Password Auth: Disabled ✔ SSH Root Login: Disabled ⚠ SSH Port: Port 22 (consider changing from default) ✔ Firewall (ufw): Active ✔ fail2ban: Active (1 jail) ✔ Auto-updates: Configured 5 passed, 1 warnings, 0 failed ``` ### Post-Hardening Checklist 1. **Test SSH access** in a new terminal before closing current session 2. **Verify firewall rules** don't block required ports 3. **Monitor fail2ban** logs for legitimate users being blocked 4. **Keep SSH key** backed up securely