Your RSA-2048 keys break in 2030. Find every one of them before attackers do.
🐍
🐍 PyPI
Not in CISA KEV
MEDIUM severity

CVE-2021-21236 — cairosvg

MEDIUMFix: Kozea/CairoSVG@cfc9175

CVE-2021-21236 is a medium-severity (CVSS 5.5) Uncontrolled Resource Consumption vulnerability in cairosvg. 1 public exploit reference exists, so weaponization risk is real. A fix is available for cairosvg — see the affected versions and patch details below.

Regular Expression Denial of Service in CairoSVG

Also known asGHSA-hq37-853p-g5cfPYSEC-2021-5
Published
Updated
Affected
1 pkg
Patched
1 / 1
Exploits
1 known
Exploitation data as of Oct 10, 2026 · OSV.dev, NVD, FIRST.org (EPSS)

EPSS Exploitation Probability

via FIRST.org ↗
1.4%probability of exploitation in next 30 days
Lower Risk+0.02%
Lower risk than most CVEs71th percentile — riskier than 71% of all scored CVEsHighest risk
0.00%0.66%1.31%1.97%0.1%1.4%Apr 26Aug 26Oct 26

Probability of exploitation in the next 30 days, from FIRST.org EPSS.

How urgent is this, really

CVE-2021-21236 by exploitation likelihood (EPSS) against impact (CVSS). Outside the shaded patch-first corner.

Where this sits among everything scored

Of 385,738 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Counts from FIRST.org, log-scaled.

Real-World Exposure

1 pkg affected
🐍cairosvg

Real-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

Doyensec Vulnerability Advisory

  • Regular Expression Denial of Service (REDoS) in cairosvg
  • Affected Product: CairoSVG v2.0.0+
  • Vendor: https://github.com/Kozea
  • Severity: Medium
  • Vulnerability Class: Denial of Service
  • Author(s): Ben Caller (Doyensec)

Summary

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.

Technical description

The vulnerable regular expressions are

https://github.com/Kozea/CairoSVG/blob/9c4a982b9a021280ad90e89707eacc1d114e4ac4/cairosvg/colors.py#L190-L191

The section between 'rgb(' and the final ')' contains multiple overlapping groups.

Since all three infinitely repeating groups accept spaces, a long string of spaces causes catastrophic backtracking when it is not followed by a closing parenthesis.

The complexity is cubic, so doubling the length of the malicious string of spaces makes processing take 8 times as long.

Reproduction steps

Create a malicious SVG of the form:

<svg width="1" height="1"><rect fill="rgb(                     ;"/></svg>

with the following code:

'<svg width="1" height="1"><rect fill="rgb(' + (' ' * 3456) + ';"/></svg>'

Note that there is no closing parenthesis before the semi-colon.

Run cairosvg e.g.:

cairosvg cairo-redos.svg -o x.png

and notice that it hangs at 100% CPU. Increasing the number of spaces increases the processing time with cubic complexity.

Remediation

Fix the regexes to avoid overlapping parts. Perhaps remove the [ \n\r\t]* groups from the regex, and use .strip() on the returned capture group.

Disclosure timeline

  • 2020-12-30: Vulnerability disclosed via email to CourtBouillon

Affected Packages

1 total 1 fixed
EcosystemPackageVulnerable rangeFix
🐍PyPIcairosvgall versions2.5.1pip install --upgrade 'cairosvg==2.5.1'

Affected Products

1 product · 1 configurations
Application
cairosvgcourtbouillon
< 2.5.1
range
Exploits & PoCs
1

Research use only. For defensive security, authorized penetration testing, and academic research only. Never execute exploit code against systems without explicit written authorization.

Detection & mitigation playbook

Open-source dependency
  1. Detect

    Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for cairosvg, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.

  2. Fix

    Update cairosvg to 2.5.1 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2021-21236 is resolved across your whole dependency graph.

  3. Workarounds

    Cap what an attacker can consume: apply request size, rate and timeout limits in front of the affected component, and run it with memory and CPU limits so exhaustion degrades one worker rather than the whole service.

Frequently Asked Questions

# Doyensec Vulnerability Advisory * Regular Expression Denial of Service (REDoS) in cairosvg * Affected Product: CairoSVG v2.0.0+ * Vendor: https://github.com/Kozea * Severity: Medium * Vulnerability Class: Denial of Service * Author(s): Ben Caller ([Doyensec](https://doyensec.com)) ## Summary 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. ## Technical description The vu
O3 Security · Impact-Aware SCA

Is CVE-2021-21236 in your dependencies?

Find it across PyPI, including transitive dependencies.

CVE-2021-21236: cairosvg DoS — Fixed in 2.5.1