01 / 20

IDOR &
Mitigations

Learn how Insecure Direct Object References let attackers access unauthorized data, and discover the authorization checks that stop them.

Cyber Security

What Is a Direct Object Reference?

When a web application uses a user-supplied identifier (like a number or filename) to fetch a specific resource, that's a direct object reference. The identifier points straight at the underlying data: a database row, a file, or an account record.

// A URL with a direct object reference:
https://bank.com/account?id=1042

When Does It Become "Insecure"?

A direct object reference becomes insecure (IDOR) when the application fails to check authorization before returning the resource. The server trusts the user's input blindly.

Attacker Changes id=1042 to id=1043 GET ?id=1043 Web Server No auth check! Trusts input fetch row 1043 Database Victim's data Returns data Leaked!

Why IDOR Matters

✕ Data Breaches
Attackers harvest personal info, medical records, or financial data in bulk by iterating through IDs.
★ OWASP Top 10
IDOR falls under Broken Access Control (A01:2021), the number-one web application security risk.
✓ Easy to Exploit
No special tools needed: just change a number in the URL. Even beginners can discover IDORs.

The Core Rule of IDOR Prevention

This is not about authentication (proving who you are). It's about authorization (proving you're allowed to access this particular object). A logged-in user should only reach their own data, not anyone else's.

1. Authenticate Who are you? 2. Authorize Can you access this? 3. Return Data Safe response IDOR happens when step 2 is missing

Types of Object References

Sequential IDs
Auto-incrementing integers: ?id=1, ?id=2, ?id=3. Easiest to guess and enumerate.
Filenames
Direct paths: /docs/report_alice.pdf. Change the name and access another user's file.
UUIDs
Random strings: ?id=a3f8c.... Harder to guess, but not a security control on their own.

IDOR vs. Other Access Control Flaws

IDOR Privilege Escalation Forced Browsing
Target Specific object (row, file) Higher role or permission Hidden page or endpoint
Method Change an object ID Tamper role parameter Guess or brute-force URL
Auth needed? Often yes (logged in) Yes (low-priv user) Sometimes none
Fix Object-level auth Role-based checks Route protection

Mitigation Checklist

1
Enforce server-side authorization. On every request, verify the current user owns the requested resource. Never trust the client.
2
Use indirect references. Map internal IDs to per-session tokens that only resolve for the authorized user.
3
Prefer UUIDs over sequential IDs. Reduces enumeration risk, though this alone is not sufficient.
4
Implement access control tests. Automated test suites should verify that User A cannot access User B's resources.
5
Log and monitor access attempts. Flag unusual patterns like a single user requesting hundreds of different IDs.

Example 1: Vulnerable Code

A user profile endpoint that fetches data based solely on the URL parameter, with no authorization check:

// Vulnerable endpoint (Python/Flask)
@app.route('/api/profile')
def get_profile():
  user_id = request.args.get('id')
  profile = db.query("SELECT * FROM users WHERE id=?", user_id)
  return jsonify(profile)  # No auth check!

Example 2: Secure Code

The same endpoint, now with server-side authorization that verifies ownership before returning data:

// Secure endpoint (Python/Flask)
@app.route('/api/profile')
@login_required
def get_profile():
  user_id = request.args.get('id')
  if user_id != current_user.id:
    return jsonify({"error": "Forbidden"}), 403
  profile = db.query("SELECT * FROM users WHERE id=?", user_id)
  return jsonify(profile)  # Authorized!

Example 3: Indirect Reference Map

Instead of exposing real IDs, the server maps each user's resources to per-session tokens that only that user can resolve:

User (Alice) Sees: ref=abc ?ref=abc Server Map (Alice's session) abc → record #1042 def → record #1055 ghi → record #1098 id=1042 Database Alice's data Attacker (Bob) Tries: ref=abc ✕ "abc" not in Bob's map 403 Forbidden

Real-World Attack Scenario

1
Discovery: Alice logs in to an online store and views her order at /orders?id=5001.
2
Hypothesis: She wonders: "What happens if I change 5001 to 5000?"
3
Exploitation: She visits /orders?id=5000 and sees another customer's order: name, address, items, payment info.
4
Enumeration: She writes a script to loop through id=1 to id=10000, harvesting thousands of records.

Defense in Depth

No single control is sufficient. Layer multiple mitigations for robust protection against IDOR:

Layer 1: Authentication Layer 2: Object-Level Authorization Layer 3: Indirect References / UUIDs Layer 4: Logging & Monitoring Rate limiting Anomaly detection Audit trails

IDOR Beyond URLs

IDOR isn't limited to URL query parameters. Attackers can manipulate object references in many places:

Request Body
JSON or form fields: {"userId": 1043} in a POST request.
Cookies
A cookie storing accountId=1042 can be edited in browser dev tools.
HTTP Headers
Custom headers like X-User-ID: 1042 used by the backend for routing.
File Paths
API parameters: /download?file=invoice_1042.pdf changed to another filename.

Common Mistakes

✕ Relying on Obscurity
Using UUIDs or hashed IDs without any authorization check. Obscure IDs can still be leaked or guessed.
✕ Client-Side Only Checks
Hiding buttons in the UI but leaving API endpoints unprotected. Attackers bypass the UI entirely.
✕ Checking Auth on Some Endpoints
Protecting /profile but forgetting /api/profile or /export. Every endpoint referencing objects needs checks.

Summary: IDOR at a Glance

Aspect Vulnerable Mitigated
Object Reference Sequential integer (1, 2, 3...) UUID or indirect token
Auth Check None or client-side only Server-side per request
Error Response Returns other user's data 403 Forbidden
Monitoring No logging of access patterns Rate limiting + alerts
Testing No cross-user test cases Automated access control tests

Question 1 of 5

What does IDOR stand for?

Question 2 of 5

A web app uses /invoice?id=501 to display invoices. Changing id=501 to id=502 shows another user's invoice. What is the root cause?

Question 3 of 5

Which of the following is the most effective mitigation against IDOR?

Question 4 of 5

Under the OWASP Top 10 (2021), IDOR falls under which category?

Question 5 of 5

An API uses an indirect reference map that converts session-specific tokens to real database IDs. Why does this help prevent IDOR?