Session-getter failures return early without executing protected logic
Why it matters
Calling const session = await auth() and then immediately proceeding to render data or execute logic without checking if (!session) means the code path runs identically whether the user is authenticated or not. CWE-284 (Improper Access Control) and OWASP A01 apply: a null session is not an error, it's the expected return value when no user is logged in. The absence of a guard after the session call is functionally equivalent to having no auth check at all — the protected logic executes unconditionally.
Severity rationale
High because an unguarded session call allows the protected logic to execute when the session is null, bypassing authentication on any route where this pattern appears.
Remediation
Add a null-check guard within the first few lines after the session call. The guard must redirect or return before any business logic runs.
// Bad: session called but result ignored
const session = await auth()
const users = await prisma.user.findMany() // executes even when session is null
// Good: guard immediately
const session = await auth()
if (!session?.user) {
redirect('/login')
// or for API routes:
// return Response.json({ error: 'Unauthorized' }, { status: 401 })
}
const users = await prisma.user.findMany()
The pattern if (!session?.user) redirect('/login') is idiomatic for Next.js App Router server components. For API routes, use an early return Response.json(...) with status 401.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Security Implementation Validation Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-284 — Improper Access Control
- cwe · CWE-754 — Improper Check for Unusual or Exceptional Conditions
- owasp:2021 · A01 — Broken Access Control
- owasp:2021 · A07 — Identification and Authentication Failures
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-slop-security-theater·automated