Summary
Spatie Browsershot can expose local files when attacker-controlled HTML is rendered through setHtml(). Root-relative references in elements such as iframe, img, link, or script may resolve to local file URLs, allowing readable file contents to appear in a returned PDF or screenshot.
Affected context
The issue affects use of Spatie Browsershot's HTML rendering path when supplied HTML can contain attacker-controlled references. The described behavior applies to versions 2.2.0 before 5.5.0. Exposure depends on how the application accepts or constructs HTML, the renderer's file access, and what content is included in the generated PDF or screenshot.
Exploit preconditions
- Attack surface: HTML provided to the Browsershot rendering flow.
- Required access: Ability to influence or supply HTML passed to
setHtml(). - Trigger point: Rendering that HTML into a PDF or screenshot.
- Why exploitation is possible: Root-relative resource references may be resolved as local
file://URLs, and the rendering process may read files available to its operating-system account.
Why this happens
The underlying issue is insufficient control over how HTML resource references are resolved. When attacker-influenced root-relative paths are interpreted as local file URLs, the renderer can access local resources rather than limiting requests to intended content. This maps to CWE-73: External Control of File Name or Path, because externally controlled path information can influence which files the application accesses.
Potential impact
- An attacker may obtain contents of files readable by the rendering process.
- Sensitive configuration, application, or system information could be disclosed in generated output.
- Exposed credentials or other secrets could enable further compromise.
General mitigation guidance
Defensive approaches focus on reducing trust in supplied HTML and restricting the renderer's ability to access local resources.
- Prefer generating HTML from trusted templates and validated, contextually encoded data.
- Restrict or reject local file references and use resource-loading policies that allow only necessary sources.
- Run the rendering process with least privilege and limit its filesystem visibility.
- Isolate rendering workloads from sensitive files and secrets.
- Apply output and input policies that prevent untrusted content from controlling resource paths.
How teams detect issues like this
- Use static analysis to identify HTML rendering paths that accept externally influenced content and calls to
setHtml(). - Review resource-resolution behavior for HTML elements that can load external or local content.
- Check whether rendering processes can access sensitive filesystem locations.
- Enforce application policies that restrict local-resource access and validate HTML inputs.
- Use automated code review tools to help flag unsafe HTML and file-access patterns.

