CVE-2024-21520 — djangorestframework
Fix: encode/django-rest-framework@3b41f01CVE-2024-21520 is a Cross-site Scripting (XSS) vulnerability in djangorestframework. A fix is available for djangorestframework — see the affected versions and patch details below.
Cross-site Scripting in djangorestframework
Exploitation Status
Proof-of-concept exploit code exists
- CISA’s SSVC triage found public proof-of-concept exploit code for this CVE, though no confirmed active exploitation.
Exploitation and automatability from CISA’s SSVC triage for CVE-2024-21520.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
Real-World Exposure
djangorestframeworkReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.
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.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐍PyPI | djangorestframework | all versions | 3.15.2pip install --upgrade 'djangorestframework==3.15.2' |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for djangorestframework, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update djangorestframework to 3.15.2 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2024-21520 is resolved across your whole dependency graph.
Workarounds
Escape or sanitise the affected output on the server side rather than relying on client-side filtering, and add a Content-Security-Policy that blocks inline script execution so injected markup cannot run even if it reaches the page.
Fixing This On Your OS
If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.
| Product | Fixed in | Advisory |
|---|---|---|
| Red Hat Ansible Automation Platform 2.4 for RHEL 8 | automation-controller-0:4.5.12-1.el8ap | RHSA-2024:7312 |
Frequently Asked Questions
Is CVE-2024-21520 in your dependencies?
Find it across PyPI, including transitive dependencies.