CVE-2024-21520 Cross-site Scripting in djangorestframework
An attacker can execute arbitrary scripts in a victim's browser via improper sanitization in the break_long_headers template filter.
- Exploited in the wild
- Not known
- Login needed
- Not needed
- Attackable
- Over the internet
- Victim action needed
- A user has to click or open something
- Fix
- Available
What is CVE-2024-21520?
CVE-2024-21520 is a medium-severity cross-site scripting vulnerability in djangorestframework, published on 26 Jun 2024. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Official description
Versions of the package djangorestframework before 3.15.2 are vulnerable to Cross-site Scripting (XSS) via the break_long_headers template filter due to improper input sanitization before splitting and joining with <br> tags.
Weakness: CWE-79
Which versions are affected by CVE-2024-21520?
3 open source packages ship an affected version, including djangorestframework.
| Package | Affected | Fixed in |
|---|---|---|
djangorestframework PyPI | All versions | 3.15.2 |
djangorestframework PyPI | All versions | 3.15.2 |
djangorestframework PyPI | All versions | 3.15.2 |
Linux distribution packages (1)
python-djangorestframework openSUSE:Tumbleweed | All versions | 3.16.1-2.1 |
How do I fix CVE-2024-21520?
Upgrade djangorestframework to 3.15.2 or later.
Escape output for the context it lands in and set a strict Content Security Policy. Upgrading the affected component is the real fix. More about Cross-site scripting.
Is CVE-2024-21520 being exploited?
It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-21520 exists.
Public exploit code: 1 proofs of concept on GitHub.
Sources
Also known as DEBIAN-CVE-2024-21520, GHSA-gw84-84pc-xp82, PYSEC-2026-1304, ROOT-APP-PYPI-CVE-2024-21520, UBUNTU-CVE-2024-21520, openSUSE-SU-2026:10115-1.