CVE-2021-32839: GHSL-2021-107: ReDoS (Regular Expression Denial of Service) in python-sqlparse - CVE-2021-32839

Published Sep 10, 2021
·
Updated

Impact The formatter function that strips comments from a SQL contains a regular expression that is vulnerable to ReDoS (Regular Expression Denial of Service). The regular expression may cause exponential backtracking on strings containing many repetitions of '\r\n' in SQL comments.

Patches The issues has been fixed in sqlparse 0.4.2.

Workarounds 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 stripcomments=True or the --strip-comments command line flag when using the sqlformat command line tool.

References This issue was discovered by GitHub team members @erik-krogh and @yoff. It was found using a CodeQL query which identifies inefficient regular expressions. You can see the results of the query on python-sqlparse by following this link.

For more information If you have any questions or comments about this advisory: Open an issue in sqlparse issue tracker Email us at albrecht.andi@gmail.com

Other sources

python-sqlparse contains a regular expression that is vulnerable to ReDoS (Regular Expression Denial of Service).

— GitHub Security Lab

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 stripcomments=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.

The formatter function that strips comments from a SQL contains a regular expression that is vulnerable to ReDoS (Regular Expression Denial of Service). The regular expression may cause exponential backtracking on strings containing many repetitions of '\r\n' in SQL comments.

Reference: https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-p5w8-wqhj-9hhf

— Red Hat

Affected Software

3 affected componentsFixes available
redhat/sqlparse<0.4.2
0.4.2
pip/sqlparse>=0.4.0<0.4.2
0.4.2
Sqlparse Project Sqlparse>=0.4.0<0.4.2

Event History

Sep 10, 2021
Advisory Published
via GitHub·05:56 PM
Sep 20, 2021
CVE Published
via MITRE·05:10 PM
Data Sourced
via MITRE·05:10 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·05:15 PM
RemedyDescriptionSeverityWeaknessAffected Software
Sep 23, 2021
Advisory Published
via GitHub Security Lab·12:00 AM
Data Sourced
via GitHub Security Lab·12:00 AM
Description

Frequently Asked Questions

1

What is the severity of CVE-2021-32839?

CVE-2021-32839 is classified as a medium severity vulnerability due to its potential for Denial of Service through regular expression exploitation.

2

How do I fix CVE-2021-32839?

To fix CVE-2021-32839, upgrade to sqlparse version 0.4.2 or later.

3

What software is affected by CVE-2021-32839?

CVE-2021-32839 affects sqlparse versions before 0.4.2 across multiple sources including Red Hat and pip.

4

What type of vulnerability is CVE-2021-32839?

CVE-2021-32839 is a Regular Expression Denial of Service (ReDoS) vulnerability.

5

Is CVE-2021-32839 easily exploitable?

Yes, CVE-2021-32839 can be easily exploited if an attacker inputs specially crafted strings that leverage the vulnerable regular expression.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203