Authorization
A complete guide to Authorization (AuthZ): access control models, RBAC, ABAC, ReBAC, Least Privilege, and preventing unauthorized access.
Imagine you work at a hospital and you badge through the front employee entrance. Your identity has been verified (Authentication: the security system confirmed that you are an employee). Now you walk down the hallway. Can you walk into an operating room and perform surgery? Can you enter the pharmacy storage room and take medication? Can you open the hospital director's office and read executive financial reports? The answer to all three is no. Even though the hospital knows who you are, your access is limited strictly to your specific job duties. That process of defining and enforcing permissions is called Authorization (often shortened to AuthZ). While Authentication determines WHO you are, Authorization determines WHAT you are allowed to do.
Definition
Authorization (AuthZ) is the security process of determining whether an authenticated user or system has permission to perform a specific action or access a particular resource.
Why It Matters
Broken access control is consistently ranked by OWASP as one of the most critical web security vulnerabilities. When authorization is missing or implemented poorly, ordinary users can access administrative dashboards, view other customers' private records, or modify billing data. Proper authorization enforces the Principle of Least Privilege: giving users and automated systems only the specific permissions they need to do their jobs, minimizing potential damage if an account is compromised.
How It Works
Modern applications enforce authorization using several established models: 1. Role-Based Access Control (RBAC): Permissions are assigned to specific roles (such as Viewer, Editor, or Administrator), and users are assigned to those roles. RBAC is easy to understand, but in large organizations it can lead to 'role explosion,' where teams create dozens of custom roles to handle unique permission cases. 2. Attribute-Based Access Control (ABAC): Access decisions are evaluated dynamically using multiple attributes: • User Attributes: The user's role, department, or clearance level. • Resource Attributes: The sensitivity level or owner of the file being requested. • Action Attributes: Whether the user wants to read, edit, delete, or export data. • Environmental Context: The user's current location, time of day, or whether they are connecting from an approved corporate device. 3. Relationship-Based Access Control (ReBAC): Permissions are derived from relationships between entities (similar to Google Drive permissions). A user can view a document because they belong to a team, and that team was given access to the folder containing the document. 4. Enforcement Points: In modern architectures, a Policy Enforcement Point (PEP, such as an API gateway) intercepts incoming requests, and a Policy Decision Point (PDP, such as Open Policy Agent) evaluates the rules to return a simple allow or deny decision.
Policy Decision Architecture: Enforcement and Decision Points
Key Points
- Authentication confirms identity; Authorization enforces permissions.
- Default-Deny: Every resource should be closed by default until explicitly permitted.
- RBAC groups permissions by role; ABAC evaluates real-time user, resource, and environmental context.
- Broken Object-Level Authorization (BOLA/IDOR) occurs when an application forgets to verify who owns a specific record.
- Frontend checks improve user experience, but server-side checks are required for real security.
Steps
Adopt Default-Deny Access Rules
Configure all routes and resources to deny access by default unless an explicit permission rule grants access.
Verify Object-Level Ownership
Never rely solely on general role checks. Always verify that the authenticated user actually owns or is permitted to see the specific record ID they requested.
Separate Policy from Application Code
Use dedicated permission middleware or policy engines rather than scattering complex, hardcoded if/else permission checks across business logic.
Enforce Checks on the Server Side
Never rely on client-side UI checks (such as hiding an Admin link in the navigation menu); validate every incoming request on the backend.
Log Authorization Denials
Record failed authorization attempts in security logs to detect automated vulnerability scanning and account enumeration.
Examples
The Office Elevator Keycard Analogy
In an office building: Authentication is the lobby guard confirming your identity and handing you a keycard. Authorization is the programming on that keycard: it opens the door to your floor and the lunchroom, but tapping it on the executive boardroom floor causes the elevator to stay put and display an access denied light.
Real-World Examples
The Panera Bread API Data Exposure
Panera Bread's online customer portal required users to log in, but the customer profile API endpoint did not check authorization on record IDs (`/api/customers/<id>`). Any logged-in user could change the numeric ID in the URL to view the names, email addresses, and phone numbers of millions of other customers.
Excessive IAM Role Permissions in Cloud Storage
In a major cloud data incident, an application firewall server was assigned an overly broad administrative IAM role. When an attacker found a vulnerability in the firewall, they inherited that role and used its excessive permissions to list and download data across hundreds of private storage buckets.
Technical Examples
import { Request, Response } from "express";
import { db } from "./database";
interface AuthenticatedRequest extends Request {
user?: {
id: string;
organizationId: string;
role: "admin" | "manager" | "member";
};
}
// Controller preventing unauthorized record access (BOLA / IDOR)
export async function getDocumentById(req: AuthenticatedRequest, res: Response) {
const documentId = req.params.id;
const user = req.user;
if (!user) {
return res.status(401).json({ error: "Authentication required" });
}
// 1. Fetch document from database
const document = await db.documents.findUnique({
where: { id: documentId },
});
if (!document) {
// Return 404 to avoid confirming whether document exists
return res.status(404).json({ error: "Document not found" });
}
// 2. Organization boundary check: User must belong to the same organization
if (document.organizationId !== user.organizationId) {
console.warn(`[ALERT] User ${user.id} tried to access doc ${documentId} from another org`);
return res.status(403).json({ error: "Access denied: insufficient permissions." });
}
// 3. Classification check: Require manager role for confidential documents
if (document.classification === "confidential" && user.role === "member") {
return res.status(403).json({ error: "Access denied: confidential documents require manager role." });
}
// Authorization successful: Return document data
return res.json({ data: document });
}Role-Based Access Control (RBAC) vs Attribute-Based Access Control (ABAC)
| Aspect | Role-Based Access Control (RBAC) | Attribute-Based Access Control (ABAC) |
|---|---|---|
| Basis for Access | User's assigned role or group (such as 'Analyst') | Attributes of the user, resource, action, and environment |
| Context Sensitivity | Static: Does not check time, location, or device health | Dynamic: Evaluates real-time contextual conditions |
| Implementation | Simple: Managed with role tables in a database | Advanced: Managed with dedicated policy rules and engines |
| Scaling Challenge | Role explosion when many custom roles are created | Policy management overhead and evaluation latency |
| Best Fit | Small to medium apps with clear hierarchy | Complex enterprise systems with varied access rules |
Relationship-Based Access Control (ReBAC)
Advantages
- Prevents Data Exposure: Ensures users can only access records and features appropriate for their role.
- Supports Compliance: Fulfills requirements under data privacy laws like GDPR and HIPAA to restrict sensitive records.
- Limits Attack Blast Radius: If an account is compromised, the attacker cannot access resources beyond that account's specific permissions.
Limitations
- Maintenance at Scale: Managing granular permission rules across large microservice architectures requires ongoing coordination.
- Performance Considerations: Evaluating complex dynamic policies on every API call requires efficient caching.
Interview Questions
How do you design an authorization system for a microservices architecture?
A standard approach uses an API Gateway as a Policy Enforcement Point (PEP) paired with a centralized Policy Decision Point (such as Open Policy Agent). When a client sends a request with an authenticated token, the gateway forwards the user's identity, requested route, and action to the policy engine. The engine evaluates the rules and returns an allow or deny decision. For object-level checks (confirming who owns a specific record), downstream services verify tenant and ownership boundaries against the database directly.
What is 'Role Explosion' in RBAC and how does ABAC resolve it?
Role Explosion occurs when an organization attempts to handle nuanced business requirements using traditional RBAC, resulting in hundreds of specialized roles (such as BillingViewer_East or BillingEditor_Q4). ABAC solves this by keeping roles generic and dynamically evaluating conditions at runtime using attributes, such as checking if the user's department matches the document's department and if the current time is within business hours.
Practice Questions
- Review an API endpoint in your own project: Can an authenticated user view records belonging to another customer by changing an ID in the URL parameter?
- Write a simple authorization rule in code that restricts editing permissions to document owners or managers.
