The widely used mPDF PHP library, boasting over 70 million installations on Packagist, harbors a subtle yet critical logic flaw that allows attackers to trigger arbitrary web requests even when user input appears properly sanitized.
The vulnerability stems from how the library processes CSS @import rules, creating a potential gateway for server-side request forgery (SSRF) attacks and reconnaissance of internal networks.
mPDF is a legitimate open-source tool for converting UTF-8-encoded HTML to PDF documents. Its popularity across thousands of PHP applications makes this discovery particularly concerning for the broader web development community.
The flaw, while not officially assigned a CVE ID, represents a significant security consideration for developers who haven’t carefully scrutinized their implementation approach.
The Logic Flaw
The vulnerability centers on mPDF’s CSS parsing mechanism. When processing HTML input, the library uses regex patterns to extract @import url() directives to fetch remote CSS files.
However, the crucial misstep is that the regex operates on the entire HTML document rather than just the CSS sections.
This means maliciously crafted @import statements placed outside legitimate <style> tags can still trigger web requests.
Security researcher Bruno discovered that even with standard PHP sanitization functions like htmlentities()Attackers can bypass protections by injecting specially crafted payloads.
A simple POST request @import url(https://attacker-controlled-domain/payload?.css) can force the server to make outbound connections, completely circumventing the intended sanitization.
The actual danger emerges when combined with the Gopher protocol a network protocol supported by PHP’s cURL library (which mPDF uses).
By crafting Gopher URLs, attackers can send raw TCP data to internal services such as Redis or MySQL running on localhost or on internal networks.
This enables several attack scenarios: port scanning across internal networks, data exfiltration through Redis manipulation, and potential file creation on vulnerable systems.
For example, an attacker could exploit a Redis instance to write arbitrary files by chaining Gopher protocol commands through mPDF’s request mechanism, potentially leading to remote code execution depending on the deployment environment.
The vulnerability was reported to the mPDF maintainers in May 2025. Still, MITRE rejected CVE assignment in October, determining that the finding doesn’t qualify as a security vulnerability because mPDF intentionally makes outbound network requests based on user input.
The maintainers maintain that proper input sanitization remains the developer’s responsibility, not the library’s.
Developers using mPDF should implement strict input validation by disallowing special characters such as @, (, ), :, /, and ? if not explicitly required.
Alternatively, blocking strings containing :// provides additional protection. For systems handling untrusted user input, applying a whitelist-based approach rather than relying solely on HTML entity encoding proves essential.
Find this Story Interesting! Follow us on Google News, LinkedIn and X to Get More Instant Updates