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

GHSA-hq37-853p-g5cf

HIGHFix: Kozea/CairoSVG@cfc9175

GHSA-hq37-853p-g5cf is a high-severity (CVSS 7.5) Uncontrolled Resource Consumption vulnerability in cairosvg. 1 public exploit reference exists, so weaponization risk is real. O3 Security confirms whether GHSA-hq37-853p-g5cf is actually reachable in your code before you act, and blocks exploitation at runtime until you patch.

Regular Expression Denial of Service in CairoSVG

Also known asCVE-2021-21236PYSEC-2021-5
Published
Jan 6, 2021
Updated
Mar 13, 2026
Affected
1 pkg
Patched
1 / 1
Exploits
1 known
Exploitation data as of Mar 13, 2026 · OSV.dev, NVD, FIRST.org (EPSS)

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.1
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. O3's reachability analysis confirms whether the vulnerable code path is actually invoked in your application, so you act on real exposure instead of every transitive match.

  2. Fix

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

  3. Workarounds

    If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.

  4. How O3 protects you

    O3 pinpoints whether GHSA-hq37-853p-g5cf is reachable in your code and exactly where to fix it, then blocks exploitation in production at runtime until the patched version is deployed.

Tailored to GHSA-hq37-853p-g5cf. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.

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 GHSA-hq37-853p-g5cf in your dependencies?

O3 detects GHSA-hq37-853p-g5cf across PyPI dependencies and uses function-level reachability to confirm whether the vulnerable code path is actually reachable — not just present. No false positives.