Admin Routes Protected with Role Check
Why it matters
An admin route that checks if (!session) but not if (session.user.role !== 'admin') is accessible to every authenticated user in the application. This exposes user management, system configuration, and privileged operations to any account holder. CWE-285 (Improper Authorization) and CWE-284 (Improper Access Control) define this failure precisely. OWASP A01 (Broken Access Control) lists this as a primary failure mode. NIST 800-53 AC-3 and AC-6 require that admin operations enforce both authentication and the specific privilege level required — the authentication check alone is necessary but not sufficient.
Severity rationale
Critical because any authenticated user gains access to administrative functionality — user management, billing, system configuration — without needing any elevated credentials.
Remediation
Use middleware.ts to enforce admin role checks across the entire /admin path group before requests reach individual handlers. Keep role checks in handlers as well for defense in depth.
// middleware.ts
export async function middleware(req: NextRequest) {
const token = await getToken({ req });
if (req.nextUrl.pathname.startsWith('/admin')) {
if (!token) return NextResponse.redirect(new URL('/login', req.url));
if (token.role !== 'admin') return NextResponse.redirect(new URL('/403', req.url));
}
return NextResponse.next();
}
export const config = {
matcher: ['/admin/:path*', '/api/admin/:path*'],
};
Middleware can be bypassed in some configurations — individual admin API handlers should also check session.user.role === 'admin' as a second line of defense.
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 Authorization Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-285 — Improper Authorization
- cwe · CWE-284 — Improper Access Control
- owasp:2021 · A01
- nist:rev5 · AC-3
- nist:rev5 · AC-6
- soc2:2017 · CC6.1 — Logical access security software, infrastructure, and architectures
- soc2:2017 · CC6.3 — Role-based access and least privilege
- soc2:2017 · CC6.6 — Protection against threats from outside system boundaries
Taxons
History
- 2026-04-18·v1.0.0·Initial import from saas-authorization·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (CC6.1, CC6.3, CC6.6) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2