Skip to content
SQL injection Write-up Intermediate

CVE-2022-34265

Django's Trunc and Extract database functions did not properly sanitise their kind and lookup_name arguments, allowing SQL injection when user input is passed directly. An attacker could execute arbitrary SQL commands, potentially accessing or deleting database data.

Takuto Yoshikai Follow

Published on github.com

A vulnerability (CVE-2022-34265) in Django was disclosed on July 5, 2022 (US time). This article describes our discussion of this vulnerability and the results of our verification.

Takuto Yoshikai (@TakutoYoshikai), on github.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

Root cause

Likely, the arguments kind and lookup_name were interpolated into SQL without proper escaping or validation.

Impact

An attacker could execute arbitrary SQL commands, potentially accessing unauthorised data or deleting the database.

What the attacker needed

Django application using Trunc or Extract with user input; Attacker can send requests to the vulnerable endpoint

The fix

The vulnerability was fixed in Django 3.2.14 and 4.0.6 by improving string handling to prevent SQL statement corruption.

How it was found

  1. Set up a Django project with a model and views that pass user input to Extract or Trunc.
  2. Send a request to the vulnerable endpoint with a crafted value that includes SQL syntax.
  3. Observe a delay in the response when using a time-delay SQL function, confirming injection.

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 web framework that helps build websites. Two functions that handle dates, Trunc and Extract, took a user-supplied value and put it directly into a database query without cleaning it. This let an attacker insert their own database commands, which could read or delete data.

What is SQL injection?

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

More from Django

View all

The newest disclosed reports for this program.

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.