deckhearth/pages
Randall Stillwell 6dae7adc77 fix(auth): tighten public auth surface — CORS + rate limit (Brief 4 of fix-auth-bypass)
Adds rate limiting to /api/auth/login and /api/auth/register and removes
their wide-open CORS allowlist.

Rate limiting (@upstash/ratelimit + @upstash/redis):
  - 5 attempts per 15-minute sliding window per IP, prefix "tcgvault:auth"
  - new lib/rate-limit.js, lazy singleton, single source of truth
  - reads KV_REST_API_URL / KV_REST_API_TOKEN (Vercel Upstash Marketplace
    convention — auto-provisioned, no manual env-var setup needed)
  - fail-closed in production if env vars are missing (better to error
    one login than silently disable brute-force protection on live)
  - fail-open in dev/test if env vars are missing (single console.warn)
  - fail-open on Upstash backend outage (defense-in-depth — don't lock
    the entire userbase out if Upstash is down)
  - IP extracted from x-forwarded-for first hop, with socket fallback;
    NOT req.body.email (rotates) or Authorization header (absent on
    unauthenticated login)

CORS:
  - Removed Access-Control-Allow-Origin: * + companion headers + OPTIONS
    preflight from login.js and register.js
  - These are first-party endpoints called from the same-origin SPA; the
    "*" allowlist was a development convenience that shipped to prod
  - verify.js is OUT OF SCOPE per architect's "cors-tighten" deferral
    (see convoy plan § Architect's calls)

Other handler ordering preserved verbatim per brief: method gate first,
then rate-limit check (returns 429 with Retry-After header), then the
existing try/catch + body parsing + DB work.

Pre-merge requirements: KV_REST_API_URL + KV_REST_API_TOKEN must be set
in Vercel Production (already done — Upstash marketplace integration
auto-provisioned both, confirmed by maintainer 2026-05-23).

Convoy: fix-auth-bypass / Brief 4
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-23 10:51:33 -05:00
..
admin Fixed SSR and null user issues for production deployment 2025-07-24 17:04:06 -05:00
api fix(auth): tighten public auth surface — CORS + rate limit (Brief 4 of fix-auth-bypass) 2026-05-23 10:51:33 -05:00
card Major Scanner Improvements 2025-07-29 14:19:48 -05:00
collection Major Scanner Improvements 2025-07-29 14:19:48 -05:00
community Major Scanner Improvements 2025-07-29 14:19:48 -05:00
deck Major Scanner Improvements 2025-07-29 14:19:48 -05:00
invite 🎉 COMPLETED: Full Collaborative Collections System 2025-07-25 08:34:28 -05:00
_app.js Major redesign: Enhanced card display with particle effects, improved filters, and search functionality 2025-07-23 21:26:54 -05:00
cards.js Major Scanner Improvements 2025-07-29 14:19:48 -05:00
collections.js 🔧 Fix System Collections & Database Schema Issues 2025-07-27 19:17:55 -05:00
dashboard.js Major Scanner Improvements 2025-07-29 14:19:48 -05:00
deck-builder.js Major Scanner Improvements 2025-07-29 14:19:48 -05:00
decks.js Major Scanner Improvements 2025-07-29 14:19:48 -05:00
index.js Major Scanner Improvements 2025-07-29 14:19:48 -05:00
login.js Clean Up Login & Add Signup Flow 2025-07-28 11:09:58 -05:00
logout.js 🎨 Restructured Layout System 2025-07-25 11:28:04 -05:00
my-cards.js Major Scanner Improvements 2025-07-29 14:19:48 -05:00
profile.js 🎯 Build Comprehensive User Profile & Settings System 2025-07-26 18:05:55 -05:00
scanner.js Marker: Fixed card queue property mismatch - cards now properly separate in scanner queue 2025-08-01 17:41:42 -05:00
settings.js 🎯 Build Comprehensive User Profile & Settings System 2025-07-26 18:05:55 -05:00
signup.js 🎨 Enhanced Signup with Username & Profile Images 2025-07-28 11:18:58 -05:00