Authorization Model Defined
Why it matters
Ad-hoc role checks scattered across route files — user.role === 'admin' repeated in a dozen places — are impossible to audit and trivially out of sync. When a new role is added or a permission is tightened, every scattered comparison must be found and updated manually. One missed file is a silent privilege escalation. CWE-284 (Improper Access Control) and OWASP A01 (Broken Access Control) both trace back to exactly this pattern: authorization decisions made without a single, auditable source of truth. NIST 800-53 AC-3 requires access enforcement to be consistently applied — string comparisons in individual handlers fail that standard by design.
Severity rationale
High because a missing or stale inline role check grants unauthorized capabilities to any authenticated user who reaches that route.
Remediation
Create lib/auth/permissions.ts as the single source of truth for all role definitions and permission checks. Export a typed hasPermission(user, action) helper and import it from every route handler — never compare role strings inline again.
// lib/auth/permissions.ts
export const ROLES = { ADMIN: 'admin', MEMBER: 'member', VIEWER: 'viewer' } as const;
export type Role = typeof ROLES[keyof typeof ROLES];
export function hasPermission(user: { role: Role }, action: string): boolean {
const permissions: Record<Role, string[]> = {
admin: ['read', 'write', 'delete', 'manage_users'],
member: ['read', 'write'],
viewer: ['read'],
};
return permissions[user.role]?.includes(action) ?? false;
}
After adding this file, grep for user.role === across the codebase and replace every hit with a hasPermission() call.
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-284 — Improper Access Control
- cwe · CWE-285 — Improper Authorization
- owasp:2021 · A01
- nist:rev5 · AC-3 — Access Enforcement
- soc2:2017 · CC6.1 — Logical access security software, infrastructure, and architectures
- soc2:2017 · CC6.3 — Role-based access and least privilege
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) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2