StripComments filter contains a regular expression that is vulnerable to ReDOS (Regular Expression Denial of Service)
Published 10 Sept 2021 · Updated 8 Jul 2026
Is your project on an affected sqlparse?
Look after several Python apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Affected package
- Affected
- >=0.4.0 <0.4.2
- Fixed in
- 0.4.2
pip install 'sqlparse>=0.4.2'Details
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 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 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](mailto:albrecht.andi@gmail.com)
Is GHSA-p5w8-wqhj-9hhf in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected sqlparse, and gives you the command that fixes it.
More advisories for sqlparse
- MediumCVE-2026-84305sqlparse: Reindentation of tuple lists causes near-cap quadratic CPU consumption · 1 Sept 2026
- HighCVE-2026-59893sqlparse: Inefficient Regex Handling of Dollar-Quoted SQL Literals Leads to ReDoS (Denial of Service) · 17 Aug 2026
- HighCVE-2026-54284sqlparse: TokenList.__init__ materializes O(subtree) value per group, causing CPU DoS before depth/token caps trigger · 17 Aug 2026
- HighCVE-2026-71491sqlparse: Quadratic O(n²) DoS in group_comments · 17 Aug 2026
- MediumCVE-2026-59894sqlparse: Generated Python and PHP snippets allow SQL string breakout through unescaped backslashes · 17 Aug 2026
- MediumGHSA-27jp-wm6q-gp25sqlparse: formatting list of tuples leads to denial of service · 13 Feb 2026
References
- Linkgithub.com/andialbrecht/sqlparse/security/advisories/GHSA-p5w8-wqhj-9hhf
- Advisorynvd.nist.gov/vuln/detail/CVE-2021-32839
- Linkgithub.com/andialbrecht/sqlparse/commit/8238a9e450ed1524e40cb3a8b0b3c00606903aeb
- Packagegithub.com/andialbrecht/sqlparse
- Linkgithub.com/pypa/advisory-database/tree/main/vulns/sqlparse/PYSEC-2021-333.yaml
- Linklists.debian.org/debian-lts-announce/2024/12/msg00022.html
- Advisorysecuritylab.github.com/advisories/GHSL-2021-107-andialbrecht-sqlparse
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.