Commit Graph

10 Commits

Author SHA1 Message Date
e446eb1775 fix(p8-010): move rate-limit store to a shared distributed DB store
Replace the per-Vercel-instance in-memory Map rate-limit cache with an
atomic shared store backed by the existing Turso RateLimit table, so limits
hold across all instances/redeploys and cannot be bypassed by distributing
brute-force attempts across instances (audit finding p8-010, MEDIUM).

- checkRateLimit now performs a single atomic round-trip:
  INSERT ... ON CONFLICT(identifier) DO UPDATE ... RETURNING count, reset_at
  with window-reset semantics (CASE WHEN reset_at < now THEN 1 ELSE count+1).
- The DB is now the primary source of truth (no longer a fire-and-forget
  fallback). The per-instance Map is reduced to a short-TTL local cache used
  ONLY to fast-fail already-blocked identifiers (cuts DB load during brute-
  force storms); it can never let a request bypass the limit.
- ensureRateLimitSchema() creates the table + a UNIQUE identifier index so
  ON CONFLICT upserts are well-defined; added RateLimit to db/create.ts.
- resetLoginRateLimits / clearRateLimitStore invalidate the local cache.
- getClientIP now trusts proxy headers in non-development environments
  (production + test); local dev stays strict against header spoofing.
- bunfig.toml defines import.meta.env.SSR=true so the server-only env guard
  loads under 'bun test'.
- Tests: await clearRateLimitStore in beforeEach (fixes a race where an
  un-awaited clear let leftover rows corrupt the next upsert); unique test
  identifiers; realistic remote-shared-store perf bounds; new p8-010
  distributed-store tests (restart-survival, multi-instance aggregation,
  no bypass by alternating instances).
2026-07-22 18:10:28 -04:00
58d48dac70 checkpoint 2026-01-21 12:22:19 -05:00
f68f1f462a session state simplification 2026-01-12 09:24:58 -05:00
8f241ce611 adjust email/pass addition flow, blog ttl extended 2026-01-07 21:21:27 -05:00
f056cf05d3 hopeful 2026-01-07 20:19:26 -05:00
08a9ad35af updating auth token security 2026-01-06 23:11:19 -05:00
a620a9f4c5 perf improvements 2026-01-04 14:53:30 -05:00
6e31246060 lockout 2025-12-30 09:50:04 -05:00
2852c0b450 post fields improvements 2025-12-29 17:47:35 -05:00
53a4ae1a43 oh baby boy 2025-12-26 13:41:50 -05:00