TExcelTAD
Home › Web Application Security: OWASP Top 10, APIs & Authentication › Authorization Models and Function-Level Access Control

Authorization Models and Function-Level Access Control

The previous lesson was about objects: may Alice read invoice 1002? This one is about functions: may Alice call DELETE /api/admin/users/7 at all? Applications often protect admin features by not showing them: the "Delete user" button only appears for administrators. But the endpoint behind the button is still there, and anyone who reads the JavaScript bundle, guesses the URL or watches an admin's traffic can call it. This is broken function-level authorization (BFLA, API5 in the OWASP API Security Top 10 2023, part of A01 Broken Access Control in the OWASP Top 10 2025). The fix needs an authorization model, a clear statement of who may do what, enforced in one place on the server. This lesson compares the common models, then builds a router that is deny-by-default and a test that proves it.

Authorization models

Model Decision based on Example rule Good for
ACL (access control list) a list of users per object "doc 9: alice rw, bob r" files, shares
RBAC (role-based) the user's roles "role support may read:tickets" most business apps; roles map to job functions
ABAC (attribute-based) attributes of user, object, action, context "a manager may approve expenses of their own department under 5,000, during office hours" fine-grained, contextual rules
ReBAC (relationship-based) a graph of relationships "viewer of a folder → viewer of its files" (Google's Zanzibar model) sharing, collaboration apps
Ownership object's owner field "users edit their own profile" the IDOR check

Real systems combine them: RBAC for functions, ownership or ReBAC for objects, ABAC for exceptions. Policy engines (Open Policy Agent, Cedar, Casbin, OpenFGA) keep the rules out of handler code.

A router that forgets, and one that can't

The vulnerable app protects the admin routes inconsistently: one checks the role, one was added later without a check, one checks only on GET. The fixed app declares the required permission on every route and refuses routes that don't declare one. A test then calls every route with every role and compares with the intended matrix.

python · try it yourself
ROLE_PERMS = {"user": {"read:own"}, "support": {"read:own", "read:users"},
              "admin": {"read:own", "read:users", "delete:users", "export:users"}}

def handlers():
    return {
        ("GET", "/api/me"):                   lambda u: f"profile of {u['name']}",
        ("GET", "/api/admin/users"):          lambda u: "list of 3 users",
        ("DELETE", "/api/admin/users/7"):     lambda u: "user 7 deleted",
        ("GET", "/api/admin/export"):         lambda u: "CSV with all users",
        ("POST", "/api/admin/export"):        lambda u: "CSV with all users",
    }

# --- vulnerable: checks sprinkled into some handlers -------------------------
def vulnerable_app(method, path, user):
    h = handlers()[(method, path)]
    if path == "/api/admin/users" and user["role"] not in ("support", "admin"):
        return "403"
    if (method, path) == ("GET", "/api/admin/export") and user["role"] != "admin":
        return "403"
    return "200 " + h(user)                   # DELETE /users/7 and POST /export: no check at all

# --- fixed: every route declares its permission; undeclared routes are refused ---
REQUIRED = {("GET", "/api/me"): "read:own", ("GET", "/api/admin/users"): "read:users",
            ("DELETE", "/api/admin/users/7"): "delete:users", ("GET", "/api/admin/export"): "export:users"}

def fixed_app(method, path, user):
    perm = REQUIRED.get((method, path))
    if perm is None:
        return "405 no such route (deny by default)"
    if perm not in ROLE_PERMS[user["role"]]:
        return "403"
    return "200 " + handlers()[(method, path)](user)

users = {"ana (user)": {"name": "ana", "role": "user"}, "sam (support)": {"name": "sam", "role": "support"},
         "ada (admin)": {"name": "ada", "role": "admin"}}
routes = list(handlers())
for name, app in [("vulnerable", vulnerable_app), ("fixed", fixed_app)]:
    print(f"== {name}")
    print(f"{'':28}" + "".join(f"{u:>16}" for u in users))
    for method, path in routes:
        cells = [app(method, path, u).split()[0] for u in users.values()]
        print(f"{method + ' ' + path:28}" + "".join(f"{c:>16}" for c in cells))

# The test that would have caught it: the intended matrix, checked for every route and role.
INTENDED = {(m, p, r): ("200" if REQUIRED.get((m, p)) in ROLE_PERMS[r] else "403/405")
            for (m, p) in routes for r in ROLE_PERMS}
failures = [(m, p, r) for (m, p, r), want in INTENDED.items()
            if (vulnerable_app(m, p, {"name": "t", "role": r}).split()[0] == "200") != (want == "200")]
print("vulnerable app, unexpected 200s:", failures)
== vulnerable
                                  ana (user)   sam (support)     ada (admin)
GET /api/me                              200             200             200
GET /api/admin/users                     403             200             200
DELETE /api/admin/users/7                200             200             200
GET /api/admin/export                    403             403             200
POST /api/admin/export                   200             200             200
== fixed
                                  ana (user)   sam (support)     ada (admin)
GET /api/me                              200             200             200
GET /api/admin/users                     403             200             200
DELETE /api/admin/users/7                403             403             200
GET /api/admin/export                    403             403             200
POST /api/admin/export                   405             405             405
vulnerable app, unexpected 200s: [('DELETE', '/api/admin/users/7', 'user'), ('DELETE', '/api/admin/users/7', 'support'), ('POST', '/api/admin/export', 'user'), ('POST', '/api/admin/export', 'support'), ('POST', '/api/admin/export', 'admin')]

The matrix makes the bug visible at a glance: in the vulnerable app an ordinary user gets 200 on DELETE /api/admin/users/7 and on POST /api/admin/export, the second because the export check was written for GET only. In the fixed app every cell follows the role table, and the POST variant, which nobody meant to offer, is refused as an undeclared route. The test at the end is the part to keep: generated from the policy, it fails the build as soon as a handler and the policy disagree.

How BFLA is detected

  • Discover functions: read the JavaScript bundles and mobile apps for API paths (/admin, /internal, /v1/), check API documentation (OpenAPI files, GraphQL introspection), and watch an admin session in your lab.
  • Call them as a low-privilege user and unauthenticated, with every HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS) and with method-override headers (X-HTTP-Method-Override: DELETE) that some frameworks honour.
  • Look for parameters that select privilege: ?admin=true, role=, /api/v1/ vs /api/v2/ (old versions often lack new checks).
  • Code review: routes without an authorization decorator or middleware; checks in the front end only; role checks by string comparison spread across handlers.
  • Logs: 200 responses on admin routes for non-admin sessions (log the role with each request so this query is possible); 403 bursts from one user on admin routes.

How it is fixed

  1. One authorization layer (middleware, decorator, policy engine) that every route passes through, deny by default: a route without a declared policy is not reachable.
  2. Permissions as data (role → permissions table), not if role == "admin" scattered across handlers.
  3. Separate admin interfaces where possible (another host name, VPN or SSO-only), which narrows who can even reach them.
  4. Automated tests generated from the policy matrix, run in CI.

Pitfalls

  • Hiding instead of protecting: removing the button is UX, not security.
  • Method confusion: protecting GET and forgetting POST/PUT, or frameworks that route HEAD to GET handlers but skip middleware.
  • Role in the token or request body taken at face value (see mass assignment and JWT pitfalls).

Practice

1. Express code: app.use('/admin', requireAdmin) followed by app.post('/Admin/users', …). Is the route protected?

It depends on case-sensitive routing settings; by default Express routing is case-insensitive, but path-matching middleware and other layers (proxies, WAF rules) may disagree. Mismatches between layers are a classic bypass. Declare the permission on the route itself.

2. Write the RBAC entry and test row for a new "refund order" function that only support staff and admins may use.

Add "refund:orders" to support and admin in ROLE_PERMS, declare ("POST", "/api/orders/{id}/refund"): "refund:orders" in REQUIRED, and let the generated matrix test check that user gets 403 and the others 200 (and pair it with an ownership/tenant check on the order).

Test yourself

What is broken function-level authorization?

  1. Reading another user's object
  2. Calling a function (often an admin endpoint) that the caller's role should not reach
  3. SQL injection in a function
  4. A slow endpoint

In the vulnerable app, why did POST /api/admin/export succeed for an ordinary user?

  1. POST is always allowed
  2. The role check was written for GET only
  3. The user had the export permission
  4. CSRF

What does 'deny by default' mean in the fixed router?

  1. Every request is denied
  2. A route without a declared permission is not reachable
  3. Admins are denied
  4. GET is denied