IDOR &
Mitigations
Learn how Insecure Direct Object References let attackers access unauthorized data, and discover the authorization checks that stop them.
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.
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.
Why IDOR Matters
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.
Types of Object References
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
Example 1: Vulnerable Code
A user profile endpoint that fetches data based solely on the URL parameter, with no authorization check:
@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:
@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:
Real-World Attack Scenario
Defense in Depth
No single control is sufficient. Layer multiple mitigations for robust protection against IDOR:
IDOR Beyond URLs
IDOR isn't limited to URL query parameters. Attackers can manipulate object references in many places:
Common Mistakes
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?