Vulnerability record · PyPI
PYSEC-0000-weasyprint-GHSA-jf6q-chmf-3h3v
Description
url_fetcher is WeasyPrint's documented mechanism for restricting resource loading - applications use it to block file://, internal hosts, etc. when rendering untrusted input.
Two write_pdf() channels ignore the document's url_fetcher and build a fresh default URLFetcher() instead. A restrictive fetcher set on HTML() is silently bypassed for:
xmp_metadata=[url] - the URL is fetched and the bytes are embedded verbatim in the output PDF. This is an arbitrary local file read when the path is attacker-influenced.stylesheets=[url_or_path] - the sheet is fetched and applied. This is SSRF / arbitrary local-or-internal resource loading, and it is transitive: the permissive fetcher propagates through the whole @import / url() graph.Applications affected are those that (1) run WeasyPrint server-side, (2) set a restrictive url_fetcher to block file:// or internal hosts, and (3) forward an attacker-influenced URL/path into either parameter - e.g. PDF rendering APIs, invoice/report generators, document SaaS.
All versions through current main - v69.0, commit 2945986160dedd97a7547be03805b667964e422a.
select_source() defaults to a fresh fetcher when none is passed (weasyprint/urls.py):
def select_source(guess=None, filename=None, url=None, ..., url_fetcher=None, ...):
...
if url_fetcher is None:
url_fetcher = URLFetcher()
Five of the seven resource-loading sites thread the document's fetcher correctly:
<link rel=stylesheet> in weasyprint/css/__init__.py<style> in weasyprint/css/__init__.py@import in weasyprint/css/__init__.py@font-face / local() in weasyprint/text/fonts.py@color-profile src in weasyprint/css/__init__.py<img>, CSS url(), SVG) in weasyprint/images.pyTwo do not — they build a fresh default fetcher instead:
write_pdf(xmp_metadata=[...]) in…Manual fix · PyPI
pip install --upgrade "weasyprint>=70.0"Sources