The archive/CVE-2025-59681
djangoDisclosed 2025

CVE-2025-59681:django: SQL injection via column alias

A historical CVE, retraced through the questions Lachesis asks of vulnerable code.

Historical record5.2.6 (git 75c4403)
WeaknessCWE-89 · SQL injection via column alias
ImpactA sql injection via column alias in django, reachable from attacker-controlled input.
Read the reconstruction
01What happened

An attacker-controlled column alias reached the SQL query because Django's safety check missed one dangerous character.

That is the shape of the failure. The rest of this case file follows the evidence behind it.

Separate the record from the run

What was known.
What Lachesis established.

01Historical record

Known before Lachesis ran

The CVE and vulnerable release were selected from public history. We are not claiming novel discovery.

CVE
CVE-2025-59681
Vulnerable target
5.2.6 (git 75c4403) · vulnerable
Prior knowledge
CVE-2025-59681 · 5.2.6 (git 75c4403) is vulnerable
then
02Lachesis run
Verified captured run

Independent re-detection

No source/sink/guard fed from memory. Hypothesis 'Q(_connector=)' from memory was REFUTED by the 5.2.6->5.2.7 diff, which showed the real fix is check_alias's FORBIDDEN_ALIAS_PATTERN gaining '#'. Drove the hunt on the diff + graph evidence only.

Seeded inputs
None
Run timestamp
2026-08-24T12:06:09Z
Evidence artifact
~/.lachesis/graphs/django_cve_2025_59681.kuzu

The commands and outputs below come from this recorded Lachesis run.

The reconstruction, in one frame

What Lachesis reconstructed.

One historical repository. Four captured queries. A complete source-to-sink argument.

Lachesis Casefiles · Unbound ComputeVerified runCVE-2025-59681
A missing character in Django's alias check changed the SQL it generated.
01Sourcedef annotate(self, *args, **kwargs):
02Sinkself.annotations[alias] = annotation
03Missing guardFORBIDDEN_ALIAS_PATTERN = _lazy_re_compile(r"['`\"\]\[;\s]|--|/\*|\*/")
$ lachesis sources_of → reaches → guard_dominance
django · 5.2.6 (git 75c4403) · vulnerableunboundcompute.com
This was known history. Your code is not.

Lachesis follows the same evidence path through unfamiliar repositories.

The Lachesis reconstruction

Here is how the path becomes visible.

These are the recorded questions Lachesis asked of the historical vulnerable code, followed by the raw result and source location each query returned.

Repositorydjango
Revision5.2.6 (git 75c4403) · vulnerable
EngineLachesis

Captured runThis block reflects the real blind drive of the graph we built for Django. We loaded the whole graph, listed every bug family with nothing chosen ahead of time, and the SQL injection sinks came out of that. The candidate, model tag and guard reading below are the facts captured on that drive on that drive. No query was seeded; the finding was rediscovered from graph structure, so the mode is independent-redetection.

01 · load_graph01 / 05
Lachesis ran
load_graph --path ~/.lachesis/graphs/django_cve_2025_59681.kuzu --profile all && candidate_census

Load the graph and list every bug family

First we load the graph and ask the tool to list every bug family, with nothing picked ahead of time. It reports all 8 domains and 31 sink constructors and says the census is complete for what the graph can observe. Injection is one row among all of them.

Captured resultCaptured · load_graph
raw captured outputload_graph
{"move": "load_graph", "graph": "/Users/riyandhiman/.lachesis/graphs/django_cve_2025_59681.kuzu", "profile": "all"}

CANDIDATE_CENSUS
move: candidate_census
taxonomy (8):
  domain=lifecycle         title=Resource lifecycle              enumerable=True
  domain=memory            title=Memory safety                   enumerable=True
  domain=injection         title=Injection                       enumerable=True
  domain=navigation        title=Request forgery & redirection   enumerable=True
  domain=object-integrity  title=Object integrity                enumerable=True
  domain=filesystem        title=Filesystem                      enumerable=True
  domain=crypto-config     title=Cryptography & transport config enumerable=True
  domain=resource          title=Resource exhaustion             enumerable=True
constructors (31): complete_for_observable_graph=True
applied: True
django/db/models/sql/query.pyline 0
Code location returned for this evidence step.
The repair

A small line with a large consequence.

The character class omits '#', which starts an inline comment on MySQL and MariaDB, so a '#' alias slips past the check and reaches the SELECT clause.

Before
FORBIDDEN_ALIAS_PATTERN = _lazy_re_compile(r"['`\"\]\[;\s]|--|/\*|\*/")
After the patch
// Add '#' to the pattern: r"['`\"\]\[;\s]|#|--|/\*|\*/" (Django 5.2.7).
Sources & further reading

The original record.

Read the historical advisory and vulnerability record behind this reconstruction.

Open the Lachesis quickstart