Every CVE Search/ Get API key

CVE-2021-21236

Regular Expression Denial of Service in CairoSVG

5.7 MediumFix available

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

1.37%Up 0.1 points since Apr 14, 2021
90%50%10%1%

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 MediumCVSS: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 MediumCVSS: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

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
Record
GHSA-hq37-853p-g5cf
CVSS 4.0
7.7 HighCVSS: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 HighCVSS: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 MediumCVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H
CVSS 3.1
5.5 MediumCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H
CVSS 2.0
4.3 MediumAV: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 MediumCVSS: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 MediumCVSS: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 MediumCVSS: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

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
Record
GHSA-hq37-853p-g5cf
CVSS 4.0
7.7 HighCVSS: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 HighCVSS: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 MediumCVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H
CVSS 3.1
5.5 MediumCVSS: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

Affected packages
PackageAffectedFixed
cairosvg
PyPI
before 2.5.1
2.5.1
py3-cairosvg
Alpine:v3.18
before 2.5.1-r0
2.5.1-r0
py3-cairosvg
Alpine:v3.19
before 2.5.1-r0
2.5.1-r0
py3-cairosvg
Alpine:v3.20
before 2.5.1-r0
2.5.1-r0
py3-cairosvg
Alpine:v3.21
before 2.5.1-r0
2.5.1-r0
py3-cairosvg
Alpine:v3.22
before 2.5.1-r0
2.5.1-r0
py3-cairosvg
Alpine:v3.23
before 2.5.1-r0
2.5.1-r0
py3-cairosvg
Alpine:v3.24
before 2.5.1-r0
2.5.1-r0
cairosvg
Debian:12
before 2.5.0-1.1
2.5.0-1.1
cairosvg
Debian:13
before 2.5.0-1.1
2.5.0-1.1
Show 12 moreShow less
Affected packages
PackageAffectedFixed
cairosvg
Debian:14
before 2.5.0-1.1
2.5.0-1.1
cairosvg
PyPI
before 2.5.1, plus listed versions
0.10.1.10.1.20.20.3
Show 45 moreShow less
0.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-cairosvg
Mageia:7
before 2.2.1-1.1.mga7
2.2.1-1.1.mga7
cairosvg
PyPI
before 2.5.1, plus listed versions
0.10.1.10.1.20.20.3
Show 45 moreShow less
0.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
cairosvg
Ubuntu:20.04:LTS
All versions, plus listed versions
2.4.0-22.4.2-1
None known
cairosvg
Ubuntu:25.10
All versions, plus listed versions
2.7.1-12.7.1-2
None known
cairosvg
Ubuntu:26.10
All versions, plus listed versions
2.8.2-12.9.0-12.9.0-2
None known
python-CairoSVG
SUSE: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-CairoSVG
openSUSE: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-CairoSVG
SUSE: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-CairoSVG
openSUSE: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-CairoSVG
openSUSE:Tumbleweed
From an advisory covering 2 CVEs
before 2.9.0-1.3
2.9.0-1.3

History

History
RecordedChangedSources
affectedOSV
affected
affected, factsOSV
affected, aliases, referencesOSV
aliasesEUVD
first indexedCVE 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

Show 15 moreShow less
This page doesn't list everything

Left out here: 14 versions. The JSON record has them.

MoveEnter Open