# CVE-2021-21236: Regular Expression Denial of Service in CairoSVG

> An attacker can cause a denial of service by providing a malicious SVG file that triggers excessive CPU usage in the CairoSVG library.

- **Severity:** Medium 5.7 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 6 Jan 2021
- **Updated:** 3 Aug 2024
- **Also known as:** DEBIAN-CVE-2021-21236, GHSA-hq37-853p-g5cf, MGASA-2021-0149, PYSEC-2021-5, UBUNTU-CVE-2021-21236

## What is CVE-2021-21236?

CVE-2021-21236 is a medium-severity denial of service vulnerability in Kozea CairoSVG, published on 6 Jan 2021. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.

### Official description

CairoSVG is a Python (pypi) package. CairoSVG is an SVG converter based on Cairo. In CairoSVG before version 2.5.1, there is a regular expression denial of service (REDoS) vulnerability. When processing SVG files, the python package CairoSVG uses two regular expressions which are vulnerable to Regular Expression Denial of Service (REDoS). If an attacker provides a malicious SVG, it can make cairosvg get stuck processing the file for a very long time. This is fixed in version 2.5.1. See Referenced GitHub advisory for more information.

Weakness: CWE-400 (Uncontrolled Resource Consumption)

## Which versions are affected by CVE-2021-21236?

3 open source packages ship an affected version, including cairosvg and CairoSVG. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `cairosvg` | PyPI | All versions | 2.5.1 |
| `cairosvg` | PyPI | All versions | 2.5.1 |
| `CairoSVG` | PyPI | All versions | 2.5.1 |

Products: Courtbouillon Cairosvg.

## How do I fix CVE-2021-21236?

Upgrade cairosvg to 2.5.1 or later.

## Is CVE-2021-21236 being exploited?

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

## Other vulnerabilities in Kozea CairoSVG

- [CVE-2023-27586](https://insights.sbomify.com/CVE-2023-27586/): CairoSVG improperly processes SVG files loaded from external resources (critical 9.9)
- [CVE-2026-31899](https://insights.sbomify.com/CVE-2026-31899/): CairoSVG vulnerable to Exponential DoS via recursive <use> element amplification (high 7.5)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-21236 and fix it if it is affected.

What it is: CVE-2021-21236 is a medium-severity denial of service vulnerability in Kozea CairoSVG, published on 6 Jan 2021. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2021-21236 in the wild and no public exploit code.

Affected packages and fixed versions:
- cairosvg (PyPI): affected all versions; fixed in 2.5.1
- cairosvg (PyPI): affected all versions; fixed in 2.5.1
- CairoSVG (PyPI): affected all versions; fixed in 2.5.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-2021-21236/ (Markdown: https://insights.sbomify.com/CVE-2021-21236/index.md)
```

## Sources

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

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