Django SQL Injection (CVE-2020-7471) Threat Alert

Django SQL Injection (CVE-2020-7471) Threat Alert

fevereiro 28, 2020 | Adeline Zhang

Vulnerability Description

On February 3, Django Software Foundation (DSF) released a security bulletin, announcing the fix of a SQL injection vulnerability (CVE-2020-7471) that is exploited via a StringAgg delimiter. An attacker could break escaping and inject malicious SQL statements by passing a crafted delimiter to the aggregation function contrib.postgres.aggregates.StringAgg.

Django is a high-level open-source web framework powered by Python. It originates from an open source community. Django allows programmers to conveniently and rapidly create high-quality database-driven applications that are easy to maintain. This framework is used widely. On February 11, NSFOCUS discovered that the proof of concept (PoC) of this vulnerability is already made public available. Affected users should upgrade Django to a patched version to fix this vulnerability.

CVSS 3.1 score: 9.8

For details of this vulnerability, visit the following link:

Scope of Impact

Affected Versions

  • Django 1.11.x < 1.11.28
  • Django 2.2.x < 2.2.10
  • Django 3.0.x < 3.0.3
  • Django master/develop branch

Unaffected Product Versions

  • Django 1.11.28
  • Django 2.2.10
  • Django 3.0.3

Vulnerability Detection

Version Check

Users can check the current Django version to determine whether this application is vulnerable.

Open a command line interface and type python. At the Python prompt, type the following commands to check the current Django version:

>>> import django

>>> django.get_version()

Note: Django contains this vulnerability if its version is within the affected scope and it uses the PostgreSQL database.

Code Audit

As this vulnerability resides in the StringAgg function, Django contains this vulnerability if its version is within the affected scope and it uses the aggregate function StringAgg. Developers can check whether the following function is used:


Note: StringAgg, an aggregate function of PostgreSQL, is used to take all expressions from rows and concatenate them into a single string. It can concatenate rows of strings into one string and has found widespread application.


Official Update

DSF has released new versions to fix the preceding vulnerability. Affected users are advised to upgrade as soon as possible.

Django 1.11.28:

Django 2.2.10:

Django 3.0.3:

If Django is installed with pip, you can upgrade to the latest version by using the –upgrade or -U flag on the command line:

$ pip install -U Django

For the detailed upgrade procedure, visit the following link:


This advisory is only used to describe a potential risk. NSFOCUS does not provide any commitment or promise on this advisory. NSFOCUS and the author will not bear any liability for any direct and/or indirect consequences and losses caused by transmitting and/or using this advisory. NSFOCUS reserves all the rights to modify and interpret this advisory. Please include this statement paragraph when reproducing or transferring this advisory. Do not modify this advisory, add/delete any information to/from it, or use this advisory for commercial purposes without permission from NSFOCUS.


NSFOCUS, Inc., a global network and cyber security leader, protects enterprises and carriers from advanced cyber attacks. The company’s Intelligent Hybrid Security strategy utilizes both cloud and on-premises security platforms, built on a foundation of real-time global threat intelligence, to provide multi-layered, unified and dynamic protection against advanced cyber attacks.

NSFOCUS works with Fortune Global 500 companies, including four of the world’s five largest financial institutions, organizations in insurance, retail, healthcare, critical infrastructure industries as well as government agencies. NSFOCUS has technology and channel partners in more than 60 countries, is a member of both the Microsoft Active Protections Program (MAPP), and the Cloud Security Alliance (CSA).

A wholly owned subsidiary of NSFOCUS Information Technology Co. Ltd., the company has operations in the Americas, Europe, the Middle East and Asia Pacific.