SyntaxPilot
Courses/Cybersecurity Fundamentals/Lesson 37
Video coming soonThis lesson’s video is being made

Start with the notes below; the video appears here as soon as it is on YouTube.

Cybersecurity Fundamentals · Lesson 37 of 90

Broken access control and IDOR

broken access controlIDORhorizontal privilege escalationvertical privilege escalationmissing function-level access controlforced browsingserver-side authorization checksobject ownership checksdeny by default in codeunguessable IDs are not access controlaccess-control unit testssecure fix on a toy app

These are the notes for Cybersecurity Fundamentals (defensive), episode 37. Episode 36 introduced the OWASP Top 10; today we take on its number one risk, broken access control. Neha changes one number in her order page and sees someone else's order. From there we invent the object ownership check, learn why unguessable IDs are not access control, meet horizontal and vertical privilege escalation, missing function-level access control and forced browsing, and finish with deny by default in code and access-control unit tests. Every term is explained the first time it appears, and the Glossary at the end defines them all again.

Neha, Ravi, Asha, the shop and every value are made up, and everything runs locally on toy data: the "servers" are small Python functions that model the rules. Only ever test access control on systems you own or are explicitly authorised to test. Every code sample runs with Python 3 (standard library only); outputs are real, copied from actual runs.

The problems you'll solve

Problem Idea it teaches
Changing /orders/1042 to /orders/1043 shows Ravi's order Authentication vs authorization, IDOR, horizontal privilege escalation
How should the server say no? Object ownership check, 404 vs 403
"Just use random IDs" Unguessable IDs are not access control
An admin page hidden from the menu Vertical privilege escalation, missing function-level access control
Files and pages nobody linked to Forced browsing, security through obscurity
A new route someone forgot to protect Deny by default in code
A teammate's "quick fix" breaks a rule Access-control unit tests, logging denials

Problem 1: change one number

Neha orders a kilo of masala chai. She is logged in, and her order page is /orders/1042. Out of curiosity she edits the address bar to /orders/1043: no tool, no skill, just a different number.

Demo 1: a server that only checks the login

# A toy order API. It checks you are LOGGED IN... and nothing else.
ORDERS = {1042: {"owner": "neha", "item": "masala chai 1 kg", "address": "Flat 4B, Pune"},
          1043: {"owner": "ravi", "item": "phone charger",    "address": "House 12, Jaipur"}}
SESSIONS = {"tok-neha": "neha", "tok-ravi": "ravi"}       # session cookie -> user

def get_order(token, order_id):
    user = SESSIONS.get(token)
    if user is None:
        return "401 please log in"
    order = ORDERS.get(order_id)
    return f"200 {order['item']}, {order['address']}" if order else "404 not found"

print("Neha, her order :", get_order("tok-neha", 1042))
print("Neha, edits URL :", get_order("tok-neha", 1043))
print("no cookie       :", get_order(None, 1042))

Output (real run):

Neha, her order : 200 masala chai 1 kg, Flat 4B, Pune
Neha, edits URL : 200 phone charger, House 12, Jaipur
no cookie       : 401 please log in

The server checked who Neha is (she has a valid session cookie) but never asked whether order 1043 is hers. Being logged in is not the same as being allowed.

Authentication vs authorization

  • Authentication answers who are you? It's the login (episode 28): a password, a passkey, a session cookie.
  • Authorization answers may you do this, to this thing? Example: Neha may view order 1042, not 1043.
  • Access control is enforcing authorization on every request.
  • Broken access control is when a user can act outside their intended permissions: read, change or delete data, or use functions, they shouldn't.
  • An object is any record the app stores: an order, an invoice, a profile. A direct object reference is its identifier (1043) taken from the request.
  • IDOR (insecure direct object reference): the server uses an identifier from the request to fetch an object without checking the user may access it. MITRE's name is CWE-639, Authorization Bypass Through User-Controlled Key.
  • A privilege is something you're allowed to do. Privilege escalation is gaining privileges you shouldn't have.
  • Horizontal privilege escalation: reaching another user's data at the same level (customer Neha reads customer Ravi's order).

Real-life example: the railway cloak room. A careless clerk fetches whichever bag matches the token number. A good clerk also checks the name on the receipt. The server must be the good clerk.

The fix: an object ownership check

Demo 2: check the owner of every object

# The fix: an OBJECT OWNERSHIP check, on the server, for every object
ORDERS = {1042: {"owner": "neha", "item": "masala chai 1 kg"},
          1043: {"owner": "ravi", "item": "phone charger"}}
SESSIONS = {"tok-neha": "neha", "tok-ravi": "ravi"}

def get_order(token, order_id):
    user = SESSIONS.get(token)
    if user is None:
        return "401 please log in"
    order = ORDERS.get(order_id)
    if order is None or order["owner"] != user:      # not yours? same answer as missing
        return "404 not found"
    return f"200 {order['item']}"

for who, oid in [("tok-neha", 1042), ("tok-neha", 1043), ("tok-ravi", 1043), ("tok-neha", 9999)]:
    print(f"{who:9} order {oid}: {get_order(who, oid)}")

Output (real run):

tok-neha  order 1042: 200 masala chai 1 kg
tok-neha  order 1043: 404 not found
tok-ravi  order 1043: 200 phone charger
tok-neha  order 9999: 404 not found

Points to notice:

  • The user comes from the server-side session, never from a user name or ID the request sends.
  • Not yours and not there give the same answer (404 not found). A 403 forbidden would confirm that order 1043 exists, which itself leaks information (how many orders the shop has, which IDs are real).
  • Check for a missing object before reading its owner; otherwise a missing order crashes the server (see Common mistakes).

Problem 2: "just use unguessable IDs"

A teammate suggests long random IDs instead of checks. Random IDs stop people counting through records (1042, 1043, 1044...), but IDs leak: they're pasted into support chats, stored in server and proxy logs, shown in screenshots, sent in emailed links and browser history.

Demo 3: a leaked random ID

# "Just use unguessable IDs!" Random IDs make guessing hard... but IDs leak.
import secrets
INVOICES = {}
def new_invoice(owner, text):
    iid = secrets.token_hex(16)                        # 128 random bits: can't be guessed
    INVOICES[iid] = {"owner": owner, "text": text}
    return iid

def get_invoice_no_check(iid):        return INVOICES.get(iid, {}).get("text", "404")
def get_invoice_checked(user, iid):
    inv = INVOICES.get(iid)
    return inv["text"] if inv and inv["owner"] == user else "404 not found"

iid = new_invoice("neha", "Invoice: Rs 84,200, PAN on file")
print("Neha's invoice id:", iid)
leaked = iid          # pasted in a support chat, saved in a proxy log, shown in a screenshot...
print("ravi, no check  :", get_invoice_no_check(leaked))
print("ravi, checked   :", get_invoice_checked("ravi", leaked))
print("neha, checked   :", get_invoice_checked("neha", leaked))

Output (real run):

Neha's invoice id: 935395f2662e1c339d6cf65c28c10f88
ravi, no check  : Invoice: Rs 84,200, PAN on file
ravi, checked   : 404 not found
neha, checked   : Invoice: Rs 84,200, PAN on file

(The invoice ID is different on every run: secrets.token_hex(16) gives 128 random bits from a CSPRNG, a cryptographically secure random number generator, episode 10.)

Unguessable IDs are not access control. They're a useful extra layer (defence in depth), but the ownership check is what actually protects the data.

Problem 3: the hidden admin page

Real-life example: a staff-only door with no lock. Taking the sign off the door doesn't stop a customer who walks in. A lock does.

  • A role is a named group of permissions, like customer or admin.
  • Vertical privilege escalation: an ordinary user gains a higher level's powers (a customer issues refunds like an admin).
  • Missing function-level access control: a function (a page, an API endpoint, an action) doesn't check the caller's role on the server. Hiding the link in the menu is not a check.

Demo 4: hidden vs checked

# Vertical escalation: the admin page is HIDDEN from the menu, but never CHECKED
USERS = {"tok-neha": {"name": "neha", "role": "customer"},
         "tok-asha": {"name": "asha", "role": "admin"}}

def menu(user):                                   # the UI: customers never SEE the link
    return ["orders", "profile"] + (["admin/refunds"] if user["role"] == "admin" else [])

def handle_hidden_only(token, path):              # the server: forgot the role check
    user = USERS[token]
    if path == "admin/refunds": return "200 refund Rs 5000 issued"
    return f"200 {path} page"

def handle_checked(token, path):
    user = USERS[token]
    if path.startswith("admin/") and user["role"] != "admin":
        return "403 forbidden"
    if path == "admin/refunds": return "200 refund Rs 5000 issued"
    return f"200 {path} page"

print("neha's menu       :", menu(USERS["tok-neha"]))
print("hidden only, neha :", handle_hidden_only("tok-neha", "admin/refunds"))   # typed by hand
print("checked, neha     :", handle_checked("tok-neha", "admin/refunds"))
print("checked, asha     :", handle_checked("tok-asha", "admin/refunds"))

Output (real run):

neha's menu       : ['orders', 'profile']
hidden only, neha : 200 refund Rs 5000 issued
checked, neha     : 403 forbidden
checked, asha     : 200 refund Rs 5000 issued

Hiding links, disabling buttons, or checking the role in JavaScript only changes what people see. Never trust the client (episode 36). The same goes for a role stored in an editable cookie or hidden form field (role=admin): the role must come from the server's own records. OWASP also lists APIs that check GET but forget POST, PUT and DELETE: every method needs the check.

Problem 4: forced browsing

  • Forced browsing means requesting URLs the site never linked to, by guessing common names: /admin, /backup.zip, /debug, /reports/2026-q3.pdf.
  • Relying on nobody knowing the URL is security through obscurity (episode 3): it fails as soon as the name is guessed or found.
  • Defenders do the opposite on their own app: list every path the app serves and check which answer without a login. Only an explicit list of public pages should.

Demo 5: a defender's anonymous-access review of our own toy app

# Forced browsing: a defender's check of which paths answer WITHOUT logging in (our own toy app)
APP = {"/": "home", "/login": "login form", "/orders": "LOGIN REQUIRED",
       "/admin": "LOGIN REQUIRED", "/backup.zip": "db dump, 2.1 MB",     # forgotten file!
       "/debug": "stack traces + config", "/reports/2026-q3.pdf": "sales report"}
PUBLIC = {"/", "/login"}                    # what SHOULD be reachable without a login

def anonymous_get(path):
    return APP.get(path, "404")

for path in ["/", "/login", "/orders", "/admin", "/backup.zip", "/debug", "/reports/2026-q3.pdf"]:
    reply = anonymous_get(path)
    open_ = reply not in ("LOGIN REQUIRED", "404")
    flag = "  <-- should NOT be public" if open_ and path not in PUBLIC else ""
    print(f"{path:22} {reply:24}{flag}")

Output (real run):

/                      home                    
/login                 login form              
/orders                LOGIN REQUIRED          
/admin                 LOGIN REQUIRED          
/backup.zip            db dump, 2.1 MB           <-- should NOT be public
/debug                 stack traces + config     <-- should NOT be public
/reports/2026-q3.pdf   sales report              <-- should NOT be public

Fixes: remove backups, dumps and debug pages from production entirely; put everything else behind the same server-side check; disable directory listing (the server showing a folder's file list) and keep backup files and metadata (such as .git) out of the web root.

Problem 5: deny by default in code

Real-life example: the office guest list. A guard with a list of troublemakers lets every newcomer in (allow by default). A guard with a guest list keeps newcomers out until someone adds them (deny by default).

OWASP's first prevention advice for access control: except for public resources, deny by default. In code, that means one central check that every request passes through, and that refuses unless a rule explicitly allows.

Demo 6: routes must declare who may use them

# Deny by default: every route must DECLARE who may use it, or nobody can
ROUTES = {}
def route(path, allow=None):                   # allow = set of roles; None = not declared
    def register(fn):
        ROUTES[path] = (fn, allow)
        return fn
    return register

@route("/orders", allow={"customer", "admin"})
def orders(user): return "your orders"
@route("/admin/refunds", allow={"admin"})
def refunds(user): return "refund issued"
@route("/admin/export")                        # a new route... someone forgot `allow`
def export(user): return "ALL customers' data"

def dispatch(path, role):
    fn, allow = ROUTES[path]
    if not allow or role not in allow:          # undeclared or not listed -> DENY
        return "403 forbidden"
    return "200 " + fn(role)

for path in ROUTES:
    print(f"{path:15} customer: {dispatch(path, 'customer'):17} admin: {dispatch(path, 'admin')}")

Output (real run):

/orders         customer: 200 your orders   admin: 200 your orders
/admin/refunds  customer: 403 forbidden     admin: 200 refund issued
/admin/export   customer: 403 forbidden     admin: 403 forbidden

The forgotten /admin/export route fails closed: it's refused even to the admin. A mistake now breaks a feature loudly (and gets fixed) instead of leaking every customer's data silently. Frameworks offer the same idea: a global "login required" setting plus explicit per-route permissions, so that a new route is protected unless someone deliberately marks it public.

Problem 6: access-control unit tests

  • A unit test is a small program that checks one piece of code automatically and reports pass or fail.
  • Build a matrix: every kind of user × every action × the expected answer (allow/deny).
  • Most bugs hide in the denials, so test that Ravi can't do things, not just that Neha can.
  • Run the tests on every change (for example with pytest in your CI pipeline); a failure blocks the release.

Demo 7: a matrix catches a teammate's "quick fix"

# Access-control tests: a matrix of WHO x WHAT, run on every change
def can(user, action, order):                  # the policy under test
    if user["role"] == "admin":   return True
    if action == "view":          return order["owner"] == user["name"]
    if action == "cancel":        return order["owner"] == user["name"] and order["status"] == "new"
    if action == "refund":        return True          # BUG: a teammate's "quick fix"
    return False

neha, ravi = {"name": "neha", "role": "customer"}, {"name": "ravi", "role": "customer"}
asha = {"name": "asha", "role": "admin"}
order = {"owner": "neha", "status": "new"}
EXPECT = [(neha, "view", True), (ravi, "view", False), (neha, "cancel", True),
          (ravi, "cancel", False), (neha, "refund", False), (ravi, "refund", False),
          (asha, "refund", True)]
failed = 0
for user, action, want in EXPECT:
    got = can(user, action, order)
    ok = "PASS" if got == want else "FAIL"
    failed += ok == "FAIL"
    print(f"{ok}  {user['name']:5} {action:7} expected {want!s:5} got {got}")
print(f"{failed} test(s) failed" if failed else "all access rules hold")

Output (real run):

PASS  neha  view    expected True  got True
PASS  ravi  view    expected False got False
PASS  neha  cancel  expected True  got True
PASS  ravi  cancel  expected False got False
FAIL  neha  refund  expected False got True
FAIL  ravi  refund  expected False got True
PASS  asha  refund  expected True  got True
2 test(s) failed

In production, also log access-control failures and alert on repeats: many denials from one account or IP address are a sign someone is probing. OWASP adds rate limiting (capping how many requests a client can make per minute) to slow down automated probing.

How common is broken access control?

Source Fact
OWASP Top 10:2025 A01 Broken Access Control is #1 (it was #1 in 2021 too)
OWASP Top 10:2025, A01 40 CWEs mapped; max incidence rate 20.15%, average 3.74%; 1,839,701 occurrences; 32,654 CVEs
OWASP Top 10:2025, A01 Server-side request forgery (SSRF) and CSRF are now inside this category
MITRE 2025 CWE Top 25 CWE-862 Missing Authorization #4; CWE-863 Incorrect Authorization #17; CWE-284 Improper Access Control #19; CWE-639 (IDOR) #24

Why so common? An automated scanner can't know that order 1043 belongs to Ravi. Only the app's designers know the rules, so they must write them down, enforce them centrally, and test them.

The whole chain

  1. An edited ID shows Ravi's order → authorization, IDOR, the ownership check.
  2. Random IDs leak → unguessable IDs are not access control.
  3. A hidden admin page → vertical escalation, function-level role checks on the server.
  4. Unlinked files answer → forced browsing review of your own app.
  5. A forgotten route → deny by default.
  6. A quick fix breaks a rule → access-control unit tests and logged denials.

Common mistakes (and what they print)

Mistake What you see Why it's wrong Fix
Checking only the login Neha, edits URL : 200 phone charger, House 12, Jaipur Authenticated ≠ authorized Check order["owner"] == user
Reading the owner before checking the order exists TypeError: 'NoneType' object is not subscriptable A missing order crashes the server if order is None or order["owner"] != user: return 404
Trusting a user ID sent by the client Any user ID works The client is not yours Take the user from the server session
Hiding an admin link without checking the role hidden only, neha : 200 refund Rs 5000 issued Hidden ≠ protected Role check on the server for every function
Relying on random IDs ravi, no check : Invoice: Rs 84,200, PAN on file IDs leak Ownership check as well
Allowing by default /admin/export ... ALL customers' data Forgotten routes are open Deny unless a rule allows
Answering 403 for other users' objects 403 forbidden for 1043, 404 for 9999 Confirms which IDs exist Same 404 for both

Mini project: a toy shop API with central access control

One policy function (can), used by every handler, deny by default, ownership checks, the same 404 for "not yours" and "not there", and a log of denials.

# Mini project: a toy shop API with central, deny-by-default access control
ORDERS = {1042: {"owner": "neha", "item": "masala chai 1 kg", "status": "new"},
          1043: {"owner": "ravi", "item": "phone charger", "status": "shipped"}}
SESSIONS = {"tok-neha": {"name": "neha", "role": "customer"},
            "tok-ravi": {"name": "ravi", "role": "customer"},
            "tok-asha": {"name": "asha", "role": "admin"}}
DENIALS = []                                         # access-control failures, for alerting

def can(user, action, order):                        # ONE policy, used everywhere
    if user["role"] == "admin":
        return action in {"view", "cancel", "refund"}
    if order["owner"] != user["name"]:
        return False                                 # not yours
    if action == "view":   return True
    if action == "cancel": return order["status"] == "new"
    return False                                     # deny by default

def handle(token, action, order_id):
    user = SESSIONS.get(token)
    if user is None:
        return "401 please log in"
    order = ORDERS.get(order_id)
    if order is None or not can(user, action, order):
        DENIALS.append((user["name"], action, order_id))
        return "404 not found"                       # don't reveal whether it exists
    if action == "cancel": order["status"] = "cancelled"
    return f"200 {action} {order['item']}"

print(handle("tok-neha", "view", 1042))
print(handle("tok-neha", "view", 1043))
print(handle("tok-ravi", "cancel", 1043))           # shipped: can't cancel
print(handle("tok-neha", "refund", 1042))
print(handle("tok-asha", "refund", 1043))
print(handle(None, "view", 1042))
print("denials logged:", DENIALS)

Output (real run):

200 view masala chai 1 kg
404 not found
404 not found
404 not found
200 refund phone charger
401 please log in
denials logged: [('neha', 'view', 1043), ('ravi', 'cancel', 1043), ('neha', 'refund', 1042)]

Practice

1. Add a cancel endpoint that only the order's owner may use, and only while the order is new.

Solution
# Practice 1 solution: a cancel endpoint with an owner check and a status check
ORDERS = {1042: {"owner": "neha", "status": "new"}, 1043: {"owner": "ravi", "status": "new"}}
SESSIONS = {"tok-neha": "neha", "tok-ravi": "ravi"}

def cancel(token, order_id):
    user = SESSIONS.get(token)
    if user is None: return "401 please log in"
    order = ORDERS.get(order_id)
    if order is None or order["owner"] != user: return "404 not found"
    if order["status"] != "new": return "409 already " + order["status"]
    order["status"] = "cancelled"
    return "200 cancelled"

print(cancel("tok-neha", 1043))
print(cancel("tok-neha", 1042))
print(cancel("tok-neha", 1042))

Output (real run):

404 not found
200 cancelled
409 already cancelled

2. Add a support role that may view any order but never refund. Unknown roles get nothing.

Solution
# Practice 2 solution: a "support" role that may VIEW any order but never refund
PERMS = {"customer": {"view_own"}, "support": {"view_any"}, "admin": {"view_any", "refund"}}

def allowed(user, action, order):
    p = PERMS.get(user["role"], set())             # unknown role -> no permissions
    if action == "view":
        return "view_any" in p or ("view_own" in p and order["owner"] == user["name"])
    if action == "refund":
        return "refund" in p
    return False

order = {"owner": "neha"}
for u in [{"name": "neha", "role": "customer"}, {"name": "ravi", "role": "customer"},
          {"name": "meera", "role": "support"}, {"name": "asha", "role": "admin"},
          {"name": "x", "role": "intern"}]:
    print(f"{u['name']:6} {u['role']:9} view: {allowed(u, 'view', order)!s:5} refund: {allowed(u, 'refund', order)}")

Output (real run):

neha   customer  view: True  refund: False
ravi   customer  view: False refund: False
meera  support   view: True  refund: False
asha   admin     view: True  refund: True
x      intern    view: False refund: False

3. Add three more denial tests to demo 7 (with the refund bug fixed): cancelling a shipped order, cancelling someone else's order, and an action nobody defined.

Solution
# Practice 3 solution: three more denial tests for demo 7's policy (with the bug fixed)
def can(user, action, order):
    if user["role"] == "admin":   return True
    if action == "view":          return order["owner"] == user["name"]
    if action == "cancel":        return order["owner"] == user["name"] and order["status"] == "new"
    return False                                   # refund: admins only (deny by default)

neha, ravi = {"name": "neha", "role": "customer"}, {"name": "ravi", "role": "customer"}
new, shipped = {"owner": "neha", "status": "new"}, {"owner": "neha", "status": "shipped"}
EXPECT = [(neha, "cancel", shipped, False),        # own order, but already shipped
          (ravi, "cancel", new, False),            # someone else's order
          (neha, "delete", new, False),            # an action nobody defined
          (neha, "refund", new, False)]
for user, action, order, want in EXPECT:
    got = can(user, action, order)
    print("PASS" if got == want else "FAIL", user["name"], action, order["status"])

Output (real run):

PASS neha cancel shipped
PASS ravi cancel new
PASS neha delete new
PASS neha refund new

4. In one line: what's the difference between "hidden" and "protected"?

Answer

Hidden changes what users see (a missing link); protected changes what the server allows (a check that refuses). Only protected counts.

Quick quiz

Ravi, a customer, opens /api/users/neha/address and gets Neha's address. Which is it? A vertical escalation; B horizontal escalation (IDOR); C forced browsing of a backup; D not a bug, he is logged in.

Answer

B, horizontal escalation (an IDOR). Both are customers (same level); he reached another user's data through an identifier in the request. Being logged in doesn't make it allowed.

Interview questions

  1. Authentication vs authorization? Authentication verifies identity (who you are); authorization decides what that identity may do to which resource.
  2. What is broken access control? Any flaw that lets users act outside their intended permissions: viewing, changing or deleting others' data, or using functions above their role.
  3. What is an IDOR? Using an identifier from the request (URL, body, header) to access an object without checking the user is allowed to access that specific object (CWE-639).
  4. Horizontal vs vertical privilege escalation? Horizontal: another user's data at the same privilege level. Vertical: gaining a higher level's privileges, such as admin functions.
  5. Do random UUIDs fix IDOR? No. They make enumeration harder, but IDs leak through logs, links and screenshots; only a server-side ownership check fixes it.
  6. What is missing function-level access control? An endpoint or action that doesn't check the caller's role or permission on the server, often because the UI simply hides it.
  7. What is forced browsing, and how do you defend against it? Requesting unlinked URLs by guessing names. Defend with deny by default, server-side checks on everything, and removing backups, debug pages and directory listings from production.
  8. Should you return 403 or 404 for another user's object? Usually 404, the same as a missing object, so you don't confirm which IDs exist. 403 is fine for functions the user knows exist but can't use.
  9. What does deny by default mean in code? One central check every request passes through, which refuses unless a rule explicitly allows; new or forgotten routes fail closed.
  10. How do you test access control? A matrix of users × actions × expected allow/deny, emphasising denials, run automatically on every change; plus logging and alerting on access-control failures in production.
  11. Why do scanners miss many access-control bugs? They can't know business rules such as who owns which record; those must be designed, written down and tested by the team.

Glossary

Term Meaning in plain words Example
Access control Enforcing who may do what to which resource, on every request Only Neha may view order 1042
Authentication Proving who you are Logging in
Authorization Deciding whether you may do a specific thing May Neha view order 1043? No
Broken access control Users can act outside their permissions Reading another user's order
Session / session cookie The server's memory that you're logged in, and the cookie that points to it (episode 28) tok-neha
Object A record the app stores An order, an invoice
Direct object reference An object's identifier taken from the request /orders/1043
IDOR Insecure direct object reference: the ID is used with no ownership check Changing 1042 to 1043
CWE-639 MITRE's ID for authorization bypass through a user-controlled key (IDOR) #24 in the 2025 CWE Top 25
Privilege Something you're allowed to do Issuing refunds
Privilege escalation Gaining privileges you shouldn't have A customer acting as admin
Horizontal privilege escalation Reaching another user's data at the same level Neha reads Ravi's order
Vertical privilege escalation Gaining a higher level's powers A customer issues refunds
Role A named group of permissions customer, admin, support
Function-level access control Checking the caller may use a given function or endpoint Only admins reach /admin/refunds
Missing function-level access control That check is absent, often because the UI just hides the link Demo 4's hidden-only server
Ownership check Confirming an object belongs to the logged-in user order["owner"] == user
401 / 403 / 404 HTTP status codes: not logged in / forbidden / not found 404 not found for other users' orders
Unguessable ID A long random identifier that can't be counted or guessed secrets.token_hex(16)
CSPRNG Cryptographically secure random number generator (episode 10) Python's secrets module
Defence in depth Several layers, so one failure isn't fatal (episode 3) Random IDs plus ownership checks
Forced browsing Requesting unlinked URLs by guessing names /backup.zip
Security through obscurity Relying on secrecy of a design or URL instead of real checks "Nobody knows the admin URL"
Directory listing A web server showing the list of files in a folder An index of /uploads/
Web root The folder a web server serves files from Where backups must never be
Allow by default Everything is permitted unless blocked Forgotten routes are open
Deny by default Everything is refused unless a rule allows Demo 6's dispatcher
Fail closed When something goes wrong, refuse The undeclared export route
Central policy One function or service that makes every access decision can(user, action, order)
Unit test A small automatic check of one piece of code Demo 7
Test matrix Every user × action × expected result The EXPECT list
pytest A popular Python test framework Runs tests on every commit
CI (continuous integration) Automatically building and testing every change Blocks a release on a failed test
Rate limiting Capping requests per client per time window 60 requests a minute
OWASP Top 10 OWASP's awareness list of the top web app risks (episode 36) A01:2025 Broken Access Control
CWE / CVE A weakness type / a specific published vulnerability (episode 8) CWE-862 / one CVE record

Summary

  • Authentication says who you are; authorization says what you may touch. Access control enforces authorization on every request, on the server.
  • IDOR (horizontal escalation): an ID from the request is used without an ownership check. Fix: look up the object, confirm it belongs to the session's user, and answer 404 for "not yours" and "not there" alike.
  • Unguessable IDs are not access control; they're only an extra layer.
  • Vertical escalation and missing function-level access control: hidden links aren't locks; check roles on the server for every function and method.
  • Forced browsing: review your own app's paths without a login; only an explicit public list should answer.
  • Deny by default in one central check, so mistakes fail closed; prove it with access-control unit tests that focus on denials, and log denials in production.
  • Broken access control is #1 in the OWASP Top 10:2025 (40 CWEs, 1.8M+ occurrences); missing authorization is #4 in the 2025 CWE Top 25.

Next episode: SQL injection and parameterised queries.

Sources: OWASP, "A01:2025 Broken Access Control" (owasp.org/Top10/2025/A01_2025-Broken_Access_Control/); MITRE, "2025 CWE Top 25 Most Dangerous Software Weaknesses" (cwe.mitre.org/top25/archive/2025/2025_cwe_top25.html, updated 15 December 2025). Code outputs from Python 3.13. Fetched 6 Nov 2026.