SSRF Risks When Applications Use `html2pdf`
The Rust html2pdf library opens a local HTML file in headless Chromium and prints it to PDF. If an application gives it HTML supplied by a user, that user can include URLs for Chromium to load. The resulting requests originate from the server running the conversion.
This applies to services that accept HTML uploads or insert unescaped user input into a document before converting it. Converting trusted local files with the CLI does not give an attacker this input path.
Requests from the conversion server
An uploaded HTML document could include:
1
<img src="http://127.0.0.1:8080/admin/status">
The URL points at the conversion serverās loopback interface. Chromium can request it even if the response is not a valid image. The request comes from the conversion server, not the userās machine.
An attacker could also target other internal hosts or a cloud metadata address. Images, stylesheets, fonts, frames, and scripts can all initiate requests. This is server-side request forgery (SSRF) through document rendering, an attack class covered by OWASP.
Making a request is different from reading its response. Chromiumās origin rules may prevent a script from reading it, and the response may not appear in the PDF. A blind request might still trigger an internal action or affect the conversion time or result. The application and its network determine which outcomes are possible.
Code path
browser_config() gives each conversion a temporary Chromium profile. It does not configure a network allowlist or block requests to private addresses.
The input path becomes a file:// URL in html_to_pdf():
1
let input = format!("file://{os}");
render() then opens that URL in Chromium:
1
page.goto(file_url).await.map_err(Error::browser)?;
Chromium then handles the URLs referenced by the page. html2pdf does not restrict those URLs before rendering.
Local test procedure
On an isolated test machine, start a local HTTP server on port 8765:
1
python3 -m http.server 8765 --bind 127.0.0.1
In another directory, save this as probe.html:
1
2
3
<!doctype html>
<title>PDF request test</title>
<img src="http://127.0.0.1:8765/probe.png">
Run the converter with the load milestone to wait for the image request:
1
html2pdf --wait-for load probe.html
The HTTP serverās access log should show a request for /probe.png. I could not run this test in the review environment because it had no Chrome or Chromium executable. The steps above are a test procedure, not a claimed reproduction.
Local files
The file:// input alone does not mean a page can include other local files in the PDF. Chromium restricts which local files a page can load and read; its documentation describes those restrictions.
Chromium runs with the converter userās operating system permissions. html2pdf does not create a filesystem boundary. In a container, files inside the container and any mounted host paths are the relevant exposure.
Conversion limits
The 20-second timeout covers the wait for a page lifecycle event. Navigation, an optional extra wait, PDF generation, and browser shutdown sit outside that timeout. The library does not cap memory or output size.
Large or script-heavy HTML could occupy a conversion worker or consume memory. Whether this causes a denial of service depends on the applicationās queue, concurrency limits, and worker isolation.
Limits for applications accepting untrusted HTML
Run conversions in a low-privilege worker with access only to required files. Block internal networks and cloud metadata endpoints from that worker. Limit the duration, memory, concurrency, and output size of the complete job. Disable JavaScript and remote resources if the documents do not need them. Keep Chromium updated and leave its sandbox enabled. OWASP recommends controls for server-side document rendering.