CVE-2021-21236
Regular Expression Denial of Service in CairoSVG
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.
Attack profile
How easy it is to exploit
- Attack vector
- Network
- Complexity
- Low
- Privileges needed
- Low
- User interaction
- Required
What an attacker can affect
- Confidentiality
- None
- Integrity
- None
- Availability
- High
Exploit likelihood
What each source reports
CVE List Score used
5.7
Regular Expression Denial of Service in CairoSVG
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.
- Record
CVE-2021-21236- CVSS 3.1
- 5.7 Medium
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H - Weakness
- CWE-400
- Updated
- 2026-11-02
EUVDEUVD-2021-0039
5.7
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.
- Record
EUVD-2021-0039- CVSS 3.1
- 5.7 Medium
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H - Updated
- 2026-11-03
GitHub AdvisoriesGHSA-hq37-853p-g5cf
7.7
Regular Expression Denial of Service in CairoSVG
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
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
- Record
GHSA-hq37-853p-g5cf- CVSS 4.0
- 7.7 High
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N/E:P - CVSS 3.1
- 7.5 High
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H - Weakness
- CWE-400
- Updated
- 2026-11-02
NVD
5.7
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.
- Record
CVE-2021-21236- CVSS 3.1
- 5.7 Medium
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H - CVSS 3.1
- 5.5 Medium
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H - CVSS 2.0
- 4.3 Medium
AV:N/AC:M/Au:N/C:N/I:N/A:P - Weakness
- CWE-400
- Updated
- 2026-11-02
OSVALPINE-CVE-2021-21236
5.5
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.
- Record
ALPINE-CVE-2021-21236- CVSS 3.1
- 5.5 Medium
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H - Updated
- 2026-11-03
OSV
5.5
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.
- Record
CVE-2021-21236- CVSS 3.1
- 5.5 Medium
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H - Updated
- 2026-11-02
Show 9 moreShow less
OSVDEBIAN-CVE-2021-21236
5.5
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.
- Record
DEBIAN-CVE-2021-21236- CVSS 3.1
- 5.5 Medium
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H - Updated
- 2026-11-02
OSVGHSA-hq37-853p-g5cf
7.7
Regular Expression Denial of Service in CairoSVG
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
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
- Record
GHSA-hq37-853p-g5cf- CVSS 4.0
- 7.7 High
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N/E:P - CVSS 3.1
- 7.5 High
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H - Weakness
- CWE-400
- Updated
- 2026-11-02
OSVUBUNTU-CVE-2021-21236
5.7
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.
- Record
UBUNTU-CVE-2021-21236- CVSS 3.1
- 5.7 Medium
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H - CVSS 3.1
- 5.5 Medium
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H - Updated
- 2026-11-06
OSVMGASA-2021-0149 No score
Updated python-cairosvg packages fix security 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 (CVE-2021-21236).
- Record
MGASA-2021-0149- Updated
- 2026-11-02
OSVopenSUSE-SU-2023:0260-1 No score
Security update for python-CairoSVG
This update for python-CairoSVG fixes the following issues:
-
CVE-2023-27586: Don't allow fetching external files unless explicitly asked for. (boo#1209538)
-
Update to version 2.5.2
- Fix marker path scale
-
Update to version 2.5.1 (boo#1180648, CVE-2021-21236):
- Security fix: When processing SVG files, CairoSVG was using two regular expressions which are vulnerable to Regular Expression Denial of Service (REDoS). If an attacker provided a malicious SVG, it could make CairoSVG get stuck processing the file for a very long time.
- Fix marker positions for unclosed paths
- Follow hint when only output_width or output_height is set
- Handle opacity on raster images
- Don’t crash when use tags reference unknown tags
- Take care of the next letter when A/a is replaced by l
- Fix misalignment in node.vertices
-
Updates for version 2.5.0.
- Drop support of Python 3.5, add support of Python 3.9.
- Add EPS export
- Add background-color, negate-colors, and invert-images options
- Improve support for font weights
- Fix opacity of patterns and gradients
- Support auto-start-reverse value for orient
- Draw images contained in defs
- Add Exif transposition support
- Handle dominant-baseline
- Support transform-origin
- Record
openSUSE-SU-2023:0260-1- Updated
- 2026-11-02
OSVopenSUSE-SU-2023:0272-1 No score
Security update for python-CairoSVG
This update for python-CairoSVG fixes the following issues:
-
CVE-2023-27586: Don't allow fetching external files unless explicitly asked for. (boo#1209538)
-
Update to version 2.5.2
- Fix marker path scale
-
Update to version 2.5.1 (boo#1180648, CVE-2021-21236):
-
Security fix: When processing SVG files, CairoSVG was using two regular expressions which are vulnerable to Regular Expression Denial of Service (REDoS). If an attacker provided a malicious SVG, it could make CairoSVG get stuck processing the file for a very long time.
-
Fix marker positions for unclosed paths
-
Follow hint when only output_width or output_height is set
-
Handle opacity on raster images
-
Don’t crash when use tags reference unknown tags
-
Take care of the next letter when A/a is replaced by l
-
Fix misalignment in node.vertices
-
-
Updates for version 2.5.0.
- Drop support of Python 3.5, add support of Python 3.9.
- Add EPS export
- Add background-color, negate-colors, and invert-images options
- Improve support for font weights
- Fix opacity of patterns and gradients
- Support auto-start-reverse value for orient
- Draw images contained in defs
- Add Exif transposition support
- Handle dominant-baseline
- Support transform-origin
- Record
openSUSE-SU-2023:0272-1- Updated
- 2026-11-02
OSVopenSUSE-SU-2024:13218-1 No score
python310-CairoSVG-2.7.1-1.1 on GA media
These are all security issues fixed in the python310-CairoSVG-2.7.1-1.1 package on the GA media of openSUSE Tumbleweed.
- Record
openSUSE-SU-2024:13218-1- Updated
- 2026-11-02
OSVopenSUSE-SU-2026:11989-1 No score
python313-CairoSVG-2.9.0-1.3 on GA media
These are all security issues fixed in the python313-CairoSVG-2.9.0-1.3 package on the GA media of openSUSE Tumbleweed.
- Record
openSUSE-SU-2026:11989-1- Updated
- 2026-11-02
OSVPYSEC-2021-5 No score
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.
- Record
PYSEC-2021-5- Updated
- 2026-11-02
Affected products
Affected packages
| Package | Affected | Fixed |
|---|---|---|
cairosvgPyPI |
before 2.5.1 | 2.5.1 |
py3-cairosvgAlpine:v3.18 |
before 2.5.1-r0 | 2.5.1-r0 |
py3-cairosvgAlpine:v3.19 |
before 2.5.1-r0 | 2.5.1-r0 |
py3-cairosvgAlpine:v3.20 |
before 2.5.1-r0 | 2.5.1-r0 |
py3-cairosvgAlpine:v3.21 |
before 2.5.1-r0 | 2.5.1-r0 |
py3-cairosvgAlpine:v3.22 |
before 2.5.1-r0 | 2.5.1-r0 |
py3-cairosvgAlpine:v3.23 |
before 2.5.1-r0 | 2.5.1-r0 |
py3-cairosvgAlpine:v3.24 |
before 2.5.1-r0 | 2.5.1-r0 |
cairosvgDebian:12 |
before 2.5.0-1.1 | 2.5.0-1.1 |
cairosvgDebian:13 |
before 2.5.0-1.1 | 2.5.0-1.1 |
Show 12 moreShow less
| Package | Affected | Fixed |
|---|---|---|
cairosvgDebian:14 |
before 2.5.0-1.1 | 2.5.0-1.1 |
cairosvgPyPI |
before 2.5.1, plus listed versions 0.10.1.10.1.20.20.3 Show 45 moreShow less0.3.10.40.4.10.4.20.4.30.4.40.51.01.0.11.0.101.0.111.0.121.0.131.0.141.0.151.0.161.0.171.0.181.0.191.0.21.0.201.0.211.0.221.0.31.0.41.0.51.0.61.0.71.0.81.0.92.0.02.0.0rc12.0.0rc22.0.0rc32.0.0rc42.0.0rc52.0.0rc62.0.12.0.22.0.32.1.02.1.12.1.22.1.32.2.0 |
2.5.1 |
python-cairosvgMageia:7 |
before 2.2.1-1.1.mga7 | 2.2.1-1.1.mga7 |
cairosvgPyPI |
before 2.5.1, plus listed versions 0.10.1.10.1.20.20.3 Show 45 moreShow less0.3.10.40.4.10.4.20.4.30.4.40.51.01.0.11.0.21.0.31.0.41.0.51.0.61.0.71.0.81.0.91.0.101.0.111.0.121.0.131.0.141.0.151.0.161.0.171.0.181.0.191.0.201.0.211.0.222.0.0rc12.0.0rc22.0.0rc32.0.0rc42.0.0rc52.0.0rc62.0.02.0.12.0.22.0.32.1.02.1.12.1.22.1.32.2.0 |
2.5.1 |
cairosvgUbuntu:20.04:LTS |
All versions, plus listed versions 2.4.0-22.4.2-1 |
None known |
cairosvgUbuntu:25.10 |
All versions, plus listed versions 2.7.1-12.7.1-2 |
None known |
cairosvgUbuntu:26.10 |
All versions, plus listed versions 2.8.2-12.9.0-12.9.0-2 |
None known |
python-CairoSVGSUSE:Package Hub 15 SP5 From an advisory covering 2 CVEs |
before 2.5.2-bp155.3.3.1 | 2.5.2-bp155.3.3.1 |
python-CairoSVGopenSUSE:Leap 15.5 From an advisory covering 2 CVEs |
before 2.5.2-bp155.3.3.1 | 2.5.2-bp155.3.3.1 |
python-CairoSVGSUSE:Package Hub 15 SP4 From an advisory covering 2 CVEs |
before 2.5.2-bp154.2.3.1 | 2.5.2-bp154.2.3.1 |
python-CairoSVGopenSUSE:Leap 15.4 From an advisory covering 2 CVEs |
before 2.5.2-bp154.2.3.1 | 2.5.2-bp154.2.3.1 |
python-CairoSVGopenSUSE:Tumbleweed From an advisory covering 2 CVEs |
before 2.9.0-1.3 | 2.9.0-1.3 |
History
| Recorded | Changed | Sources |
|---|---|---|
| affected | OSV | |
| affected | ||
| affected, facts | OSV | |
| affected, aliases, references | OSV | |
| aliases | EUVD | |
| first indexed | CVE List, GitHub Advisories, NVD, OSV |
Dates are when Every CVE recorded each change. Upstream dates may differ.
In short
CVE-2021-21236 is a medium vulnerability (CVSS 5.7) in Courtbouillon Cairosvg, published January 6, 2021. No source lists public exploit code. EPSS puts the chance of exploitation in the next 30 days at 1.37%, the 72nd percentile. Fixed in cairosvg 2.5.1.
References
github.com/Kozea/CairoSVG/security/advisories/GHSA-hq37-853p-g5cf
pypi.org/project/CairoSVG
github.com/Kozea/CairoSVG/commit/cfc9175e590531d90384aa88845052de53d94bf3
github.com/Kozea/CairoSVG/releases/tag/2.5.1
nvd.nist.gov/vuln/detail/CVE-2021-21236
github.com/pypa/advisory-database/tree/main/vulns/cairosvg/PYSEC-2021-5.yaml
Show 15 moreShow less
github.com/advisories/GHSA-hq37-853p-g5cf
security.alpinelinux.org/vuln/CVE-2021-21236
security-tracker.debian.org/tracker/CVE-2021-21236
github.com/Kozea/CairoSVG
advisories.mageia.org/MGASA-2021-0149.html
bugs.mageia.org/show_bug.cgi?id=28122
ubuntu.com/security/CVE-2021-21236
github.com/Kozea/CairoSVG/commit/063185b60588a41d4df661ad70f9f7b699901abc
cve.org/CVERecord?id=CVE-2021-21236
lists.opensuse.org/archives/list/[email protected]/thread/2GIY4HBHI7WUBHUAMEZKWBMEPOUYNCTU
bugzilla.suse.com/1180648
bugzilla.suse.com/1209538
suse.com/security/cve/CVE-2021-21236
suse.com/security/cve/CVE-2023-27586
lists.opensuse.org/archives/list/[email protected]/thread/74KEOEJKIQ5UHFG7M5KN7X37WT37PVYX
Left out here: 14 versions. The JSON record has them.