Research · Python · SAST
Can static analysis find IDOR?
Most teams leave IDOR to DAST scanners and manual review. We built a detection engine for Python that doesn’t look for keywords — it reasons about who picks the object and whether anything checks that it belongs to them.
What IDOR looks like
IDOR (Insecure Direct Object Reference) happens when a server returns or changes an object just because the client asked for its id, without checking that the object belongs to that user. Here the route requires a login, but nothing ties the order to the person logged in — change the number in the URL and you read someone else’s order:
@app.get("/orders/<int:order_id>")@login_requireddef get_order(order_id): order = Order.query.get(order_id) return jsonify(order.to_dict())
Only an ownership check closes the hole — for example, narrowing the query to the current user:
@app.get("/orders/<int:order_id>")@login_requireddef get_order(order_id): order = Order.query.filter_by( id=order_id, owner_id=current_user.id, ).first_or_404() return jsonify(order.to_dict())
UUIDs and rate limits make ids harder to guess, but they are not a fix: an id leaked through a log or another endpoint still opens someone else’s data.
Why existing tools miss it
| Approach | What it sees | What it misses for IDOR |
|---|---|---|
| API specs (OpenAPI) | The contract of each endpoint | A protected and a vulnerable endpoint look exactly the same in the spec |
| AST heuristics | Code structure and keywords | “There is a permission call somewhere in the function” — noisy in both directions |
| Classic taint analysis | Data flow from source to sink | The flow exists in safe code too; it can’t tell whether a check is about the same object |
The key point: IDOR is not about a flow that exists, it’s about a check that doesn’t. In vulnerable and safe code alike the id travels from the URL to the database. What tells them apart is whether a check on the same object stands on the path of the request.
How the engine works
The engine reads a Python project in three layers that pass data, not calls, to each other:
- Find handlers. Route-decorated functions, class-based views, viewsets and views wired through
urls.pyin Django, DRF, Flask and FastAPI. - Record facts. For every handler: what came from the request, which data was accessed, which checks ran and on which branch, and who the current user is.
- Decide. Hypotheses about what could be wrong are weighed against suppressors that explain why the code is actually safe.
Every value gets one of five origin labels:
| Label | Meaning | Example |
|---|---|---|
SUBJECT | The current user set by authentication | request.user |
INPUT | Anything the client sent | request body, headers |
ATTACKER_SELECTED | An identifier the client uses to pick a specific object | /orders/<id> |
OBJECT | A record loaded from storage | the order row |
DYNAMIC | A value whose origin can’t be resolved statically | getattr(model, name) |
Splitting INPUT from ATTACKER_SELECTED is what keeps the noise down. A comment’s text is input — it can cause XSS, but it can’t choose whose record is loaded. The id in the URL can. So the question narrows to one thing: did an attacker-selected id reach an object lookup, and did anything tie that object to the subject on the way?
The rule
A handler is reported when an attacker-selected id reaches an object lookup and there is no check that compares the same object with the current user on the path the request takes.
Three properties make this different from pattern matching:
- Labels survive helper functions, so an id read in a helper still counts.
- A check counts only if it governs the access: a check in a sibling branch, or after the object has already been returned, doesn’t.
- Values produced by authentication are the subject, not input — otherwise every request after login would look tainted.
What it finds on real code
We run the engine on open-source Python projects and on large company codebases, and review every finding by hand. The hardest case is production code that keeps authorization outside the handler — in route permissions, router dependencies or a custom RBAC layer: a handler body with no visible check isn’t necessarily vulnerable.
Since the Habr article was published, precision has improved substantially on both kinds of code. We’ll publish updated measurements soon.
So, can it?
Yes — the formal model works, exactly as far as it can see the code. That’s why most of the work goes into reading the authorization layers that production code keeps outside the handler. This research is part of the work behind AuditMind.