RBAC vs ABAC Authorization

01 Min
πŸ”„
Course In Progress In Progress

This article belongs to the AuthN & AuthZ course, which is actively in development with new lessons rolling out regularly.

After authentication, the next big question is:

β€œWhat is this user allowed to do?”

This is the domain of authorization.
Two common models dominate modern systems:

  • RBAC (Role-Based Access Control)
  • ABAC (Attribute-Based Access Control)

Both aim to restrict access, but they take very different approaches.


RBAC (Role-Based Access Control)

RBAC is the simpler and most widely used model.
Users are assigned roles, and each role carries a set of permissions.

RolePermissions
UserRead posts
EditorEdit articles
AdminManage users

Instead of attaching permissions directly to every user:

User β†’ Role β†’ Permissions

Arjit β†’ Admin
John β†’ Editor
Sarah β†’ User

The role determines what actions are allowed.

Implementing RBAC in Express.js

  • User logs in
  • System loads their role
  • Request checks required role
  • Access granted or denied
function requireRole(role) {
  return (req, res, next) => {
    if (req.user.role !== role) {
      return res.status(403).send("Forbidden");
    }
    next();
  };
}

app.delete("/users/:id", auth, requireRole("admin"), async (req, res) => {
  res.send("User deleted");
});

Only admins can delete users.


ABAC (Attribute-Based Access Control)

ABAC is more flexible. Instead of just roles, it evaluates attributes. Attributes can belong to:

  • User β†’ department, country, clearance level
  • Resource β†’ owner, project ID, classification
  • Request β†’ method, IP address, endpoint
  • Environment β†’ time, device type, location

How ABAC Works Instead of asking β€œIs this user an admin?” ABAC asks β€œCan this user perform this action on this resource under these conditions?”

Implementing ABAC in Express.js

function canEditDocument(req, res, next) {
  const document = req.document;

  if (document.ownerId !== req.user.id) {
    return res.status(403).send("Forbidden");
  }

  next();
}

Here, access depends on user ID vs document owner ID, not role