SECURITY · DEVELOPER GUIDE

# How to render HTML to PDF safely in a SaaS backend

A headless browser is not just a document formatter. It is a browser process inside your infrastructure. Treat the HTML and every resource it can reach as untrusted input.

## Start with the threat model

When a backend accepts HTML from users, templates or integrations, the renderer may process attacker-controlled markup. A browser that can execute scripts or fetch arbitrary URLs can turn a PDF endpoint into a route toward internal services, metadata endpoints, local files or unexpected third-party requests.

## 1. Disable page JavaScript

Most invoices and reports can be rendered from static HTML and CSS. Disable JavaScript in the page context unless your product has a validated requirement for it. This is not a replacement for OS/container isolation.

## 2. Block outbound and local network requests

Use request interception or a network policy to deny requests from the rendering browser by default. Be careful with redirects, IPv6, alternate IP encodings and DNS rebinding. A deny-by-default policy is safer than attempting to enumerate every internal address.

## 3. Isolate the renderer

Run Chrome in a constrained container or worker with least privilege. Do not mount application secrets, SSH keys, source repositories or writable host directories into the renderer. Keep Chromium patched and retain its sandbox where the environment allows it.

## 4. Enforce resource limits

Set maximum HTML size, request duration, page count, memory and concurrency. Rate-limit by user and API key. Reserve monthly quota atomically so parallel requests cannot exceed plan limits, and release the reservation if rendering fails.

## 5. Avoid leaking document data

Do not log full HTML, customer records or PDF contents by default. Log request IDs, account IDs, execution times, page counts and safe error categories. Define retention and deletion policies before accepting customer data.

## 6. Be precise about “secure”

Disabling JavaScript and remote requests reduces attack surface; it does not make an application automatically secure. Document runtime isolation, dependencies, limits, storage, retention and incident response. Never claim a certification you have not earned.

## Vervant's current approach

The Vervant prototype disables page scripts, intercepts browser requests, exposes revocable API keys and enforces monthly quotas. Its current local renderer launches Chromium inside an outer Bubblewrap boundary: unprivileged user, network, PID, IPC and UTS namespaces; dropped capabilities; a read-only root filesystem; masked home/application/data paths; and a per-render temporary profile. The browser uses a debugging pipe, not a TCP debugging port. A regression test verifies that Chromium cannot reach a server bound to the host's 127.0.0.1. Chromium's own --no-sandbox flag remains enabled inside this outer boundary because its nested sandbox does not start in this environment. The target hosting container has not yet been built or tested, and its seccomp/runtime policy may restrict the namespaces Bubblewrap needs. The hosted service remains offline and is not accepting production, confidential or sensitive documents. This prototype has not received an independent security audit or certification.
