# CVE-2024-4340: Passing a heavily nested list to sqlparse.parse() leads to a Denial of Service due to RecursionError.

> Attackers can cause a Denial of Service in applications using sqlparse by submitting heavily nested SQL lists, triggering a RecursionError.

- **Severity:** High 7.5 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 30 Apr 2024
- **Updated:** 3 Nov 2025
- **Also known as:** DEBIAN-CVE-2024-4340, ECHO-d041-0b74-8b13, GHSA-2m57-hf25-phgg, MGASA-2024-0185, OESA-2024-1533, OESA-2024-1603, OESA-2024-1646, PYSEC-2026-1940, RHSA-2024:9984, RHSA-2024:9986, ROOT-APP-PYPI-CVE-2024-4340, SUSE-SU-2024:1767-1, SUSE-SU-2024:1861-1, UBUNTU-CVE-2024-4340, USN-6771-1

## What is CVE-2024-4340?

CVE-2024-4340 is a high-severity denial of service vulnerability in sqlparse, published on 30 Apr 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Passing a heavily nested list to sqlparse.parse() leads to a Denial of Service due to RecursionError.

Weakness: CWE-674 (Uncontrolled Recursion)

## Which versions are affected by CVE-2024-4340?

3 open source packages ship an affected version, including sqlparse.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `sqlparse` | PyPI | All versions | 0.5.0 |
| `sqlparse` | PyPI | All versions | 0.5.0 |
| `sqlparse` | PyPI | All versions | 0.5.0 |
| `python-sqlparse` | Red Hat:openstack:17.1::el8 | All versions | 0:0.4.1-2.el8ost |
| `python3-sqlparse` | Red Hat:openstack:17.1::el8 | All versions | 0:0.4.1-2.el8ost |
| `python-sqlparse` | Red Hat:openstack:17.1::el9 | All versions | 0:0.4.1-2.el9ost |
| `python3-sqlparse` | Red Hat:openstack:17.1::el9 | All versions | 0:0.4.1-2.el9ost |
| `python3-sqlparse` | SUSE:Enterprise Storage 7.1 | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Linux Enterprise High Performance Computing 15 SP3-LTSS | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Linux Enterprise High Performance Computing 15 SP4-ESPOS | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Linux Enterprise High Performance Computing 15 SP4-LTSS | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Linux Enterprise Module for Basesystem 15 SP5 | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Linux Enterprise Module for Basesystem 15 SP6 | All versions | 0.4.2-150300.12.1 |
| `python-sqlparse` | SUSE:Linux Enterprise Module for Public Cloud 15 SP4 | All versions | 0.4.4-150400.6.7.1 |
| `python-sqlparse` | SUSE:Linux Enterprise Module for Public Cloud 15 SP5 | All versions | 0.4.4-150400.6.7.1 |
| `python3-sqlparse` | SUSE:Linux Enterprise Server 15 SP3-LTSS | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Linux Enterprise Server 15 SP4-LTSS | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Linux Enterprise Server for SAP Applications 15 SP3 | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Linux Enterprise Server for SAP Applications 15 SP4 | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Manager Proxy 4.3 | All versions | 0.4.2-150300.12.1 |
| `python3-sqlparse` | SUSE:Manager Server 4.3 | All versions | 0.4.2-150300.12.1 |
| `python-sqlparse` | openSUSE:Leap 15.5 | All versions | 0.4.4-150400.6.7.1 |
| `python3-sqlparse` | openSUSE:Leap 15.5 | All versions | 0.4.2-150300.12.1 |

## How do I fix CVE-2024-4340?

Upgrade sqlparse to 0.5.0 or later.

## Is CVE-2024-4340 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-4340 exists.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-4340 and fix it if it is affected.

What it is: CVE-2024-4340 is a high-severity denial of service vulnerability in sqlparse, published on 30 Apr 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-4340 exists.

Affected packages and fixed versions:
- sqlparse (PyPI): affected all versions; fixed in 0.5.0
- sqlparse (PyPI): affected all versions; fixed in 0.5.0
- sqlparse (PyPI): affected all versions; fixed in 0.5.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-4340/ (Markdown: https://insights.sbomify.com/CVE-2024-4340/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-4340
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-4340
- OSV: https://osv.dev/vulnerability/CVE-2024-4340

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-4340/
Summaries are generated and may contain mistakes; the official description above is the record.
