CVE-2021-32839 Regular Expression Denial of Service in sqlparse

High 7.5 Published Updated

An attacker can cause a denial of service via exponential backtracking in sqlparse when stripping comments from SQL statements.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Over the internet
Victim action needed
Not needed
Fix
Available

What is CVE-2021-32839?

CVE-2021-32839 is a high-severity denial of service vulnerability in andialbrecht sqlparse, published on 20 Sep 2021. An attacker can exploit it over the internet without logging in, with no action from the victim.

Official description

sqlparse is a non-validating SQL parser module for Python. In sqlparse versions 0.4.0 and 0.4.1 there is a regular Expression Denial of Service in sqlparse vulnerability. The regular expression may cause exponential backtracking on strings containing many repetitions of '\r\n' in SQL comments. Only the formatting feature that removes comments from SQL statements is affected by this regular expression. As a workaround don't use the sqlformat.format function with keyword strip_comments=True or the --strip-comments command line flag when using the sqlformat command line tool. The issues has been fixed in sqlparse 0.4.2.

Weakness: CWE-400

Which versions are affected by CVE-2021-32839?

3 open source packages ship an affected version, including sqlparse. It affects 1 product.

PackageAffectedFixed in
sqlparse PyPIFrom 0.4.00.4.2
sqlparse PyPIFrom 0.4.00.4.2
sqlparse PyPIFrom 0.4.00.4.2
Linux distribution packages (3)
python-sqlparse SUSE:Linux Enterprise Module for Basesystem 15 SP3All versions0.4.2-3.3.1
python-sqlparse openSUSE:Leap 15.3All versions0.4.2-3.3.1
python-sqlparse openSUSE:TumbleweedAll versions0.4.2-1.1

Products include Sqlparse Project Sqlparse.

How do I fix CVE-2021-32839?

Upgrade sqlparse to 0.4.2 or later.

Upgrade, then put limits on request size, rate and nesting depth so one client cannot exhaust the service. More about Denial of service.

Is CVE-2021-32839 being exploited?

There is no known exploitation of CVE-2021-32839 in the wild and no public exploit code.

Sources

Also known as DEBIAN-CVE-2021-32839, GHSA-p5w8-wqhj-9hhf, PYSEC-2021-333, SUSE-SU-2021:3857-1, UBUNTU-CVE-2021-32839, openSUSE-SU-2021:3857-1 and 1 more.

Is CVE-2021-32839 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free