Security hardening: PII filter expansion and attack chain remediation#2
Open
Security hardening: PII filter expansion and attack chain remediation#2
Conversation
…harden all layers Comprehensive security remediation based on 83-finding audit (11 critical, 22 high, 24 medium, 14 low, 12 info). Closes the critical attack chain where a crafted email could bypass injection filters, expose unredacted PII, and exfiltrate data via drafts. Phase 1 — Break the attack chain: - Injection filter now blocks (was: warn only) - create_draft filtered through pipeline (recipient domain blocking, CRLF strip) - list_threads PII-redacts snippet/subject via pipeline.redactText() - PII/injection filters enforced as always-on (server-side floors in api.ts) - MCP endpoint body size limited to 1MB - .env.bak deleted, .gitignore hardened with *.bak, *.pem, *.key, etc. Phase 2 — Harden auth, crypto, and infrastructure: - OAuth account takeover prevention (password-based accounts reject OAuth login) - HKDF key derivation separates session/credential/OAuth keys from master secret - Per-credential random salt for IMAP/GAS encryption (legacy fallback preserved) - OAuth tokens encrypted at rest (EncryptedOAuthTokens type) - Rate limiter: per-email + per-IP dual-key limiting, MCP endpoint rate limiting - Session verified on OAuth connect callback - Logout changed to POST with Origin header CSRF protection - IMAP SSRF prevention via DNS resolution + comprehensive IP validation - .dockerignore created, Dockerfile hardened (non-root user, healthcheck) - docker-compose hardened (localhost bind, no-new-privileges, read-only) - Security headers added (X-Content-Type-Options, X-Frame-Options, HSTS, etc.) - Wildcard CORS removed, scoped to configured origin Phase 3 — Deepen defenses: - PII patterns expanded: phone numbers, Mastercard 2-series, addresses, dollar amounts - Unicode NFKC normalization in sanitizer (collapses homoglyphs) - PII redaction applied to from/to/cc name fields - ReDoS protection for user-supplied regex patterns - Sessions invalidated on password change - Login error messages whitelisted (no URL param reflection) - CI/CD security scanning (pnpm audit, TruffleHog) - Structured audit logging for security events Build: all 4 packages clean. Tests: 55/55 pass. Remaining manual actions: - Rotate GOOGLE_CLIENT_SECRET and SESSION_SECRET in production - pnpm update hono (4.11.9 -> 4.12.x for timing-safe comparison fix) - pnpm add safe-regex2 --filter @agentcloak/server Created by gregb and his home-grown crew of builders 🦜 🤖
Tests cover the full security hardening surface: filter pipeline integration (chain ordering, redactText, folder/attachment filtering), MCP tool security (create_draft recipient domain blocking, CRLF injection prevention, list_threads PII redaction and thread blocking), HKDF key derivation (context separation, determinism), IMAP credential encryption (per-credential salt, legacy fallback, tamper detection), and expanded PII patterns (phone, MC 2-series, SSN variants, address name fields). 103 tests passing across 9 test files. Created by gregb and his home-grown crew of builders 🦜 🤖
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan