Security overview

Defense in depth - security applied at every tier. No single point of failure.

Security layers

NextForge applies security at 5 distinct tiers:

  1. Input - Zod validation + XSS sanitization before any processing
  2. Business logic - rate limiting + auth re-verification in every action
  3. Database - injection prevention + parameterized queries
  4. Session - JWT strategy, HTTP-only cookies, auth re-check in server components
  5. Transport - security headers on every response via proxy.ts

Full security reference

Render this as a full-width table (w-full border-collapse):

LayerImplementation
Password hashingbcrypt, cost factor 12
OTP generationcrypto.randomInt (CSPRNG), 6-digit
OTP storageSHA-256 hash stored, plaintext never persisted
OTP verificationcrypto.timingSafeEqual - constant-time comparison
OTP expiry10 minutes, checked at query time with expiresAt > now
NoSQL injectionstripMongoOperators() strips $-prefixed and dot-notation keys
SQL injectionSupabase JS client uses parameterized queries internally
XSSescapeHTML() applied to all user-supplied string inputs
Rate limitingUpstash Redis sliding window - 5/min auth, 3/min OTP
SessionJWT strategy, AUTH_SECRET required in all environments
Route protectionproxy.ts redirects + independent auth() check in every action
Security headersCSP, X-Frame-Options: DENY, X-Content-Type-Options: nosniff, HSTS
Email enumerationPassword reset and OTP resend always return the same response

The middleware CVE

In early 2025, a critical CVE was disclosed affecting Next.js middleware. An attacker could bypass middleware-based authentication checks entirely by sending a crafted x-middleware-subrequest header - bypassing all redirect and auth logic in middleware.ts.

Next.js 16 addresses this by renaming middleware.ts to proxy.ts and changing the export function name from middleware to proxy, making bypass attempts less effective. However, the architectural lesson remains: