T25: opt-in PostHog + security review pass #24
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "t25-posthog-security"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
T25: Opt-in PostHog (no PII) + security review pass
Stacked on #23 (
t24-self-hosting) → … → #1. Merge those first.PostHog (opt-in, privacy-first)
POSTHOG_KEYis set (POSTHOG_HOSTdefaults to the EU cloud). No SDK, no autocapture, no cookies./,/login,/calendar,/connectors,/assistants,/account; everything else becomes/other, so no/authorize?…or/auth/callback?code=…) plus a random per-browser id. It honours Do Not Track / Global Privacy Control.POST /api/telemetry(same origin, 512-byte streaming cap) forwards the event from the Worker, so PostHog never sees the user's IP or user agent. Events carry$ip: nulland$process_person_profile: false.Security headers (every response)
Referrer-Policy: no-referrer(OAuth codes and states never leak throughReferer),X-Content-Type-Options,X-Frame-Options: DENYandframe-ancestors 'none',base-uri,object-src,Permissions-Policy,COOP, and HSTS on https. Route-specific headers (the consent page's strict CSP) take precedence. Verified: MCP 401/streaming, OAuth redirects and the dev server all still work.Whole-repository security audit
Astra audited the entire repo, not a diff. No P0/P1. Fixed:
ALLOWED_USERSwasn't enforced for MCP, so a removed user kept access through the AI. There's now one shared policy (src/lib/allowlist.ts) for website sign-in and MCP, and excluded users' grants are revoked on use.readBounded512-byte streaming cap (moved tosrc/lib/bounded.ts).truncatedflag (that flag came from Astra's diff review).It also confirmed as sound: user isolation, CSRF (including TanStack's default server-function protection), OAuth/PKCE/state, SSRF and token exfiltration, crypto, injection/XSS/open redirects, credential exposure, deletion, headers and cookies, and dependency advisories.
docs/security.mdData inventory, a threat → control → test table, and an audit log.
Verified
bun run lint && bun run typecheck && bun run test: 285 tests. New ones cover telemetry (allowlisted paths, event validation, payload without IP), security headers (precedence, immutable redirects, HSTS only on https), the rate limiter, the allowlist policy, the oversized upstream body, and the bounded and truncated Grades tree.bun run dev: headers present on pages and on the/mcp401, the rate limit triggers after 10 registrations, telemetry is a no-op without a key, and the signed-in calendar still renders.🤖 Generated with Claude Code