Перейти к основному содержимому
Web Authentication & Access Control Fundamentals
Урок 3 из 18

Web Authentication & Access Control Fundamentals

Distinguish authentication from authorization, recognise horizontal and vertical access control flaws such as IDOR and trusted role cookies, and verify server-side permission checks.

Начальный 22 мин Веб-безопасность
Этого урока пока нет на выбранном языке — показана версия на другом языке. Перевод готовится.
Только в разрешённой среде — Описанные здесь приёмы применяются только в учебных лабораториях и в системах, которые принадлежат вам или на которые есть письменное разрешение.

Цели обучения

  • Distinguish authentication from authorization and map HTTP 401 and 403 status codes correctly
  • Identify vertical privilege escalation, horizontal privilege escalation (IDOR), and hidden-endpoint flaws
  • Explain why trusting client-controlled role cookies, hidden fields, or user IDs breaks access control
  • Verify and design deny-by-default server-side authorization checks

Рекомендуется заранее: HTTP-запросы и ответы, cookie и управление сессиямиHTML/JS Execution, Same-Origin Policy, CORS & CSP

#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.

  1. Request with cookieBrowser sends session cookie to server
  2. Authenticate (AuthN)Server looks up session ID; fail -> 401
  3. Authorize (AuthZ)Server checks role and ownership; fail -> 403
  4. 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:

Broken role check using a client-controlled cookieBroken role check using a client-controlled cookieBrowserServerDatabaseGET /admin (Cookie: session=u8f2k; role=admin)Tester modified role=student to role=admin in Burp SuiteCheck cookie value role == "admin"200 OK (admin dashboard returned!)

Testing for this flaw takes one HTTP request, either in Burp Suite Repeater or with curl:

Tampering with a client-supplied role cookie in a lab
$ 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 OK

Here, 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:

python
# 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 role cookies, hidden <input> fields, or user_id query 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 curl or Burp Suite.
  • Forgetting method and API parity: Protecting GET /admin while leaving POST /api/admin/users unprotected.
  • Missing deny-by-default: Requiring developers to remember an @require_admin decorator on every new endpoint instead of enforcing authentication and role policies across all routes by default.

#Summary

  • Authentication verifies who a user is (401 on failure), while authorization checks what they can do on each request (403 on 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.

Проверка знаний

Войдите, чтобы проходить тест, завершать уроки и сохранять прогресс. Войти в систему

Практика: проверьте свои знания