Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 38 ยท Broken Access Control

Privilege Escalation and Function-Level Access

Learn vertical and horizontal privilege escalation, missing function-level checks on admin routes, tampered roles in tokens and cookies, and how to enforce roles safely.

Privilege escalation means gaining more rights than you were given. It comes in two forms:

  • Horizontal: acting as another user at the same level (reading a neighbour's order, the IDOR pattern).
  • Vertical: acting at a higher level (a normal user calling an admin function).

This lesson focuses on vertical escalation caused by missing function-level access control: the application hides privileged features but does not block them on the server.

"Security by hidden button"

Imagine an app where only admins see a Users menu. The page for normal users simply has no link to /admin/users. But the route itself still answers anyone who requests it.

Python
# VULNERABLE: the menu is hidden, the route is open
@app.get("/admin/users")
def list_users():
    return db.all_users()           # no role check!

@app.post("/admin/users/<int:uid>/promote")
def promote(uid):
    db.set_role(uid, "admin")       # no role check!

Attackers do not click menus. They guess URLs (/admin, /api/admin/users, /manage), read your JavaScript bundle for API paths, or look at documentation. Any route that exists will be requested.

Other places privilege checks go missing:

  • Management APIs used by the mobile app but not the website.
  • Newer API versions (/v2/...) that forgot the checks of /v1/....
  • Alternative methods: GET is protected, POST or PUT is not.
  • Background-job triggers, export endpoints, debug and health routes.
  • Multi-step workflows where only step 1 checks the role and step 3 can be called directly.

Fix: check on every route, deny by default

Python A role-checking decorator

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.

In real frameworks you do not write this by hand: use route middleware groups, @PreAuthorize, [Authorize(Roles = "Admin")], Laravel gates or Django permission_required. What matters is that the default for a new route is protected, for example by putting all /admin routes under one guarded group.

Trusting client-held roles

Another path to escalation is letting the client say what its role is.

TEXT
Cookie: role=user          <-- user edits it to role=admin
POST /profile  {"isAdmin": true}
GET /dashboard?admin=true

The role must come from server-side state (the session store or database) or from a signed token whose signature the server verifies. Never from a plain cookie, form field, header or query parameter.

Python Signed role claims

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 signature covers the claims, so editing them breaks verification. The key never leaves the server. (JWT libraries add standard structure; later lessons cover their pitfalls such as accepting the none algorithm.)

Re-checking privileges at the moment of use

Roles change: an employee leaves, a user is demoted, a subscription expires. Long-lived tokens that embed the role keep granting it until they expire. Mitigations:

  • Short token lifetimes and refresh tokens.
  • A server-side revocation list or a per-user "token version" checked on each request.
  • Re-authenticate (step-up) for sensitive actions such as changing the email or deleting the account.

Separate admin surfaces

Reduce risk by isolating administration:

  • Put admin tools on a separate hostname or network path, restricted by IP, VPN or zero-trust proxy.
  • Require MFA for admin accounts.
  • Give admins narrow roles (billing admin, content admin) instead of one super role.
  • Log every administrative action with who, what and when.

A route inventory test

A simple automated defense: list all routes, and for each one declare the minimum role. Fail the build if a route has no declaration.

Python Fail the build when a route has no policy

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.

Most frameworks can print their route table, so this check is easy to automate in CI.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A normal user requests /admin/users directly and receives the user list. Which flaw is this?

    The admin route is reachable without a role check. Hiding the menu link does not protect it.
  2. 2. Where should a user's role come from?

    Anything the client controls can be forged. Only server state or a verified signature is trustworthy.
  3. 3. What is horizontal privilege escalation?

    Horizontal means same level, different user (IDOR is the typical example). Vertical means moving up to a higher role.
  4. 4. Which practice makes new routes safe by default?

    Guarded groups and a route-policy inventory ensure that a forgotten route fails closed.

Summary

  • Vertical escalation gives a user higher rights; horizontal escalation reaches other users' data.
  • Hidden menus are not controls: enforce role checks on every route, method and API version.
  • Take roles from server-side state or verified signed tokens, never from client-editable values.
  • Keep tokens short-lived, support revocation and require step-up auth for sensitive actions.
  • Isolate admin tools, use MFA, and test that every route declares a policy.

Next: Path Traversal and Forced Browsing