#Why this matters
In the OWASP Top 10 (2021), Broken Access Control holds the number-one spot. An application can use HTTPS, strong password hashing, and valid session cookies, yet still leak every user's private records if the server forgets to verify who is allowed to call an endpoint or view an object.
To build and test web applications accurately, you must keep two questions separate: who the user is, and what that user is permitted to do.
#Authentication vs. authorization
Authentication (AuthN) proves identity: the user supplies credentials (such as a password and multi-factor code) and receives a random session identifier or signed token. Authorization (AuthZ) checks permissions on every subsequent request: it decides whether that verified identity may run an action on the requested object.
- Request with cookieBrowser sends session cookie to server
- Authenticate (AuthN)Server looks up session ID; fail -> 401
- Authorize (AuthZ)Server checks role and ownership; fail -> 403
- Handle requestExecute action and return 200 OK
HTTP defines distinct status codes for these two failures:
401 Unauthorized: Missing, expired, or invalid authentication credentials (despite the legacy name, it means unauthenticated).403 Forbidden: The server knows who the user is, but the user lacks permission for the requested resource or action.
#Common access control failure patterns
Access control flaws generally fall into three patterns:
| Pattern | What goes wrong | Example in a lab app |
|---|---|---|
| Vertical escalation | Low-privilege user runs admin actions | Student account requests POST /admin/delete-user and succeeds |
| Horizontal escalation (IDOR) | User A accesses User B's resource | Changing ?invoice_id=104 to ?invoice_id=105 returns another student's receipt |
| Security by obscurity | Sensitive route is hidden in UI or JS, not blocked | /internal-export is omitted from the navbar, so anyone who guesses it gets data |
Insecure Direct Object Reference (IDOR) is one of the most common beginner findings. When a route accepts an object ID (?id=42 or /api/orders/42) and queries the database without checking ownership (owner_id == current_user_id), any authenticated user can enumerate sequential IDs.
Similarly, hiding an /admin link in HTML or browser JavaScript gives zero protection. As you learned in the browser security lesson, anyone can inspect downloaded JavaScript in DevTools or review site traffic in Burp Suite to discover undocumented routes.
#Why client-controlled trust fails
Anything arriving in an HTTP request -- cookies, headers, query strings, or hidden form fields -- is controlled by the client. A classic mistake is storing a user's role or identity in a plain cookie or hidden field and trusting it on the server:
Testing for this flaw takes one HTTP request, either in Burp Suite Repeater or with curl:
$ curl -s -i -b "session=s9x2a1; role=student" http://lab.local/admin | head -n 1
HTTP/1.1 403 Forbidden
$ curl -s -i -b "session=s9x2a1; role=admin" http://lab.local/admin | head -n 1
HTTP/1.1 200 OKHere, the server ignored the user's real role stored alongside session=s9x2a1 and trusted the editable role cookie instead. The same bug happens when an API reads user_id from the JSON request body instead of deriving it from the server-side session.
#Defending and common mistakes
Strong access control enforces decisions centrally on the server:
# Safe pattern: derive identity and role from the server-side session
def get_invoice(request, invoice_id):
user = session_store.get(request.cookies.get("session"))
if not user:
return HttpResponse(status=401)
invoice = db.query_one(
"SELECT id, total FROM invoices WHERE id = %s AND owner_id = %s",
(invoice_id, user.id),
)
if not invoice:
return HttpResponse(status=403)
return JsonResponse(invoice)Avoid these frequent mistakes:
- Trusting client values: Never rely on
rolecookies, hidden<input>fields, oruser_idquery parameters to decide permissions. - Checking auth only in the UI: Hiding buttons or checking roles in client-side JavaScript does not block direct requests via
curlor Burp Suite. - Forgetting method and API parity: Protecting
GET /adminwhile leavingPOST /api/admin/usersunprotected. - Missing deny-by-default: Requiring developers to remember an
@require_admindecorator on every new endpoint instead of enforcing authentication and role policies across all routes by default.
#Summary
- Authentication verifies who a user is (
401on failure), while authorization checks what they can do on each request (403on failure). - Broken access control includes vertical escalation (regular user running admin routes), horizontal escalation/IDOR (accessing another user's ID), and relying on hidden endpoints.
- Client-supplied cookies, headers, and parameters can be altered trivially in Burp Suite or
curl. - Prevent these bugs by adopting deny-by-default rules and deriving user identity, roles, and object ownership strictly on the server.