Skip to content

    Frontend System Design

    RBAC and ABAC on the UI

    Learn how role-based and attribute-based access control decide what a user may do, and why the UI only reflects a decision that the server enforces, with a lab.

    By Published 14 min read

    • frontend-system-design
    • authorization
    • rbac
    • abac
    Share

    Standard lessonintermediateTypeScript labFrontend System Design

    Before this: Authentication vs Authorization in the UI

    What you'll learn: By the end of this lesson you will be able to explain role-based (RBAC) and attribute-based (ABAC) access control in one decision function, say what each is good and bad at, combine roles with attribute constraints and deny rules, decide where the front end gets its show-or-hide hints, explain why a hidden button protects nothing, and handle a stale or refused action in the UI. A small TypeScript model lets you run the decisions and see the browser and the server disagree.

    Think of a hotel. The card reader on each room door decides whether you may enter. The key sleeve at the front desk, which lists your room number and floors, is a convenience: it saves you walking to the wrong corridor. If someone edits the sleeve to say "penthouse", the reader still says no. The reader is enforcement. The sleeve is a hint.

    A web front end is the key sleeve. It can show only the menu items and buttons a user is likely allowed to use, which makes the product feel right. It cannot be the reader, because everything the browser holds can be changed by whoever is sitting at it. This lesson is about the decision the reader makes (roles, attributes, rules) and what the UI does with it.

    The running example is an order dashboard used by customers and by staff of several shops. Staff can read and update orders, managers can refund them up to a limit, admins can delete them, and customers can see their own orders. Everything in the lab is made up for the lesson.

    The core idea

    1. Authorization is a decision function. Given who is asking, what they want to do and to which resource (and sometimes the context), it returns allow or deny. The same inputs always give the same answer.
    2. RBAC and ABAC are two ways to write that function. RBAC decides by roles. ABAC decides by attributes of the subject, the resource and the environment. Real systems mix them.
    3. The server enforces; the UI reflects. OWASP: "Developers must never rely on client-side access control checks." Client-side checks may improve the user experience, but "should never be the decisive factor in granting or denying access to a resource".

    This lesson builds on the lesson on authentication versus authorization in the UI (planned in this course, so there is no link yet): authentication says who you are, and everything here is about what that person may do.

    Roles: RBAC

    NIST describes role-based access control as managing security at a level that corresponds closely to the organization's structure: each user is assigned one or more roles, and each role is given one or more privileges that apply to everyone in it. OWASP's definition is that access is "granted or denied based upon the roles assigned to a user".

    For the dashboard: support may read and update orders, manager may also refund, admin may also delete. Roles can inherit: in the lab a manager has everything a support agent has. NIST's page also mentions mutually exclusive roles and role hierarchies as things RBAC software handles.

    RBAC is easy to explain, audit and put in a menu, but a role says what a kind of user may do, not on which record: "managers can refund" says nothing about the order's shop or amount. Encoding that in roles produces role explosion, which OWASP names as a trade-off of RBAC (too many roles defined to cover every case), and OWASP warns that with RBAC it is "easy to miss or improperly perform role checks".

    Attributes: ABAC

    NIST describes ABAC as controlling access to objects by evaluating rules against the attributes of the subject and the object, the requested action and the environment. NIST's special publication 800-162 is the definition document (the January 2014 edition was withdrawn in 2019 and superseded by an updated version). OWASP's wording: decisions use "characteristics that can be represented as name-value pairs".

    • Subject attributes: department, shop, refund limit, clearance.
    • Object (resource) attributes: owner, shop, status, amount.
    • Environment attributes: time, network, device.

    A rule such as "a refund must not exceed the refund limit of the person" compares an attribute of the resource with an attribute of the subject. NIST notes that changing attribute values changes decisions without rewriting every subject-to-object relationship, and that a new subject who holds the right attributes gains access without a rule change. The cost, per OWASP, is that the initial setup is more complex than RBAC. OWASP also describes relationship-based control (ReBAC), where access depends on relationships between resources, such as the creator of a post being allowed to edit it, and says ABAC and ReBAC "should typically be preferred for application development".

    One decision function

    The lab combines the two in a single function. This is the lab's own design, chosen for teaching, not a standard.

    1. A deny rule that matches ends the decision with deny (for example "nobody refunds an order they placed", or "a frozen order cannot be changed").
    2. A role grant gives the permission. It counts only if every constraint for that action holds (same shop; refund within the limit).
    3. An allow rule can grant from attributes alone (a customer reads their own order).
    4. Otherwise: deny by default.

    A condition whose attribute is missing is never "true": an allow rule or constraint that needs it grants nothing, and a deny rule that needs it applies. The model fails closed.

    Figure 1. The decision order

    flowchart TD accTitle: Order of an authorization decision accDescr: Deny rules are checked first and end the decision with deny. Then a role grant is checked together with its attribute constraints. Then attribute-only allow rules. If nothing grants the action, it is denied by default. A["Request: who, action, resource"] --> B{"A deny rule
    matches?"} B -->|"yes"| D["Deny, with the rule's reason"] B -->|"no"| C{"A role grants it and
    every constraint holds?"} C -->|"yes"| OK["Allow"] C -->|"no"| E{"An allow rule
    matches?"} E -->|"yes"| OK E -->|"no"| F["Deny by default"]

    How to read this: the order is the policy. Putting deny first means no role, however powerful, can override it. Reaching the bottom means nothing granted the action, which is the safe default.

    OWASP gives the two principles behind it: "an application should be configured to deny access by default", and users should get only the minimum privileges they need (it also warns about "privilege creep" as people change jobs).

    What the front end does

    The UI has three jobs, and none is enforcement.

    1. Reflect the decision. Show, hide or disable menu items and buttons so people are not offered what they cannot do.
    2. Survive refusal. Its picture can be stale or wrong, so a 403 is a normal answer to handle, not an exception.
    3. Keep one source of truth. Ask the server which actions are available for a record, or ship the permission data it computed, rather than re-implementing the rules in the browser where they drift.

    Figure 2. Hints in the browser, decisions on the server

    The UI shows hints from its own copy; the API decides with its own dataUI to API (request + session); API to Policy (decide); API to Records (load record); API to UI (200 or 403)TRUSTED: YOUR SERVERSUI: buttons, routesUIbuttons, routesAPI: enforcesAPIenforcesPolicy: roles, rulesPolicyroles, rulesRecords: owner, shopRecordsowner, shoprequest + sessiondecideload record200 or 403

    How to read this: only the zone on the right is trusted. The UI box is a hint-maker: whatever it holds can be stale or edited. The API looks up the user and the record itself and runs the policy.

    Figure 3. A stale button and a refused click

    sequenceDiagram accTitle: A stale button and a refused action accDescr: A manager is demoted on the server while a page is open. The page still shows the refund button. The user clicks, the API denies with 403, and the UI refreshes its permissions and hides the button. participant U as User participant P as Page participant A as API Note over P: loaded while the user was a manager A->>A: role changed to support U->>P: clicks Refund P->>A: POST refund A-->>P: 403 (not allowed) P->>A: reload permissions A-->>P: refund not available P->>U: hide Refund, explain

    How to read this: the refusal is the real control. The UI's job after it is to correct itself and tell the user why, instead of retrying or showing "something went wrong".

    Where the hints come from

    Approach Gain Cost
    Send the user's role list and test roles in components Simple Checks scattered through components; roles say nothing about a record; stale after a change
    Send the policy and evaluate it in the browser One engine, instant Leaks rules; stale; two copies to keep identical
    API returns allowed actions with each record One source of truth; per-record attributes included A field to compute for every record and every list

    The third is the usual choice when decisions depend on record attributes, because only the server has them all.

    Three illustrations

    Illustration 1 (minimal). The delete button is hidden for non-admins by if (user.role === "admin"). The DELETE endpoint is still there. Anyone can send the request with curl and their own session, so what the button controls is how many people notice the endpoint exists. OWASP: "an attacker only needs to find one way in".

    Illustration 2 (realistic). The dashboard. A support agent opens an order of their own shop and sees Update, no Refund. A manager of another shop sees nothing actionable, because the constraint "same shop" fails although their role would grant refunds. A large refund is refused by the limit attribute, and a manager can never refund an order they placed. The server runs all of this and the UI shows the result per record.

    Illustration 3 (failure). An order page keeps a manager's permissions in memory. The manager is demoted in the morning and the tab stays open, so the Refund button remains. If the API checks only that the caller is signed in, the click succeeds. If it checks the role, it answers 403 and the UI needs a way to recover.

    Choosing a model

    Figure 4. Which approach for which rule

    flowchart TD accTitle: Choosing between roles and attributes accDescr: If the rule depends only on what kind of user it is, use a role. If it depends on the record or the context, add an attribute constraint or an allow rule. If it must never happen, write a deny rule. Enforce everything on the server. A{"What does the rule
    depend on?"} -->|"kind of user"| R["Role permission"] A -->|"the record or context"| T["Attribute constraint
    or allow rule"] A -->|"must never happen"| X["Deny rule"] R --> S["Enforce on the server,
    show the result in the UI"] T --> S X --> S

    How to read this: roles answer "what kind of person", attributes answer "which record, which context", deny rules answer "never". All three end in the same place: the server decides.

    Approach Good at Weak at
    RBAC Simple, auditable, easy to show in menus Per-record rules; role explosion
    ABAC Per-record and context rules; fewer roles More setup; harder to explain who can do what
    ReBAC "Owner of this", "member of that" Needs relationship data
    Roles + attributes + deny Most business rules Needs a clear evaluation order and tests

    The other side of this topic

    The server has to implement the decision, usually through a policy engine or a shared library, and to load the record's attributes before it decides. A later back-end lesson on authorization models covers that half. The front-end skill is knowing that the decision lives elsewhere, and designing screens that stay correct when it changes.

    Build it: run the decisions

    Goal. Evaluate a small policy against six people and five orders, with a reason for each answer. Compare roles alone with roles plus attributes, and compare what a browser's copy of the user says with what the server decides.

    Setup. The lab lives in the course's example workspace. It needs Node.js (captured on Node 26.13.1, which runs TypeScript directly) and pnpm. It has no browser, no network and no real login: a session table stands in for authentication.

    cd examples/frontend
    pnpm install
    pnpm --filter ./labs/rbac-abac-model test   # 31 tests
    cd labs/rbac-abac-model
    node src/demo.ts

    Steps.

    1. In section 2, predict each line before reading its reason. Find the refund that the role allows but a constraint refuses (mia, order o-101), and the one a deny rule refuses (mia, her own order).
    2. In section 3, find the five requests where roles alone give a different answer from roles plus attributes. One goes the other way: a customer can read their own order because of an allow rule, not a role.
    3. In section 4, part a) has a current browser copy and the buttons match the server. In parts b) and c) they do not, and only the 403 stops the action.
    4. Read decide in src/model.ts. It is the four steps of Figure 1, in order.

    The core of the server side is this short:

    const subject = userId === undefined ? undefined : state.users.get(userId);
    if (subject === undefined) return { status: 401, reason: "no valid session" };
    // ...find the resource in the server's own store...
    const decision = decide(state.policy, subject, request.action, resource);
    return decision.effect === "allow" ? { status: 200, reason: decision.reason } : { status: 403, reason: decision.reason };

    Expected output, captured from a real run (Node 26.13.1, 2026-12-01):

    Authorization model: roles, attributes, a decision and a reason
    
    === 1. The policy is data: what each role grants (inheritance included)
    customer  (nothing from the role)
    support   order.read, order.update
    manager   order.read, order.refund, order.update
    admin     order.delete, order.read, order.refund, order.update, user.manage
    constraints on role grants: same-tenant, refund-limit
    allow rules (attributes only): owner-reads-own, owner-cancels-own-open
    deny rules (override all):     no-self-refund, frozen-order
    
    === 2. Decisions, each with its reason
    ALLOW  sam order.update on o-100 (shop t1, owner ana, open, 4500)
             role support grants order.update; constraints hold: same-tenant
    deny   sam order.refund on o-100 (shop t1, owner ana, open, 4500)
             no role grants order.refund and no allow rule matches (default deny)
    ALLOW  mia order.refund on o-100 (shop t1, owner ana, open, 4500)
             role manager grants order.refund; constraints hold: same-tenant, refund-limit
    deny   mia order.refund on o-101 (shop t1, owner ben, shipped, 52000)
             role manager grants order.refund, but constraint refund-limit is not met: the order amount must not exceed the refund limit of the person
    deny   mia order.refund on o-mia (shop t1, owner mia, shipped, 1500)
             denied by rule no-self-refund: nobody refunds an order they placed
    deny   max order.refund on o-100 (shop t1, owner ana, open, 4500)
             role manager grants order.refund, but constraint same-tenant is not met: staff work only on orders of their own shop
    ALLOW  max order.refund on o-200 (shop t2, owner ben, open, 3000)
             role manager grants order.refund; constraints hold: same-tenant, refund-limit
    ALLOW  ana order.read on o-100 (shop t1, owner ana, open, 4500)
             allowed by rule owner-reads-own: a customer may read their own orders
    deny   ana order.read on o-101 (shop t1, owner ben, shipped, 52000)
             no role grants order.read and no allow rule matches (default deny)
    deny   ben order.read on o-200 (shop t2, owner ben, open, 3000)
             no role grants order.read and no allow rule matches (default deny)
    ALLOW  ana order.cancel on o-100 (shop t1, owner ana, open, 4500)
             allowed by rule owner-cancels-own-open: a customer may cancel their own open order
    deny   ana order.cancel on o-102 (shop t1, owner ana, frozen, 900)
             denied by rule frozen-order: a frozen order cannot be changed
    ALLOW  ada order.delete on o-101 (shop t1, owner ben, shipped, 52000)
             role admin grants order.delete; constraints hold: same-tenant
    deny   ada order.delete on o-102 (shop t1, owner ana, frozen, 900)
             denied by rule frozen-order: a frozen order cannot be changed
    ALLOW  ada user.manage
             role admin grants user.manage
    deny   ada order.teleport on o-100 (shop t1, owner ana, open, 4500)
             no role grants order.teleport and no allow rule matches (default deny)
    
    === 3. Roles alone against roles plus attributes (same requests)
    max order.refund on o-100: roles only -> allow, with attributes -> deny   <- differs
    mia order.refund on o-101: roles only -> allow, with attributes -> deny   <- differs
    mia order.refund on o-mia: roles only -> allow, with attributes -> deny   <- differs
    ada order.delete on o-102: roles only -> allow, with attributes -> deny   <- differs
    ana order.read on o-100: roles only -> deny, with attributes -> allow   <- differs
    illustrative count: 4 base roles x 3 shops x 3 refund-limit tiers = 36 roles to encode in roles alone, against 4 roles plus 2 attributes
    
    === 4. The browser decides what to show, the server decides what happens
    a) mia, browser copy is current
      order.read    button shown   server 200
      order.update  button shown   server 200
      order.refund  button shown   server 200
      order.delete  button hidden  server 403
    b) mia is demoted to support on the server; the open page still holds the old copy
      order.read    button shown   server 200
      order.update  button shown   server 200
      order.refund  button shown   server 403   <- the UI and the server disagree
      order.delete  button hidden  server 403
    c) ana edits her copy of the user in the browser to say admin, and sends claimedRoles too
      order.read    button shown   server 200
      order.update  button shown   server 403   <- the UI and the server disagree
      order.refund  button hidden  server 403
      order.delete  button shown   server 403   <- the UI and the server disagree
    
    In b) and c) the browser held a wrong picture of the user, and only the server's 403 stopped the action.

    What the lab does not show. It is a model, not a product: no authentication, tokens, ReBAC, time or location attributes, audit log or decision caching, and no list endpoints (filtering a list by permission is a query problem). Its way of combining roles, constraints, allow and deny rules is one simple design. The count of 36 roles in section 3 is plain multiplication with made-up numbers.

    Break it. In src/model.ts, in decide, change for (const rule of policy.deny) { to for (const rule of [] as readonly Rule[]) {, so no deny rule is ever read. The demo then lets a manager refund their own order and an admin delete a frozen one, and four tests fail. Put the line back.

    Stretch. Add a relationship predicate (resource.projectId is in subject.projects) and write its tests first, or add a decision log that records which rules were evaluated.

    In practice: refunds on a support dashboard

    NOTE

    This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.

    The situation

    A support dashboard gains a Refund action. The first version hides the button unless user.role === "manager", a check repeated in five components. The refund API checks that the caller is signed in. Managers belong to one shop each, and each has a refund limit. Two reviewers ask the same question: what stops a support agent from calling the endpoint directly, and what stops a manager from refunding another shop's orders?

    Starting architecture

    Figure 5. Starting point: the check lives in the browser

    Starting architecture: the role check is in the UI and the API only checks that a user is signed inDashboard to Refund API (POST refund); Refund API to Orders (refund)Dashboard: role checksDashboardrole checksRefund API: signed in onlyRefund APIsigned in onlyOrders: all shopsOrdersall shopsPOST refundrefund

    How to read this: both warning boxes are the problem. The only role check can be skipped, and the API accepts any signed-in caller for any order.

    Options considered

    Option What it fixes What it costs Risk
    Check the role in the API too Agents cannot refund A role check per endpoint Easy to miss one; ignores shop and amount
    Policy with roles, constraints and deny rules, evaluated on the server Shop, limit and self-refund rules are enforced A policy to write, test and review Must be applied on every route
    Server returns allowed actions per order One source of truth for buttons A field on each record Stale until reloaded

    The decision

    Field Decision record
    Context Refund is allowed only for managers, within their shop and limit, never on their own orders.
    Decision Run one policy on the server for every endpoint, deny by default. The order API returns the allowed actions with each order, and the UI renders from that field. A 403 makes the UI reload that field.
    Consequences, good The browser cannot grant anything; rules change in one place; reasons are available for support.
    Consequences, bad Every list response computes permissions per row; the UI is only as fresh as its last load.
    Revisit when Per-row cost matters (cache decisions briefly) or rules need relationships (add them).

    Rollout and verification

    1. Write the policy tests first: table-driven cases for each person and order, including the denials, from the decision function.
    2. Check every route calls the policy, with a test that lists the API's routes and fails for any that does not.
    3. Test the stale path: change a role on the server while a page is open and confirm the next click gives a refusal the UI handles.
    4. Add monitoring for the rate of 403 by action, so a sudden rise shows either an attack or a broken rule.

    The 2 a.m. failure

    Support reports that Refund "does nothing" for one manager after a team change. The button is visible and clicking shows a spinner for a few seconds, then a generic error. Logs show the same POST repeated three times.

    The cause is the UI. The manager was moved to support, the API now answers 403, and the page's generic error handler treats every failure as a network error and retries. The page also still shows the old button because it never reloads the permission field after a refusal.

    First three checks: (1) read the API log for the status and the decision reason; (2) check the page's error handler for which statuses it retries; (3) compare the allowed actions the page holds with what the server returns now. Mitigation: stop retrying 403 and reload the permission field when one arrives. Follow-up: show the server's reason when it is safe to, and add a test that a 403 hides the action.

    Architect's notes

    • Put the rules in one place on the server, and make the UI a consumer of its answers.
    • Fail closed: a missing attribute or an unknown action denies.
    • Treat a 403 as an ordinary result in the UI: refresh, explain, never retry.
    • Test denials as carefully as allowances, and test that every route calls the policy.
    • Use attributes for per-record rules, roles for coarse grouping, and review privileges as people move.

    Common mistakes

    • Hiding a button and calling it authorization. The endpoint is still there.
    • Trusting roles or "isAdmin" sent by the browser. The server must look the user up itself.
    • Checking the action but not the object. Access to one order is not access to all orders.
    • Retrying a 403, or showing a generic error for it.
    • Keeping the browser's copy of permissions for the whole session with no refresh path.

    Key takeaways

    • Authorization is a function from subject, action and resource (and context) to allow or deny.
    • RBAC decides by roles; ABAC by attributes of the subject, resource and environment; most systems mix them.
    • Roles are coarse; per-record rules need attributes, or roles multiply.
    • A good evaluation order is deny rules, role grants with constraints, allow rules, then deny by default, and missing attributes fail closed.
    • The server decides on every request; client-side checks are for the user experience only.
    • The UI gets its hints from server-computed answers, and treats 403 as a normal result.
    • Test denials, and test that every route checks.

    Practice exercises

    Exercise 1 — Starter (30 min): For three actions on a system you know, write who may do each, and mark whether it depends on the kind of user, the record or the context.

    Exercise 2 — Intermediate (2 hours): In the lab, add a rule that a support agent can update an order only while it is open, and a test for each outcome. Predict the demo output change before you run it.

    Exercise 3 — Advanced (half day): Design the UI side for a list of 50 orders: where the allowed actions come from, what happens after a 403, how stale data is refreshed and what you monitor.

    In this course:

    Elsewhere on the site:

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments