Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 38 ยท Broken Access Control

Access Control Fundamentals (A01)

Learn what broken access control is, the difference between authentication and authorization, deny-by-default, RBAC and ownership checks, with a runnable policy engine in Python.

Broken Access Control is the number one category in the 2021 OWASP Top 10. Access control is the set of rules that decide who may do what to which thing. When those rules are missing, incomplete or only enforced in the browser, users can read other people's data, change records they should not touch, or perform administrator actions.

It ranks first because it is hard to automate: a scanner cannot know that user 17 must not see user 18's invoice. Only the developers know the business rules, so only they can encode them.

Authentication versus authorization

  • Authentication (authn) proves who you are: password, passkey, MFA.
  • Authorization (authz) decides what that identity may do.

A common failure is checking the first and forgetting the second. "The user is logged in" is not the same as "the user may open this record". Every request that touches protected data needs both.

Three questions for every request

  1. Who is calling? (the authenticated subject)
  2. What action? (read, create, update, delete, approve)
  3. On which object? (this order, this file, this account)

Rules that only answer the first two ("customers can read orders") produce the most common flaw: reading any order. The third question, ownership or relationship to the object, is the one developers forget.

Access control models

Model Idea Example
RBAC (role-based) Permissions belong to roles; users get roles admin, editor, viewer
ABAC (attribute-based) Rules use attributes of user, object and context "Managers may approve expenses under $5,000 from their own department"
ReBAC (relationship-based) Rules follow relationships "Members of the project may read its files"
ACL (access control list) Each object lists who may access it A shared document with named readers

Real applications mix them: roles for broad rights, ownership or relationship checks for individual objects.

Principles

  • Deny by default. If no rule explicitly allows an action, refuse it. New endpoints are then safe until someone opens them deliberately.
  • Least privilege. Give each role the smallest set of permissions that gets the job done.
  • Enforce on the server, in one place. A central policy layer (middleware, policy classes, a decorator) is easier to audit than checks scattered across hundreds of handlers.
  • Re-check every time. Do not assume a previous page's check still applies.
  • Log denials. Repeated denied requests are a signal of probing (see detection later in the track).
Python A deny-by-default policy engine

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The last row shows the value of deny-by-default: an unknown role gets nothing, instead of everything.

Ownership checks

Roles are not enough for data that belongs to individuals. "Customers may read orders" must really mean "customers may read their own orders". The check compares the object's owner (or a membership table) with the authenticated user.

Python Role plus ownership

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Returning the same 404 for "missing" and "forbidden" avoids telling an attacker which ids exist. The next lessons show what happens when this check is left out (see IDOR).

Where to enforce

flowchart TD
  A["Request"] --> B["Authentication middleware"]
  B --> C["Route-level rule: role allowed here?"]
  C --> D["Load the object"]
  D --> E["Object-level rule: owner or member?"]
  E --> F["Perform action"]
  F --> G["Log result"]

Two layers: a coarse route check and a precise object check. Missing either one leaves a gap.

Frameworks help: Laravel has policies and gates, Django has permissions, Spring has method security, Express has middleware. Use them instead of hand-written if statements in each handler.

Common mistakes

  • Checking permissions only when rendering the menu, not on the endpoint.
  • Trusting values from the client (role=admin in a cookie, a hidden user_id field).
  • Writing an "admin" check once and forgetting it on the matching API route or export endpoint.
  • Allowing a method you did not test: the page denies GET but the same URL accepts PUT.
  • Letting authorization depend on a URL pattern that can be bypassed with a different case, trailing slash or encoding.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does deny by default mean?

    With deny-by-default, a forgotten rule fails safely. Allow-by-default makes every omission a vulnerability.
  2. 2. A customer is logged in and requests /invoices/55, which belongs to someone else. Which check is missing if it succeeds?

    The user is authenticated, but nothing verified that invoice 55 belongs to them. That is an ownership check.
  3. 3. Where must access control be enforced?

    Clients can be bypassed. The server is the only place that is trusted to enforce rules.
  4. 4. Which model grants permissions through roles like editor and viewer?

    Role-based access control assigns permissions to roles, and users receive roles.
  5. 5. Why return the same 404 for missing and forbidden objects?

    Different responses leak existence. A uniform answer reveals nothing.

Summary

  • Broken access control means users can act outside their intended permissions; it is the top Top 10 category.
  • Authentication says who you are; authorization says what you may do, and both are needed on every request.
  • Ask who, which action and which object; ownership checks are the commonly forgotten part.
  • Use deny by default, least privilege and one central policy layer on the server.
  • Do not rely on hidden menus, client-side flags or unverified user-supplied roles.

Next: IDOR and Object-Level Authorization