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

sqlparse Updated 02 Oct 2025

Summary

20/09/2021
N/A
Yes i
High
7.5

UBUNTU-CVE-2021-32839: sqlparse is a non-validating SQL parser module for Python. Affects sqlparse versions < 0.4.1-1ubuntu1. Fixed in 0.4.1-1ubuntu1. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

Background

sqlparse is a non-validating SQL parser module for Python, widely used for parsing SQL statements and formatting them. It provides functionalities to manipulate SQL queries, making it easier for developers to work with SQL in Python applications. However, certain versions of sqlparse are vulnerable to a Regular Expression Denial of Service (ReDoS) attack, which can lead to performance degradation when processing specific SQL comments.

Vulnerability Detail

The vulnerability identified as CVE-2021-32839 affects sqlparse versions 0.4.0 and 0.4.1. It arises from a regular expression that may cause exponential backtracking when processing strings containing many repetitions of '\r\n' in SQL comments. This can lead to significant delays or crashes in applications that rely on the formatting feature of sqlparse, particularly when the 'strip_comments' option is enabled. The impact of this vulnerability is classified with a CVSS score of 7.5, indicating a high severity level.

How To Fix

Minimum fixed version

0.4.1-1ubuntu1

This is the first release that contains the fix.

sudo apt-get install --only-upgrade sqlparse

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a temporary workaround, avoid using the 'sqlformat.format' function with the 'strip_comments=True' option or refrain from using the '--strip-comments' command line flag when utilizing the sqlformat command line tool.

Conclusion

CVE-2021-32839 is a significant vulnerability in the sqlparse package that can lead to performance issues in applications. Users are strongly advised to update to the patched version 0.4.2 or later to mitigate the risks associated with this vulnerability. In the meantime, workarounds are available to reduce exposure.

See every vulnerability recorded for sqlparse →

Share this vulnerability

FAQ

CVE-2021-32839 is a vulnerability in the sqlparse package that allows for a Regular Expression Denial of Service (ReDoS) attack, affecting the performance of applications using this package.

The vulnerability affects sqlparse versions 0.4.0 and 0.4.1.

You can use the Vulert playground at Vulert Scanner to check if your application is affected by this vulnerability without requiring any signup.

If immediate updates are not possible, you can use the provided workaround to mitigate the risk by avoiding the use of the 'strip_comments' option.

The CVSS score of CVE-2021-32839 is 7.5, indicating a high severity level.

Related vulnerabilities

Recent vulnerabilities recorded for sqlparse.

How To Fix

Minimum fixed version

0.4.1-1ubuntu1

This is the first release that contains the fix.

sudo apt-get install --only-upgrade sqlparse

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback