CVE-2024-4340

7.5 HIGH

📋 TL;DR

This vulnerability in sqlparse allows attackers to cause a Denial of Service (DoS) by passing heavily nested SQL statements to the sqlparse.parse() function, triggering a RecursionError that crashes the application. It affects any application using vulnerable versions of the sqlparse Python library to parse SQL queries.

💻 Affected Systems

Products:
  • sqlparse Python library
Versions: All versions before 0.5.0
Operating Systems: All operating systems running Python
Default Config Vulnerable: ⚠️ Yes
Notes: Any Python application using sqlparse.parse() with untrusted input is vulnerable. The vulnerability is in the library itself, not dependent on specific configurations.

⚠️ Manual Verification Required

This CVE does not have specific version information in our database, so automatic vulnerability detection cannot determine if your system is affected.

Why? The CVE database entry doesn't specify which versions are vulnerable (no version ranges provided by the vendor/NVD).

🔒 Custom verification scripts are available for registered users. Sign up free to download automated test scripts.

Recommended Actions:
  1. Review the CVE details at NVD
  2. Check vendor security advisories for your specific version
  3. Test if the vulnerability is exploitable in your environment
  4. Consider updating to the latest version as a precaution

⚠️ Risk & Real-World Impact

🔴

Worst Case

Complete service unavailability for applications using sqlparse, requiring manual restart and potentially causing extended downtime.

🟠

Likely Case

Application crashes when processing malicious SQL input, leading to temporary DoS until the service is restarted.

🟢

If Mitigated

Limited impact with proper input validation and rate limiting in place, though the vulnerable library remains a risk.

🌐 Internet-Facing: HIGH - Applications accepting SQL input from untrusted sources (like web forms) are directly vulnerable to DoS attacks.
🏢 Internal Only: MEDIUM - Internal applications could still be exploited by malicious insiders or compromised internal systems.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires only the ability to submit SQL input to the vulnerable function. Proof-of-concept code is publicly available in advisory references.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 0.5.0 and later

Vendor Advisory: https://github.com/advisories/GHSA-2m57-hf25-phgg

Restart Required: Yes

Instructions:

1. Update sqlparse using pip: 'pip install --upgrade sqlparse>=0.5.0'. 2. Restart any applications using sqlparse. 3. Verify the update with 'pip show sqlparse'.

🔧 Temporary Workarounds

Input validation and sanitization

all

Implement input validation to reject heavily nested SQL statements before they reach sqlparse.parse()

Rate limiting

all

Implement rate limiting on endpoints that accept SQL input to reduce DoS impact

🧯 If You Can't Patch

  • Implement strict input validation to reject SQL statements with excessive nesting depth
  • Deploy web application firewalls (WAF) with rules to detect and block recursive SQL patterns

🔍 How to Verify

Check if Vulnerable:

Check sqlparse version with 'pip show sqlparse' or 'python -c "import sqlparse; print(sqlparse.__version__)"'. Versions below 0.5.0 are vulnerable.

Check Version:

python -c "import sqlparse; print('sqlparse version:', sqlparse.__version__)"

Verify Fix Applied:

After updating, verify version is 0.5.0 or higher using the same commands. Test with known malicious nested SQL to ensure no RecursionError occurs.

📡 Detection & Monitoring

Log Indicators:

  • Python RecursionError exceptions in application logs
  • Application crashes or restarts following SQL processing
  • Unusually large or nested SQL queries in logs

Network Indicators:

  • Multiple rapid requests containing SQL payloads to vulnerable endpoints
  • Traffic patterns suggesting DoS attempts

SIEM Query:

source="application.log" AND "RecursionError" AND "sqlparse" OR source="application.log" AND "maximum recursion depth exceeded"

🔗 References

📤 Share & Export