Skip to content
SSRF Write-up Intermediate

Breaking mPDF with regex and logic

mPDF extracts @import URLs from the entire HTML input, not just CSS, so an attacker can trigger server-side requests even when angle brackets are sanitised. This allows blind SSRF, port scanning, and via gopher, interaction with internal services like Redis to write files.

medium.com

Published on medium.com

mPDF is an open source PHP library for generating PDFs from HTML.

brun0ne, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The library applies a regular expression to the entire HTML input to find @import rules, rather than restricting the search to CSS contexts.

Impact

An attacker could make the server send requests to internal or external systems, enabling blind SSRF, port scanning, and potentially file write via gopher to services like Redis; the text notes this behaviour is not considered a vulnerability by the maintainers.

What the attacker needed

Application passes user input to mPDF; input allows characters @, (, ), :, /; server can make outbound requests

The fix

The library should restrict @import extraction to actual CSS contexts, or users should disallow special characters like @, (, ), :, / in user input.

How it was found

  1. Sanitise user input with htmlentities to prevent HTML tags.
  2. Insert the sanitised input into an HTML template and pass it to mPDF's WriteHTML.
  3. Submit a POST request with text containing an @import rule pointing to an external URL.
  4. Observe the server making an outbound request to that URL.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

mPDF is a tool that turns HTML into PDF files. It looks for special CSS rules called @import to load stylesheets, but it searches the whole input instead of just the style section. So even if you block HTML tags, someone can type a fake @import line and make the server fetch a URL, which can be used to probe internal systems.

What is SSRF?

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.