# CVE-2021-32839: StripComments filter contains a regular expression that is vulnerable to ReDOS (Regular Expression Denial of Service)

Source: https://junglewise.ai/threats/cve-2021-32839-stripcomments-filter-contains-a-regular-expression-that-is  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2021-09-20  
License: CC BY 4.0 with a link back

CVE-2021-32839 · Severity: low · CVSS 3.1 · Published 2021-09-20

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.

Technologies: [sqlparse (PyPI)](https://junglewise.ai/threats/technologies/sqlparse). Vendors: [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is CVE-2021-32839 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2021-32839 being exploited in the wild.

**How severe is CVE-2021-32839?** Low severity, with a CVSS score of 3.1, published 20 September 2021.

**Which products and versions are affected?** sqlparse (PyPI) ECOSYSTEM:introduced=0.4.0,fixed=0.4.2, GIT:introduced=1499cffcd7c4d635b4297b44d48fb4fe94cf988e,fixed=8238a9e450ed1524e40cb3a8b0b3c00606903aeb|ECOSYSTEM:introduced=0.4.0,fixed=0.4.2.

**Is there a fix for CVE-2021-32839?** Yes. sqlparse (PyPI): upgrade to 0.4.2 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**Am I affected by CVE-2021-32839?** Check whether you run sqlparse (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- sqlparse (PyPI): upgrade to 0.4.2 or later

  ```sh
  pip install "sqlparse>=0.4.2"
  ```


## Affected products

- sqlparse (PyPI) ECOSYSTEM:introduced=0.4.0,fixed=0.4.2, GIT:introduced=1499cffcd7c4d635b4297b44d48fb4fe94cf988e,fixed=8238a9e450ed1524e40cb3a8b0b3c00606903aeb|ECOSYSTEM:introduced=0.4.0,fixed=0.4.2

## Identifiers

- CVE-2021-32839
- GHSA-p5w8-wqhj-9hhf
- PYSEC-2021-333

## Related threats

- [sqlparse quadratic CPU consumption in reindent filter](https://junglewise.ai/threats/cve-2026-84305-sqlparse-quadratic-cpu-consumption-in-reindent-filter)
- [sqlparse quadratic DoS in group_comments](https://junglewise.ai/threats/cve-2026-71491-sqlparse-quadratic-dos-in-group-comments)
- [sqlparse code injection in Python and PHP output modes](https://junglewise.ai/threats/cve-2026-59894-sqlparse-code-injection-in-python-and-php-output-modes)
- [sqlparse inefficient regex handling in dollar-quoted literals](https://junglewise.ai/threats/cve-2026-59893-sqlparse-inefficient-regex-handling-in-dollar-quoted-literals)
- [sqlparse TokenList CPU denial of service](https://junglewise.ai/threats/cve-2026-54284-sqlparse-tokenlist-cpu-denial-of-service)
