Course contentsShow
← Security
Lesson 842 of 3,05217. Web Security - Authorization and Access ControlFree lesson

Resource-Level Permission Checks

Implement granular authorization at the resource level, validating ownership and permissions for every object access.

Resource-Level Permission Checks

What you'll learn: How to validate authorization for every individual object access, not just feature access.

The Missing Layer of Protection

You've learned about denying by default, enforcing authorization server-side, and centralizing your logic. But there's a critical gap: even with all that in place, you must verify permissions for each specific resource.

Think of it like a hospital. A doctor has access to patient records (feature-level permission), but they shouldn't see every patient's records—only those they're treating. Resource-level checks ensure Dr. Smith can view Patient 123's file only if Dr. Smith is actually Patient 123's physician.

Core Implementation Principles

Every object access must answer two questions:

  1. Does this user have permission to perform this action? (function-level)
  2. Does this user have permission to perform this action on this specific resource? (resource-level)

A typical vulnerable pattern:

if (user.hasRole("EDITOR")) {
    return database.getDocument(documentId);
}

This checks if the user is an editor, but not if they can edit this document.

Secure pattern:

if (user.hasRole("EDITOR") && 
    document.belongsToUser(user.id)) {
    return database.getDocument(documentId);
}

Where to Apply Resource-Level Checks

  • Before database queries: Validate ownership/permissions
  • After retrieval: Double-check before returning data
  • API endpoints: Every GET, PUT, DELETE on /documents/{id}, /users/{id}, etc.
  • Relational access: Posts, comments, attachments—check the entire chain

Resource-level checks prevent IDOR vulnerabilities, horizontal privilege escalation, and unauthorized data access even when attackers manipulate IDs or parameters.

Key Takeaway: Validating permission at the function level isn't enough—always verify the user has rights to the specific resource they're accessing before allowing any read, modify, or delete operation.