CVE-2021-32839: GHSL-2021-107: ReDoS (Regular Expression Denial of Service) in python-sqlparse - CVE-2021-32839
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
Remediation
Event History
Frequently Asked Questions
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.
How do I fix CVE-2021-32839?
To fix CVE-2021-32839, upgrade to sqlparse version 0.4.2 or later.
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.
What type of vulnerability is CVE-2021-32839?
CVE-2021-32839 is a Regular Expression Denial of Service (ReDoS) vulnerability.
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.