Skip to content

ee/reporting: restrict PDF renderer URL fetcher to http(s)/data and report assets - #2588

Open
kalt2212 wants to merge 1 commit into
amidaware:developfrom
kalt2212:fix/reporting-pdf-file-fetcher
Open

kalt2212 wants to merge 1 commit into
amidaware:developfrom
kalt2212:fix/reporting-pdf-file-fetcher

Conversation

@kalt2212

Copy link
Copy Markdown

Problem

ee.reporting.utils.generate_pdf renders user-editable template HTML with WeasyPrint and the default URL fetcher, which resolves file:// URLs. Any <img src="file:///etc/passwd"> (or CSS url(), background image, etc.) embedded in report template HTML or rendered markdown makes the PDF renderer read arbitrary local files on the server (e.g. /etc/passwd, /proc/self/environ, SSH keys) and embed the content in the generated PDF that is then downloadable by the user.

Fix

Adds ReportAssetURLFetcher, a URLFetcher subclass, and uses it in generate_pdf:

  • http, https and data URLs keep working (remote images, remote fonts).
  • file:// URLs are kept ONLY when the resolved path is inside REPORT_ASSETS_BASE_PATH, which is what normalize_asset_url(..., type="pdf") legitimately produces when it inlines asset:// report assets as file://{asset.file.path}. Report assets keep rendering exactly as before.
  • Any other file:// path (and other non-http(s)/data schemes) is rejected, so the renderer can no longer read arbitrary local files.

Verification

Runtime-tested against WeasyPrint 70.0 (the version pinned in api/tacticalrmm/requirements.txt), exercising the exact patched code:

  • default fetcher before the patch: <img src="file:///tmp/poc_red.png"> embeds the local file in the PDF (2260 -> 2593 bytes) - arbitrary local read confirmed;
  • patched fetcher: file:///tmp/poc_red.png and file:///etc/passwd are rejected (image omitted, no file read);
  • patched fetcher: file://<REPORT_ASSETS_BASE_PATH>/asset.png still embeds (2260 -> 2589 bytes), so the report asset feature is unaffected.

Added api/tacticalrmm/ee/reporting/tests/test_pdf_url_fetcher.py covering outside-path rejection, inside-path allowance, ../ traversal and non-http protocol rejection.

…eport assets

The report PDF generator used WeasyPrint's default URL fetcher, which
resolves file:// URLs. Template HTML is user-editable, so any <img> or
background URL pointing at file:// made the renderer read arbitrary
local files on the server (e.g. /etc/passwd, /proc/self/environ).

normalize_asset_url(type="pdf") legitimately rewrites asset:// URLs to
file://{asset.file.path} under REPORT_ASSETS_BASE_PATH, so file:// is
kept but restricted to that base path. ftp and other schemes are
rejected as well.
@CLAassistant

CLAassistant commented Nov 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@kalt2212
kalt2212 force-pushed the fix/reporting-pdf-file-fetcher branch from a405f1c to b20f562 Compare November 16, 2026 19:15

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants