The Plain Picture#
A hotel where your key card opens your room — but the lift doesn't check which floor you're allowed on, and the room doors only check that you have a key card, not which room it's for. Any guest can open any room.
The Real Names#
Broken access control — users can act outside their permissions. It is #1 in the OWASP Top 10 (the industry's standard list of the most critical web application risks, from the OWASP foundation).
IDOR (Insecure Direct Object Reference) — the most common form: the server trusts an ID from the request without checking the current user is allowed to access that object. Part 0's problem 2.
Under the Hood#
Priya is logged in (her session says user_id = 7)
GET /notes/42 → note 42 belongs to Priya → 200 ✔
GET /notes/43 → note 43 belongs to Rahul → 200 ✗ ← IDOR: the server never checked ownershipVulnerable (the idea, in Python-like code — Python comes in Backend with Python (coming soon)):
def get_note(note_id, current_user):
return db.query("SELECT * FROM notes WHERE id = %s", note_id) # anyone's note!Fixed — tie every query to the current user's permissions:
def get_note(note_id, current_user):
note = db.query("SELECT * FROM notes WHERE id = %s AND owner_id = %s", note_id, current_user.id)
if note is None:
raise NotFound() # 404, not 403 — don't even confirm the note existsOther forms of broken access control:
a normal user calling admin endpoints (
POST /admin/credits) because only the admin UI was hidden;changing your own role by sending
"role": "admin"in a profile update (mass assignment — accepting fields the user shouldn't be allowed to set);JWT claims trusted without verifying the signature.
Defences: deny by default; check authorization in one central place (a dependency or middleware — FastAPI Models and Dependency Injection (coming soon)) rather than remembering it in every handler; filter queries by owner; allow-list which fields each endpoint accepts; and write tests where user A tries to access user B's data.
Random, unguessable IDs (like UUIDs) make guessing harder but are not a fix — IDs leak through URLs, logs and shared links.
Check yourself
4 questionsWhat is IDOR?
Show answerHide answer
The server uses an object ID from the request without checking the user may access that object.
How do you fix GET /notes/{id} so users can only read their own notes?
Show answerHide answer
Check ownership on the server — e.g. query WHERE id = ? AND owner_id = current_user.id, return 404 otherwise.
Why aren't random UUIDs a real fix?
Show answerHide answer
IDs leak (links, logs, screenshots); security must come from the permission check, not secrecy of the ID.
What is mass assignment?
Show answerHide answer
The server copies request fields straight into the database record, letting users set fields like role or credits.