An open API service providing security vulnerability metadata for many open source software ecosystems.

Security Advisories: GSA_kwCzR0hTQS1wNXc4LXdxaGotOWhoZs0VtQ

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


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.


The issues has been fixed in sqlparse 0.4.2.


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.


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:

Source: GitHub Advisory Database
Origin: Unspecified
Severity: High
Classification: General
Published: over 2 years ago
Updated: about 1 year ago

CVSS Score: 7.5
CVSS vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

Identifiers: GHSA-p5w8-wqhj-9hhf, CVE-2021-32839
References: Repository:
Blast Radius: 39.8

Affected Packages

Dependent packages: 361
Dependent repositories: 201,134
Downloads: 47,599,969 last month
Affected Version Ranges: >= 0.4.0, < 0.4.2
Fixed in: 0.4.2
All affected versions: 0.4.0, 0.4.1
All unaffected versions: 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.1.10, 0.1.11, 0.1.12, 0.1.13, 0.1.14, 0.1.15, 0.1.16, 0.1.17, 0.1.18, 0.1.19, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.3.0, 0.3.1, 0.4.2, 0.4.3, 0.4.4, 0.5.0