Skip to content
SQL injection Write-up Advanced

CVE-2025–57833: Deep Dive into Django ORM FilteredRelation Alia

Django's ORM mishandled alias names in FilteredRelation when combined with alias() and annotate(), allowing user-controlled alias names to bypass quoting and be injected into SQL. An attacker could manipulate JOINs to access sensitive data, though the text does not demonstrate a working exploit.

Balki Maharaj Follow

Published on medium.com

� Safe: The alias name totalamount is a fixed string, so there’s no risk of SQL injection.

Balki Maharaj, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Impact

Attackers could manipulate JOINs to access sensitive data, and scope change is possible, but the text provides no working exploit and notes that normal annotation usage safely quotes aliases.

What the attacker needed

Application uses FilteredRelation with dynamic aliases; alias names derived from untrusted input

The fix

The vulnerability was fixed in Django 4.2.24, 5.1.12, 5.2.6 and later; additionally, alias names should never come from untrusted input and should be validated with a whitelist or regex.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Django is a tool that helps developers talk to a database without writing raw database commands. Normally it safely wraps names in quotes, but a specific feature called FilteredRelation failed to do that for alias names. If a website lets a user choose such a name, an attacker might sneak extra database instructions into the query.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.