Skip to content

feat(worker): proxy security hardening — 7-layer defense-in-depth stack#62

Open
wgordon17 wants to merge 12 commits intogordon-code:mainfrom
wgordon17:worktree-proxy-security-hardening
Open

feat(worker): proxy security hardening — 7-layer defense-in-depth stack#62
wgordon17 wants to merge 12 commits intogordon-code:mainfrom
wgordon17:worktree-proxy-security-hardening

Conversation

@wgordon17
Copy link
Copy Markdown
Member

Summary

  • Implements 7-layer defense-in-depth for CF Worker proxy endpoints: WAF rules (documented), request validation, session cookies, Workers Rate Limiting Binding, Turnstile challenges, AES-256-GCM sealed tokens with purpose binding, and SSRF hardening
  • Adds 6 new Worker modules (crypto, validation, session, turnstile, proxy, type declarations) with 132 new tests across 6 test files, plus integration tests for the /api/proxy/seal endpoint
  • Updates CSP to allowlist Turnstile domains, DEPLOY.md with WAF rules/secrets/local dev docs, and wrangler.toml with rate limiting binding and global_fetch_strictly_public flag

wgordon17 added 12 commits April 8, 2026 21:23
- sealApiToken: add purpose parameter, include in POST body (CRIT-001, 6/7 reviewers)
- ensureSession: wrap issueSession in try/catch, fallback to random sessionId on error (SEC-002, STRUCT-005)
- handleProxySeal: add VALID_PURPOSES allowlist + 64-char max-length for purpose field (SEC-003, QA-002)
- validateAndGuardProxyRoute: include CORS headers on validation error responses (SEC-004)
- session.ts: cache derived HMAC keys at module level to avoid repeated HKDF derivation (PERF-001/002)
- turnstile.ts: add 5s AbortController timeout to siteverify fetch (PERF-003)
- proxy.test.ts: update sealApiToken calls with purpose, assert body.purpose field, add error field test
- seal.test.ts: update purpose values to match VALID_PURPOSES allowlist
- crypto.test.ts: add cross-purpose isolation test (F-003)
- adds Turnstile token length guard (>2048) with boundary tests
- adds seal key derivation cache (_sealKeyCache Map, bounded by VALID_PURPOSES)
- passes pre-parsed pathname to validateAndGuardProxyRoute (eliminates redundant URL parse)
- unifies session key cache into single Map (removes duplicate getSessionHmacPrevKey)
- fixes structured error logging in ensureSession catch path
- removes dead options parameter from validateProxyRequest
- corrects HKDF key material descriptions in CryptoEnv and DEPLOY.md
- fixes test key comments to match actual decoded values
- adds 14 new tests covering previously-untested paths
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant