find_unscoped_queries
Detect Django querysets that fetch tenant-scoped data without ownership filters. Identifies potential IDOR vulnerabilities by analyzing model relationships and missing scoping conditions.
Instructions
Find querysets that read tenant-scoped data without scoping the query.
This is the shape behind most IDOR reports: a view loads an object by
primary key and never checks who owns it. Generic analysers struggle
because the defect is the absence of a filter, and absence has no syntax.
The model graph makes it tractable: it knows Order reaches the tenant root
through 'customer', so it can tell that filtering on pk alone is not enough.
Candidates, not verdicts. A filter in a base class, a mixin, a custom
manager or a get_queryset() override is invisible from here.
Args:
tenant_root: the model that owns data, e.g. "auth.User" or "shop.Customer".
search_path: directory to scan. Defaults to the project path.
max_depth: how many relation hops still count as owned.
include_exempt: also scan admin, management commands and tests.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_depth | No | ||
| search_path | No | ||
| tenant_root | No | auth.User | |
| include_exempt | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||