{"id":"CVE-2021-21236","aliases":["CVE-2021-21236","GHSA-hq37-853p-g5cf","PYSEC-2021-5"],"related":[],"kind":"vulnerability","state":"published","title":"Regular Expression Denial of Service in CairoSVG","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"# Doyensec Vulnerability Advisory \n\n* Regular Expression Denial of Service (REDoS) in cairosvg\n* Affected Product: CairoSVG v2.0.0+\n* Vendor: https://github.com/Kozea\n* Severity: Medium\n* Vulnerability Class: Denial of Service\n* Author(s): Ben Caller ([Doyensec](https://doyensec.com))\n\n## Summary\n\nWhen processing SVG files, the python package CairoSVG uses two regular expressions which are vulnerable to Regular Expression Denial of Service (REDoS).\nIf an attacker provides a malicious SVG, it can make cairosvg get stuck processing the file for a very long time.\n\n## Technical description\n\nThe vulnerable regular expressions are\n\nhttps://github.com/Kozea/CairoSVG/blob/9c4a982b9a021280ad90e89707eacc1d114e4ac4/cairosvg/colors.py#L190-L191\n\nThe section between 'rgb(' and the final ')' contains multiple overlapping groups.\n\nSince all three infinitely repeating groups accept spaces, a long string of spaces causes catastrophic backtracking when it is not followed by a closing parenthesis.\n\nThe complexity is cubic, so doubling the length of the malicious string of spaces makes processing take 8 times as long.\n\n## Reproduction steps\n\nCreate a malicious SVG of the form:\n\n    <svg width=\"1\" height=\"1\"><rect fill=\"rgb(                     ;\"/></svg>\n\nwith the following code:\n\n    '<svg width=\"1\" height=\"1\"><rect fill=\"rgb(' + (' ' * 3456) + ';\"/></svg>'\n\nNote that there is no closing parenthesis before the semi-colon.\n\nRun cairosvg e.g.:\n\n    cairosvg cairo-redos.svg -o x.png\n\nand notice that it hangs at 100% CPU. Increasing the number of spaces increases the processing time with cubic complexity.\n\n## Remediation\n\nFix the regexes to avoid overlapping parts. Perhaps remove the [ \\n\\r\\t]* groups from the regex, and use .strip() on the returned capture group.\n\n## Disclosure timeline\n\n- 2020-12-30: Vulnerability disclosed via email to CourtBouillon","format":"markdown","source":"ghsa"},{"lang":"es","text":"CairoSVG es un paquete de Python (pypi).&#xa0;CairoSVG es un conversor de SVG basado en Cairo.&#xa0;En CairoSVG versiones anteriores a 2.5.1, se presenta de denegación de servicio de expresión regular (REDoS).&#xa0;Cuando se procesan archivos SVG, el paquete de python CairoSVG utiliza dos expresiones regulares que son vulnerables a una Denegación de Servicio de Expresiones Regulares (REDoS).&#xa0;Si un atacante proporciona un SVG malicioso, puede hacer que cairosvg se atasque al procesar el archivo durante mucho tiempo.&#xa0;Esto es corregido en la versión 2.5.1.&#xa0;Consulte el aviso Referenced GitHub para obtener más información","source":"nvd"}],"published":"2021-01-06T16:57:50.000Z","modified":"2026-09-10T03:49:14.069Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H","score":5.7,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:N/I:N/A:H","score":5.7,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"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","rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H","score":5.5,"rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:N/AC:M/Au:N/C:N/I:N/A:P","score":4.3,"rating":"MEDIUM"}],"cwes":["CWE-400"],"affected":[{"ranges":[{"version":"< 2.5.1","status":"affected"}],"vendor":"Kozea","product":"CairoSVG","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.5.1"}],"ecosystem":"PyPI","package":"cairosvg","purl":"pkg:pypi/cairosvg","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"2.5.1"}],"vendor":"courtbouillon","product":"cairosvg","cpe":"cpe:2.3:a:courtbouillon:cairosvg:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"git","introduced":"0","status":"affected","fixed":"cfc9175e590531d90384aa88845052de53d94bf3"},{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.5.1"}],"ecosystem":"PyPI","package":"cairosvg","purl":"pkg:pypi/cairosvg","repo":"https://github.com/Kozea/CairoSVG","source":"pysec"}],"references":[{"url":"https://github.com/Kozea/CairoSVG/security/advisories/GHSA-hq37-853p-g5cf","tags":["advisory","exploit","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://pypi.org/project/CairoSVG/","tags":["package","product","third-party-advisory","x-refsource-misc","x-transferred"],"sources":["cvelist","nvd","pysec"]},{"url":"https://github.com/Kozea/CairoSVG/commit/cfc9175e590531d90384aa88845052de53d94bf3","tags":["fix","patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/Kozea/CairoSVG/releases/tag/2.5.1","tags":["release-notes","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-21236","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/Kozea/CairoSVG","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/cairosvg/PYSEC-2021-5.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://pypi.org/project/CairoSVG","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-21236","url":"https://www.cve.org/CVERecord?id=CVE-2021-21236","licence":"CVE Terms of Use","modified":"2024-08-03T18:09:15.166Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-hq37-853p-g5cf","url":"https://github.com/advisories/GHSA-hq37-853p-g5cf","licence":"CC-BY-4.0","modified":"2026-09-10T03:49:14.069Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-21236","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-21236","licence":"Public domain","modified":"2026-06-17T03:35:05.927Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2021-5","url":"https://osv.dev/vulnerability/PYSEC-2021-5","licence":"CC-BY-4.0","modified":"2023-11-08T04:04:38.945Z"}],"updatedAt":"2026-11-25T22:57:59.153Z","epss":{"score":0.01362,"percentile":0.72575,"date":"2026-12-01T12:00:22.000Z"}}