CVE-2021-32839:Regular Expression Denial of Service (ReDoS) vulnerability in sqlparse Python module versions 0.4.0 and 0.4.1 when processing SQL comments containing many repetitions of '\r\n'.

splash
Back

Description Preview

sqlparse is a non-validating SQL parser module for Python. In versions 0.4.0 and 0.4.1, there is a Regular Expression Denial of Service (ReDoS) vulnerability that can be triggered when processing SQL comments containing many repetitions of '\r\n' characters. The vulnerable regular expression can cause exponential backtracking, leading to excessive CPU usage and potential denial of service. This vulnerability only affects the formatting feature that removes comments from SQL statements, specifically when using the sqlformat.format function with strip_comments=True or the --strip-comments command line flag.

Overview

The vulnerability exists in the comment stripping functionality of sqlparse, a popular Python SQL parsing library. When processing SQL statements with comments containing numerous '\r\n' sequences, the regular expression used for comment handling can enter an exponential backtracking state. This can cause the application to become unresponsive or consume excessive system resources when parsing specially crafted SQL inputs. An attacker could potentially exploit this vulnerability to cause denial of service by submitting SQL statements with maliciously crafted comments designed to trigger the backtracking behavior.

Remediation

  1. Update to sqlparse version 0.4.2 or later, which contains the fix for this vulnerability.
  2. If updating is not immediately possible, implement the following workaround:
    • Avoid using the sqlformat.format function with the strip_comments=True parameter
    • Do not use the --strip-comments command line flag when using the sqlformat command line tool
  3. Consider implementing input validation to reject SQL statements with suspiciously large or repetitive comment sections before passing them to sqlparse.
  4. Monitor system resource usage when processing SQL statements with comments to detect potential exploitation attempts.

References

  1. GitHub Security Advisory: https://github.com/andialbrecht/sqlparse/security/advisories/GHSA-p5w8-wqhj-9hhf
  2. Fix Commit: https://github.com/andialbrecht/sqlparse/commit/8238a9e450ed1524e40cb3a8b0b3c00606903aeb
  3. CVE Details: CVE-2021-32839
  4. OWASP Regular Expression Denial of Service: https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS

Industry ExposureMost to least
This section illustrates the prevalence of a specific Common Vulnerabilities and Exposures (CVE) across various industries based on customer reports. The ranking displays industries from the most to least affected by this particular vulnerability, offering valuable insight into where this CVE has been most frequently observed. This information can help organizations within these sectors prioritize their security efforts, understand their relative risk exposure compared to their peers, and focus remediation strategies where they are most needed. By understanding the industry-specific impact, organizations can make more informed decisions regarding patching, resource allocation, and overall risk management related to this CVE.

  1. Finance and Insurance
    Finance and Insurance
  2. Health Care & Social Assistance
    Health Care & Social Assistance
  3. Management of Companies & Enterprises
    Management of Companies & Enterprises
  4. Professional, Scientific, & Technical Services
    Professional, Scientific, & Technical Services
  5. Retail Trade
    Retail Trade
  6. Arts, Entertainment & Recreation
    Arts, Entertainment & Recreation
  7. Educational Services
    Educational Services
  8. Manufacturing
    Manufacturing
  9. Public Administration
    Public Administration
  10. Transportation & Warehousing
    Transportation & Warehousing
  11. Accommodation & Food Services
    Accommodation & Food Services
  12. Administrative, Support, Waste Management & Remediation Services
    Administrative, Support, Waste Management & Remediation Services
  13. Agriculture, Forestry Fishing & Hunting
    Agriculture, Forestry Fishing & Hunting
  14. Construction
    Construction
  15. Information
    Information
  16. Mining
    Mining
  17. Other Services (except Public Administration)
    Other Services (except Public Administration)
  18. Real Estate Rental & Leasing
    Real Estate Rental & Leasing
  19. Utilities
    Utilities
  20. Wholesale Trade
    Wholesale Trade

Focus on What Matters

  1. See Everything.
  2. Identify True Risk.
  3. Proactively Mitigate Threats.

Let's talk!

background
Armis Vulnerability Intelligence Database