← All lessons Stage 3 · Lesson 4
20 min

IDOR: the simplest serious bug

Stage 3 · Lesson 4 · 20 minutes · Requires Stage 2


The one-line answer

An IDOR (Insecure Direct Object Reference) is when changing an ID in a request — invoice=1043 to invoice=1044 — gives you someone else's data, because the server never checks whether that object belongs to you.

The boundary: if you ever notice an ID pattern on a real site, do not "just check" the next number. Accessing another person's data without authorisation is unauthorised access under the IT Act and a personal-data issue under the DPDP Act. Labs only.


Why you should care

IDOR needs no special tools, no clever payloads — just Repeater and one changed number. Yet it regularly exposes whole customer databases: invoices, medical records, ID documents, private messages.

It's also the purest example of broken access control, which OWASP ranks as the number one web application risk. Understand IDOR and you understand Stage 4's BOLA too — they're the same bug.


How it actually works

The bug

You log in and view your order:

GET /orders?id=50231 HTTP/2
Cookie: session=<your session>

The server runs something like:

order = db.get_order(id=request.args["id"])
return render(order)

It checks that you're logged in (you have a valid session) — but never checks that order 50231 is yours. So in Repeater you change it:

GET /orders?id=50230 HTTP/2
Cookie: session=<your session>

and you get someone else's order — name, address, phone, items.

That's the whole bug. Recall Stage 0, lab 02 (URL parameters): the student already saw that changing a parameter can change what you get.

Authentication vs authorisation

This distinction is the heart of IDOR:

  • Authentication — who are you? (Logging in proves this.)
  • Authorisation — are you allowed to do this, to this thing?

IDOR happens when an application does authentication but forgets authorisation for a specific object.

Where IDs hide

IDs aren't only in URLs (recall your input-point table from Stage 2 Lesson 3):

LocationExample
URL parameter/download?file_id=881
URL path/api/users/1043/profile
Form field / JSON body{"address_id": 77, "action": "delete"}
Cookieuser_id=1043
Hidden field<input type="hidden" name="account" value="1043">

And it isn't only reading. IDORs that let you change or delete someone else's object (update their address, cancel their order) are often more severe.

Why "unguessable IDs" are not a fix

A common response is "we'll use long random IDs instead of 1, 2, 3":

/orders?id=8f3c2a91-4b7e-4d2a-9c11-7e0b5f6a2d43

This makes guessing harder, but recall Stage 0 Lesson 5: IDs leak. They appear in shared links, emails, browser history, logs, referrer headers, and other API responses (e.g. a public review that includes the author's user ID). Once an attacker has the ID, the server still hands over the data.

Random IDs are a reasonable extra layer. They are not access control.

Testing for IDOR (on authorised targets)

The standard method uses two accounts you control:

  1. Log in as User A. Create or find an object (an order, a message). Note its ID.
  2. Log in as User B in a separate browser or session.
  3. In Repeater, take one of User B's requests and swap in User A's object ID — keeping User B's session.
  4. If User B can see or change User A's object, that's an IDOR.

Using two accounts you own is what makes this safe and conclusive: you prove the bug without touching a real person's data.


See it yourself

Only on PortSwigger labs:

  1. Read the Access control topic and its IDOR section (link below).
  2. Do the apprentice lab on insecure direct object references (chat transcripts). Watch HTTP history for the download request and change the ID in Repeater.
  3. Do an apprentice lab where a user ID in a request parameter controls whose account page you see.
  4. For each, write down: the object, where the ID was, and which check the server skipped.

How attackers abuse this

Attackers walk through ID ranges — often with simple automation (Stage 2 Lesson 2) — downloading record after record. Because each request looks like normal use by a logged-in user, a basic setup may not notice anything until the data appears for sale.

The defensive fix — server-side authorisation on every object access:

order = db.get_order(id=request.args["id"])
if order is None or order.owner_id != current_user.id:
    return 404   # don't reveal whether it exists
return render(order)
  • Check ownership or permission on every request, for every object, for every action (read, update, delete). Never trust that the client only asks for its own IDs (recall Stage 0 Lesson 8).
  • Look objects up through the user where possible: "get this user's order 50231" instead of "get order 50231".
  • Centralise the check (middleware or a shared function) so a new endpoint can't forget it.
  • Use random IDs as an extra layer, not the fix.
  • Monitor for one account requesting many different object IDs quickly — a strong Stage 5 detection signal.
  • Test for it: automated tests with two users that try to access each other's objects.

Common mistakes

  • Confusing "logged in" with "allowed". Authentication isn't authorisation.
  • Only checking reads. Update and delete endpoints need the same checks — often more.
  • Trusting random IDs. They leak.
  • Testing with real users' data. Always use two accounts you control.
  • Forgetting IDs in bodies, cookies and headers. Check every input point, not just the URL.

Check yourself

  1. In one sentence, what check is missing when an IDOR exists?
  2. Why are long random IDs not a complete fix?
  3. Why do testers use two accounts they control when testing for IDOR?
Answers
  1. The server doesn't check that the requesting user is authorised to access that specific object (ownership/permission), only that they're logged in.
  2. IDs leak — through links, logs, emails, referrer headers and other API responses. Once someone has the ID, there's still no permission check stopping them.
  3. It proves the bug conclusively (User B accessed User A's object) without touching any real person's data, keeping the test within authorisation and privacy law.

Your lab

  • PortSwigger Access control (including IDOR): https://portswigger.net/web-security/access-control
  • OWASP Juice Shop on your own machine has several access-control challenges — try viewing another user's basket.

Writeup: the object, where the ID was, the two-account proof, and the exact server-side check that fixes it.


Summary in your language

தமிழில் சுருக்கம்

IDOR என்பது ஒரு request-இல் உள்ள ID-ஐ மாற்றினால் வேறு ஒருவரின் தரவு கிடைப்பது — ஏனெனில் அந்தப் பொருள் உங்களுடையதா என்று server சரிபார்ப்பதில்லை. Login செய்திருப்பது (authentication) வேறு, அனுமதி இருப்பது (authorisation) வேறு. நீண்ட random ID-கள் தீர்வு அல்ல — அவை கசியும். சோதனைக்கு உங்களுக்குச் சொந்தமான இரண்டு கணக்குகளைப் பயன்படுத்துங்கள். தீர்வு: ஒவ்வொரு request-இலும், ஒவ்வொரு பொருளுக்கும், படிக்க/மாற்ற/நீக்க — server-இல் உரிமைச் சரிபார்ப்பு.

हिंदी में सारांश

IDOR तब होता है जब request में ID बदलने पर किसी और का data मिल जाता है — क्योंकि server यह नहीं जाँचता कि वह चीज़ आपकी है या नहीं। Login होना (authentication) और अनुमति होना (authorisation) अलग बातें हैं। लंबे random IDs इलाज नहीं हैं — वे leak हो जाते हैं। Testing के लिए अपने दो accounts इस्तेमाल करें। इलाज: हर request पर, हर object के लिए, पढ़ने/बदलने/हटाने — सब पर server-side ownership check।

Want this summary in Malayalam, Telugu, Kannada or another language? Tell us — the most requested languages get added next.


What's next

From "is this yours?" to "are you really who you say you are?": Broken authentication & session flaws