# CVE-2024-36039: PyMySQL SQL Injection vulnerability

> Attackers can execute arbitrary SQL commands via untrusted JSON input due to improper key escaping in PyMySQL.

- **Severity:** Medium 6.3 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 21 May 2024
- **Updated:** 21 Nov 2024
- **Also known as:** ALSA-2024:4244, ALSA-2024:4245, ALSA-2024:9193, ALSA-2024:9194, AZL-43726, AZL-44457, CLSA-2026-1768435940, DEBIAN-CVE-2024-36039, DLA-3822-1, DSA-5700-1, GHSA-v9hf-5j83-6xpp, OESA-2024-1719, PYSEC-2026-502, RHSA-2024:4244, RHSA-2024:4245, RHSA-2024:9193, RHSA-2024:9194, RLSA-2024:4244, RLSA-2024:4245, RLSA-2024:9193, RLSA-2024:9194, ROOT-APP-PYPI-CVE-2024-36039, SUSE-SU-2024:1855-1, SUSE-SU-2024:1925-1, UBUNTU-CVE-2024-36039, USN-6801-1, openSUSE-SU-2024:13993-1, openSUSE-SU-2026:11995-1

## What is CVE-2024-36039?

CVE-2024-36039 is a medium-severity SQL injection vulnerability in n/a, published on 21 May 2024. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

PyMySQL through 1.1.0 allows SQL injection if used with untrusted JSON input because keys are not escaped by escape_dict.

Weakness: CWE-89 (Improper Neutralization of Special Elements used in an SQL Command)

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

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `pymysql` | PyPI | All versions | 1.1.1 |
| `pymysql` | PyPI | All versions | 1.1.1 |
| `pymysql` | PyPI | All versions | 1.1.1 |
| `python3.11-PyMySQL` | AlmaLinux:8 | All versions | 1.0.2-2.el8_10 |
| `python3.12-PyMySQL` | AlmaLinux:8 | All versions | 1.1.0-3.el8_10 |
| `python3.11-PyMySQL` | AlmaLinux:9 | All versions | 1.0.2-2.el9 |
| `python3.11-PyMySQL+rsa` | AlmaLinux:9 | All versions | 1.0.2-2.el9 |
| `python3.12-PyMySQL` | AlmaLinux:9 | All versions | 1.1.0-3.el9 |
| `python3.12-PyMySQL+rsa` | AlmaLinux:9 | All versions | 1.1.0-3.el9 |
| `python3.11-PyMySQL` | Red Hat:enterprise_linux:8::appstream | All versions | 0:1.0.2-2.el8_10 |
| `python3.12-PyMySQL` | Red Hat:enterprise_linux:8::appstream | All versions | 0:1.1.0-3.el8_10 |
| `python3.11-PyMySQL` | Red Hat:enterprise_linux:9::appstream | All versions | 0:1.0.2-2.el9 |
| `python3.11-PyMySQL+rsa` | Red Hat:enterprise_linux:9::appstream | All versions | 0:1.0.2-2.el9 |
| `python3.12-PyMySQL` | Red Hat:enterprise_linux:9::appstream | All versions | 0:1.1.0-3.el9 |
| `python3.12-PyMySQL+rsa` | Red Hat:enterprise_linux:9::appstream | All versions | 0:1.1.0-3.el9 |
| `python3.11-PyMySQL` | Rocky Linux:8 | All versions | 0:1.0.2-2.el8_10 |
| `python3.12-PyMySQL` | Rocky Linux:8 | All versions | 0:1.1.0-3.el8_10 |
| `python3.11-PyMySQL` | Rocky Linux:9 | All versions | 0:1.0.2-2.el9 |
| `python3.12-PyMySQL` | Rocky Linux:9 | All versions | 0:1.1.0-3.el9 |
| `python-PyMySQL` | SUSE:Linux Enterprise Module for Package Hub 15 SP5 | All versions | 0.7.11-150000.3.3.1 |
| `python-PyMySQL` | SUSE:Linux Enterprise Module for Package Hub 15 SP6 | All versions | 0.7.11-150000.3.3.1 |
| `python-PyMySQL` | openSUSE:Leap 15.5 | All versions | 0.7.11-150000.3.3.1 |
| `python-PyMySQL` | openSUSE:Leap 15.6 | All versions | 1.1.0-150600.3.3.1 |
| `python-PyMySQL` | openSUSE:Tumbleweed | All versions | 1.2.0-1.2 |

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

Upgrade pymysql to 1.1.1 or later.

## Is CVE-2024-36039 being exploited?

There is no known exploitation of CVE-2024-36039 in the wild and no public exploit code.

Public exploit code:

- PoC for CVE-2024-36039: Demonstrating SQL Injection via PyMySQL Object-to-String serialization flaw (github_poc): https://github.com/zenniskayy2k4/CVE-2024-36039_PoC

## Fix prompt for AI coding agents

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

What it is: CVE-2024-36039 is a medium-severity SQL injection vulnerability in n/a, published on 21 May 2024. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2024-36039 in the wild and no public exploit code.

Affected packages and fixed versions:
- pymysql (PyPI): affected all versions; fixed in 1.1.1
- pymysql (PyPI): affected all versions; fixed in 1.1.1
- pymysql (PyPI): affected all versions; fixed in 1.1.1

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-36039/ (Markdown: https://insights.sbomify.com/CVE-2024-36039/index.md)
```

## Sources

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

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