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.
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.
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
- Set up a Django project with a model and views that pass user input to Extract or Trunc.
- Send a request to the vulnerable endpoint with a crafted value that includes SQL syntax.
- 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.