CVE-2021-32839
mediumpriority · track · 21EPSS 0.023 · 84 %ileEURUUSEPSS · scored 2026-10-28
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.
cvss
Technical severity, 0–10. One row per scoring source.
base score 0–10 · higher = more severe · hover a vector to decode⚠ sources disagree · medium–high · 5–7.5
weaknesses
The CWE weakness classes this flaw belongs to.
affected products (8)
Products and version ranges known to be affected.
advisories (2)
Vendor and ecosystem advisories describing this.
- GHSA-p5w8-wqhj-9hhfStripComments filter contains a regular expression that is vulnerable to ReDOS (Regular Expression Denial of Service)2021-09-10ghsa · osvUS
### Impact The formatter function that strips comments from a SQL contains a regular expression that is vulnerable to [ReDoS](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_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 `strip_comments=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](https://codeql.github.com/) query which identifies inefficient regular expressions. You can see the results of the query on python-sqlparse by following [this link](https://lgtm.com/query/2223658096471222354/). ### For more information If you have any questions or comments about this advisory: * Open an issue in [sqlparse issue tracker](https://github.com/andialbrecht/sqlparse/issues) * Email us at [albrecht.andi@gmail.com](mailto:albrecht.andi@gmail.com)
- PYSEC-2021-3332021-09-20vendor · osvUS
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.
also known as (7)
Other names and identifiers for this entity.
sources
Which sources assert this record, and when.
references (14)
External citations — patches, advisories, analysis.
- https://github.com/andialbrecht/sqlparse/commit/8238a9e450ed1524e40cb3a8b0b3c00606903aebcnnvd
- https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-p5w8-wqhj-9hhfcnnvd
- https://nvd.nist.gov/vuln/detail/CVE-2021-32839cnnvd
- https://packetstormsecurity.com/files/164258/Ubuntu-Security-Notice-USN-5085-1.htmlcnnvd
- https://packetstormsecurity.com/files/167709/Red-Hat-Security-Advisory-2022-5498-01.htmlcnnvd
- https://vigilance.fr/vulnerability/sqlparse-overload-via-Regular-Expression-36486cnnvd
- https://www.auscert.org.au/bulletins/ESB-2021.3199cnnvd
- https://www.auscert.org.au/bulletins/ESB-2021.4081cnnvd
Attackers weaponise vulnerabilities like this against internet-exposed services. See what is exposed on your perimeter with a free passive scan.
Free scan