What Is IDOR? Insecure Direct Object Reference Explained With Examples
An Insecure Direct Object Reference (IDOR) is an access control flaw. An application uses an identifier supplied by the user, such as an order number or file ID, to fetch a record, but never checks that the logged-in user is allowed to see or change that record. Changing the identifier can then expose another customer's data.
Topic: Web & API Security in Cybersecurity & Ethical Hacking · Commands & reference
Also covers: Cyber Threats, Scams & Online Safety, Ethical Hacking
Quick answer: An Insecure Direct Object Reference (IDOR) is an access control flaw. An application uses an identifier supplied by the user, such as an order number or file ID, to fetch a record, but never checks that the logged-in user is allowed to see or change that record. Changing the identifier can then expose another customer's data. OWASP lists the API form as Broken Object Level Authorization (API1:2023), and MITRE tracks it as CWE-639. The fix is a server-side ownership or permission check on every request, ideally by scoping database queries to the current user, backed by automated tests and logging.
Key takeaways
- IDOR is missing authorisation, not missing authentication.
- It is the top risk in the OWASP API Security Top 10 2023.
- Random IDs make guessing harder but do not fix the flaw.
- Check ownership on the server for every read, update and delete.
- Test with two accounts and log access-denied events.
Table of Contents
- How Does an IDOR Vulnerability Work?
- How Does IDOR Relate to BOLA and Broken Access Control?
- What Is the Impact of IDOR?
- What Does Vulnerable and Safe Code Look Like?
- Do Random IDs Prevent IDOR?
- How Do You Detect and Test for IDOR?
- What Is the Prevention Checklist?
- References
How Does an IDOR Vulnerability Work?
Most apps reference records by key: a URL path with an invoice number, a JSON body with an account ID, or a download link with a file name. The flaw appears when the server trusts that key. Login proves who the user is; authorisation decides what they may touch. If the code fetches the record by ID alone, any logged-in user can request any record. The OWASP IDOR Prevention Cheat Sheet explains that the root cause is the missing check, whatever the ID format.
How Does IDOR Relate to BOLA and Broken Access Control?
| Name | Source | Scope |
|---|---|---|
| IDOR | OWASP cheat sheet, testing guide | Object access by user-supplied reference |
| BOLA (API1:2023) | OWASP API Security Top 10 | Same flaw in APIs |
| A01 Broken Access Control | OWASP Top 10 | Wider category including IDOR |
| CWE-639 | MITRE | Authorisation bypass via user-controlled key |
In July 2023, CISA, Australia's ACSC and the NSA issued a joint advisory on IDOR, warning that these flaws were being abused in data breaches and urging vendors to adopt secure-by-design checks.
What Is the Impact of IDOR?
- Data exposure: invoices, health records, identity documents.
- Unauthorised changes: editing another user's profile, address or password reset email.
- Deletion: removing other users' records.
- Privilege escalation: reaching admin objects by ID.
In India, exposure of personal data can trigger duties under the DPDP Act 2023 and CERT-In's 6-hour incident reporting rule.
What Does Vulnerable and Safe Code Look Like?
Vulnerable pattern: the record is fetched by ID only.
# UNSAFE: any logged-in user can read any invoice
@app.get('/api/invoices/<int:invoice_id>')
@login_required
def get_invoice(invoice_id):
invoice = Invoice.query.get_or_404(invoice_id)
return jsonify(invoice.to_dict())
Safe pattern: the query is scoped to the current user, so other users' records simply do not exist for them.
# SAFE: ownership enforced in the query
@app.get('/api/invoices/<int:invoice_id>')
@login_required
def get_invoice(invoice_id):
invoice = Invoice.query.filter_by(
id=invoice_id, owner_id=current_user.id
).first_or_404()
return jsonify(invoice.to_dict())
Returning 404 rather than 403 also avoids confirming that the record exists. For shared resources, call a central policy function, as the OWASP Authorization Cheat Sheet recommends.
Do Random IDs Prevent IDOR?
No. UUIDs make enumeration harder, but IDs leak through emails, shared links, logs and other API responses. Treat random IDs as defence in depth only. The authorisation check is the real control.
How Do You Detect and Test for IDOR?
| Method | What it finds |
|---|---|
| Code review | Queries by ID without user scope |
| Two-account testing (WSTG-ATHZ-04) | User A requesting User B objects in your own test environment |
| Automated authorisation tests in CI | Regressions after new endpoints |
| Log monitoring | One account touching many object IDs or many 404s |
Only test applications you own or are authorised to assess in writing; unauthorised access breaks Sections 43 and 66 of the IT Act 2000. Our banking bug bounty IDOR case study shows how responsible disclosure works.
What Is the Prevention Checklist?
- Enforce authorisation on the server for every object action.
- Scope queries by the current user or tenant.
- Deny by default and centralise access rules.
- Never trust IDs from hidden fields, cookies or JSON bodies.
- Write tests for cross-user access on every endpoint.
- Log and alert on unusual object access patterns.
See the OWASP Top 10 guide for the wider picture, and explore WebAsha API and web security training.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0