← AuditMind research

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.

Vladislav · AppSec specialist at AuditMind · This is a short English version. Full article on Habr (in Russian)

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

ApproachWhat it seesWhat it misses for IDOR
API specs (OpenAPI)The contract of each endpointA protected and a vulnerable endpoint look exactly the same in the spec
AST heuristicsCode structure and keywords“There is a permission call somewhere in the function” — noisy in both directions
Classic taint analysisData flow from source to sinkThe 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:

  1. Find handlers. Route-decorated functions, class-based views, viewsets and views wired through urls.py in Django, DRF, Flask and FastAPI.
  2. 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.
  3. 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:

LabelMeaningExample
SUBJECTThe current user set by authenticationrequest.user
INPUTAnything the client sentrequest body, headers
ATTACKER_SELECTEDAn identifier the client uses to pick a specific object/orders/<id>
OBJECTA record loaded from storagethe order row
DYNAMICA value whose origin can’t be resolved staticallygetattr(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.