Role-based access control enforced
Why it matters
Broken Function Level Authorization (OWASP API Security Top 10 2023 API5) is what happens when authentication and object-level checks exist but role enforcement doesn't — any logged-in user reaches admin-only functions. CWE-269 (Improper Privilege Management) covers the pattern: the application knows what role a user has but doesn't consult it before executing privileged operations. A user who discovers /api/admin/delete-user or /api/billing/refund-all can invoke it if role checks are missing. Compromised non-admin accounts become full admin accounts. Internal tools are a common gap — developers add auth but skip role checks on 'internal' routes.
Severity rationale
High because missing role checks let any authenticated user — including compromised accounts — execute privileged operations like deleting records or modifying system configuration.
Remediation
Add explicit role assertions at the top of every privileged route handler, not just in middleware. Middleware handles authentication; role authorization belongs at the route level where the required role is clear.
// src/app/api/admin/users/route.ts
export async function DELETE(req: Request) {
const user = await getAuthUser(req)
if (!user) return new Response('Unauthorized', { status: 401 })
// Role check — explicit, not delegated to a generic middleware flag
if (user.role !== 'admin') return new Response('Forbidden', { status: 403 })
const { userId } = await req.json()
await db.user.delete({ where: { id: userId } })
return Response.json({ deleted: true })
}
For complex role hierarchies, centralize checks in a src/lib/authz.ts policy module so role requirements are auditable in one place.
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 API Security 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-269 — Improper Privilege Management
- owasp:2021 · A01 — Broken Access Control
- owasp:2023 · API5 — Broken Function Level Authorization
- soc2:2017 · CC6.3 — Role-based access and least privilege
Taxons
History
- 2026-04-18·v1.0.0·Initial import from api-security·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (CC6.3) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2