{"id":"CVE-2021-32839","aliases":["CVE-2021-32839","GHSA-p5w8-wqhj-9hhf","PYSEC-2021-333"],"related":[],"kind":"vulnerability","state":"published","title":"Regular Expression Denial of Service in sqlparse","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"### Impact\nThe 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.\n\n### Patches\nThe issues has been fixed in sqlparse 0.4.2.\n\n### Workarounds\nOnly 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.\n\n### References\nThis issue was discovered by GitHub team members @erik-krogh and @yoff. It was found using a [CodeQL](https://codeql.github.com/) query which identifies inefficient regular expressions. You can see the results of the query on python-sqlparse by following [this link](https://lgtm.com/query/2223658096471222354/). \n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [sqlparse issue tracker](https://github.com/andialbrecht/sqlparse/issues)\n* Email us at [albrecht.andi@gmail.com](mailto:albrecht.andi@gmail.com)","format":"markdown","source":"ghsa"},{"lang":"es","text":"sqlparse es un módulo analizador de SQL no comprobable para Python. En las versiones 0.4.0 y 0.4.1 de sqlparse, se presenta una vulnerabilidad de Denegación de Servicio por Expresión regular en sqlparse. La expresión regular puede causar un retroceso exponencial en las cadenas que contienen muchas repeticiones de \"\\r\\n\" en los comentarios SQL. Sólo la función de formato que elimina los comentarios de las sentencias SQL esta afectada por esta expresión regular. Como solución, no use la función sqlformat.format con la palabra clave strip_comments=True o el indicador de línea de comandos --strip-comments cuando use la herramienta de línea de comandos sqlformat. Este problema ha sido corregido en sqlparse versión 0.4.2","source":"nvd"}],"published":"2021-09-10T17:56:06.000Z","modified":"2026-07-08T06:29:57.075Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:N/AC:L/Au:N/C:N/I:N/A:P","score":5,"rating":"MEDIUM"}],"cwes":["CWE-400"],"affected":[{"ranges":[{"version":">= 0.4.0, < 0.4.2","status":"affected"}],"vendor":"andialbrecht","product":"sqlparse","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0.4.0","status":"affected","fixed":"0.4.2"}],"ecosystem":"PyPI","package":"sqlparse","purl":"pkg:pypi/sqlparse","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"0.4.0","fixed":"0.4.2"}],"vendor":"sqlparse_project","product":"sqlparse","cpe":"cpe:2.3:a:sqlparse_project:sqlparse:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"git","introduced":"1499cffcd7c4d635b4297b44d48fb4fe94cf988e","status":"affected","fixed":"8238a9e450ed1524e40cb3a8b0b3c00606903aeb"},{"type":"ecosystem","introduced":"0.4.0","status":"affected","fixed":"0.4.2"}],"ecosystem":"PyPI","package":"sqlparse","purl":"pkg:pypi/sqlparse","repo":"https://github.com/andialbrecht/sqlparse","source":"pysec"}],"references":[{"url":"https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-p5w8-wqhj-9hhf","tags":["advisory","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/andialbrecht/sqlparse/commit/8238a9e450ed1524e40cb3a8b0b3c00606903aeb","tags":["fix","patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://lists.debian.org/debian-lts-announce/2024/12/msg00022.html","tags":["web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-32839","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/andialbrecht/sqlparse","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/sqlparse/PYSEC-2021-333.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://securitylab.github.com/advisories/GHSL-2021-107-andialbrecht-sqlparse","tags":["advisory"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-32839","url":"https://www.cve.org/CVERecord?id=CVE-2021-32839","licence":"CVE Terms of Use","modified":"2025-11-03T21:44:47.559Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-p5w8-wqhj-9hhf","url":"https://github.com/advisories/GHSA-p5w8-wqhj-9hhf","licence":"CC-BY-4.0","modified":"2026-07-08T06:29:57.075Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-32839","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-32839","licence":"Public domain","modified":"2026-06-17T03:53:44.140Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2021-333","url":"https://osv.dev/vulnerability/PYSEC-2021-333","licence":"CC-BY-4.0","modified":"2023-11-08T04:06:01.984Z"}],"updatedAt":"2026-11-25T22:58:04.082Z","epss":{"score":0.02339,"percentile":0.84069,"date":"2026-12-01T12:00:22.000Z"}}