App Router route handlers (GET, POST, PUT, DELETE) are public HTTP endpoints. Every exported function must independently verify auth — middleware alone is insufficient. [CWE-862 · A01:2021]
Why This Matters
prevents unauthorized access to API endpoints that bypass middleware
Impact: CRITICAL (prevents unauthorized access to API endpoints that bypass middleware)
App Router route handlers (app/api/.../route.ts) are publicly accessible HTTP endpoints. Each exported function — GET, POST, PUT, DELETE — resolves independently and must verify authentication and authorization on its own. Middleware and layout-level auth checks do not protect route handlers because:
Route handlers are resolved independently from the page component tree
Middleware can be bypassed (see CVE-2025-29927)
Direct HTTP requests skip the UI entirely — there is no layout wrapping an API call
This is the route handler equivalent of sec-server-action-auth. The same principle applies: treat every route handler as a public-facing API endpoint.