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

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

February 28, 2020 | Mina Hao

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:

https://www.djangoproject.com/weblog/2020/feb/03/security-releases

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:

django.contrib.postgres.aggregates.StringAgg

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.

Mitigation

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:

https://www.djangoproject.com/m/releases/1.11/Django-1.11.28.tar.gz

Django 2.2.10:

https://www.djangoproject.com/m/releases/2.2/Django-2.2.10.tar.gz

Django 3.0.3:

https://www.djangoproject.com/m/releases/3.0/Django-3.0.3.tar.gz

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:

https://docs.djangoproject.com/zh-hans/2.2/howto/upgrade-version

Statement

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.

About 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.