Summary
A path validation flaw in Dompdf can allow rendered HTML controlled by an attacker to bypass the configured chroot boundary through ambiguous path-prefix matching. When an application renders attacker-influenced HTML and permits local file access, the issue may expose sensitive files outside the intended directory.
Affected context
The vulnerability occurs in Dompdf deployments that use local-resource access during HTML-to-PDF rendering and rely on the chroot validation performed by validateLocalUri(). It becomes risky when an attacker can influence rendered HTML or referenced local resources, and the configured chroot path has sibling directories sharing the same textual prefix.
Exploit preconditions
- Attack surface: HTML-to-PDF rendering with local URI or file access enabled
- Required access: Ability to supply or influence HTML content processed by Dompdf
- Trigger point: Local resource resolution and chroot validation
- Why exploitation is possible: Normalized paths are compared using a string-prefix check, allowing paths in similarly prefixed sibling directories to appear inside the permitted chroot
Why this happens
The underlying bug is an insufficient boundary check during filesystem path validation. After path normalization removes the trailing directory separator from the configured chroot, a simple strpos() prefix comparison treats directories such as /var/www2 as if they were descendants of /var/www. This reflects CWE-20: Improper Input Validation, because the validation logic does not correctly enforce the intended directory relationship.
Potential impact
- Sensitive local files may be disclosed through generated documents
- Application configuration or credential material could be exposed
- Private source code or deployment data may be read
- Further compromise could become possible if exposed files contain secrets or privileged information
General mitigation guidance
Mitigation generally focuses on enforcing canonical directory boundaries rather than relying on raw string prefixes.
Common defensive patterns include:
- Resolve both the requested path and permitted root using canonical filesystem APIs
- Require the resolved path to equal the root or begin with the root followed by a directory separator
- Restrict local-resource access when it is not required for document generation
- Treat rendered HTML and resource references as untrusted input
- Run PDF generation with least-privilege filesystem permissions and isolated service identities
- Avoid placing secrets or sensitive files within readable application directories
These controls reduce exposure even if an attacker can influence document content.
How teams detect issues like this
Organizations can look for:
- Static analysis findings involving raw prefix comparisons for filesystem authorization
- Code review signals such as
strpos()or equivalent checks used without path-boundary validation - Tests covering sibling directories, relative paths, symlinks, and canonicalization edge cases
- Policy checks requiring canonical path comparison before local file access
- Application logs showing unexpected local resource references during PDF generation
Automated security review tools may help identify path-validation patterns, but filesystem-boundary tests remain important.

