Your RSA-2048 keys break in 2030. Find every one of them before attackers do.
🐍
🐍 PyPI
Not in CISA KEV
HIGH severity

CVE-2021-32839 — sqlparse

HIGHFix: andialbrecht/sqlparse@8238a9e

CVE-2021-32839 is a high-severity (CVSS 7.5) Uncontrolled Resource Consumption vulnerability in sqlparse. A fix is available for sqlparse — see the affected versions and patch details below.

StripComments filter contains a regular expression that is vulnerable to ReDOS (Regular Expression Denial of Service)

Also known asGHSA-p5w8-wqhj-9hhfPYSEC-2021-333
Published
Sep 20, 2021
Updated
Jul 15, 2026
Affected
1 pkg
Patched
1 / 1
Exploits
None indexed
Exploitation data as of Oct 1, 2026 · OSV.dev, NVD, FIRST.org (EPSS)

EPSS Exploitation Probability

via FIRST.org ↗
2.3%probability of exploitation in next 30 days
Lower Risk0.00%
Lower risk than most CVEs83th percentile — riskier than 83% of all scored CVEsHighest risk
0.00%1.00%2.00%3.01%0.1%2.3%Apr 26Aug 26Oct 26

Probability of exploitation in the next 30 days, from FIRST.org EPSS.

How urgent is this, really

CVE-2021-32839 by exploitation likelihood (EPSS) against impact (CVSS). Outside the shaded patch-first corner.

Where this sits among everything scored

Of 381,682 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Counts from FIRST.org, log-scaled.

Real-World Exposure

1 pkg affected
🐍sqlparse

Real-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.

Description

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:

Affected Packages

1 total 1 fixed
EcosystemPackageVulnerable rangeFix
🐍PyPIsqlparse≥ 0.4.0&&< 0.4.20.4.2pip install --upgrade 'sqlparse==0.4.2'

Affected Products

1 product · 1 configurations
Application
sqlparsesqlparse_project
≥ 0.4.0 && < 0.4.2
range

Detection & mitigation playbook

Open-source dependency
  1. Detect

    Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for sqlparse, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.

  2. Fix

    Update sqlparse to 0.4.2 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2021-32839 is resolved across your whole dependency graph.

  3. Workarounds

    Cap what an attacker can consume: apply request size, rate and timeout limits in front of the affected component, and run it with memory and CPU limits so exhaustion degrades one worker rather than the whole service.

Fixing This On Your OS

If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.

Red HatModerate
Workaround published by Red Hat
As mitigation, 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.
Source: Red Hat security advisory for CVE-2021-32839 (CC BY 4.0)
ProductFixed inAdvisory
Red Hat Satellite 6.11 for RHEL 8python-sqlparse-0:0.4.2-2.el8pcRHSA-2022:5498

Frequently Asked Questions

### 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 `sqlforma
O3 Security · Impact-Aware SCA

Is CVE-2021-32839 in your dependencies?

Find it across PyPI, including transitive dependencies.

CVE-2021-32839: sqlparse — Fixed in 0.4.2 | O3 Security