Skip to content
SSRF Write-up Intermediate

From blind SSRF to localhost dirbusting and asset enumeration

WeasyPrint's PDF generator omits the alt text of an image when the image URL is reachable from the server, even if the response is not a valid image. An attacker who can inject image tags could therefore use the presence or absence of alt text in the generated PDF to discover which internal paths and endpoints exist on localhost.

Jovan Šikanja Follow

Published on medium.com

HTML to PDF generators are, in general, known to “very challenging” when it comes to security.

Joshibeast, 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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

HTML to PDF generators are, in general, known to be "very challenging" when it comes to security. If a user is able to inject HTML and/or JavaScript into the HTML that will be used for generating a PDF by the server, SSRF and local file read vulnerabilities may occur. The report points to a list of things that could go wrong in the HackTricks page on server-side XSS in dynamic PDF generation.

Allowing users to inject <img> tags is often considered "safer", because even if the PDF generator is initiating server-side HTTP requests from a privileged environment, the actual SSRF is just the blind one. That is not entirely true: you can try to include internal images, and if the server is vulnerable you will be able to extract data you should not have access to. The report links to a write-up by mike-n1 on turning SSRF into P4 to P2 for that technique.

The researcher came across this exact problem while working on a private bug bounty program. The PDF generator in use was WeasyPrint. The HTML sanitiser only allowed injection of <img> tags, and the researcher was able to leak some internal images, such as Apache icons, by injecting an image that looks like this:

HTML
<img src=http://localhost/path/to/image>

Setup

The report does not describe the program, the application, accounts, roles or the WeasyPrint version. The relevant preconditions are stated directly: the application generates PDFs from HTML with WeasyPrint, the user can inject HTML into that document, and the sanitiser restricts the injection to <img> tags. The researcher's payloads showed the generator could reach localhost.

Finding it

The researcher did not stop at leaking internal images and kept exploring different payloads and tags. There the researcher noticed a strange behaviour in WeasyPrint and its handling of the alt tag.

The two images below compare two different PDFs generated by WeasyPrint. On the left is the injected HTML and on the right is the generated PDF.

From the original on medium.com

The expected behaviour is that if an image is broken or inaccessible, the string entered as the value of the alt tag should be printed instead of the image, so nothing should go wrong there. With WeasyPrint, however, if the img src endpoint is accessible by the server (it does not return 404), the alt tag is not printed. Whether the response is a valid image or not does not matter, and that is the core of the bug.

Exploitation

Step 1: Turn the alt tag into an existence oracle

The researcher sent the following payload to the PDF generator:

HTML
<img src=http://localhost/.git/HEAD alt=Blind?>

If the server returns "Blind?" in the PDF, that means .git/HEAD is not accessible from localhost. If the PDF comes back empty, that means .git/HEAD exists and can be accessed from the environment where WeasyPrint was running.

Step 2: Enumerate and dirbust internal systems

From this point it is straightforward how bad this can be: the researcher could run enumeration and dirbusting of the internal systems. Even worse, this can be done free of charge, letting the server enumerate itself and send the results back in the generated PDF. The researcher sent the following HTML and observed the generated PDF:

HTML
<img src=”[http://localhost/secure_login](http://localhost/secure_login)” alt=”secure_login”>
<img src=”[http://localhost/secureauth](http://localhost/secureauth)” alt=”secureauth”>
<img src=”[http://localhost/secured](http://localhost/secured)” alt=”secured”>
<img src=”[http://localhost/secureform](http://localhost/secureform)” alt=”secureform”>
<img src=”[http://localhost/secureprocess](http://localhost/secureprocess)” alt=”secureprocess”>
….

If secureauth, secureprocess or secured do not appear in the PDF, those endpoints exist. At the cost of one request, the server has been tricked into running hundreds or thousands of requests and returning information about the internal infrastructure.

Root cause

WeasyPrint does not print the alt text when the img src endpoint is accessible by the server, regardless of whether the response is a valid image. The alt fallback is therefore tied to reachability rather than to whether the resource could actually be rendered, which turns the alt text into a signal about the existence of internal resources. The sanitiser allowed <img> tags, and image-based SSRF is often treated as blind.

Impact

An attacker who can inject <img> tags into HTML rendered to PDF by WeasyPrint can use the presence or absence of the alt text in the generated PDF to determine whether internal endpoints exist, and can enumerate and dirbust internal systems from the privileged environment where the generator runs. The report does not state which internal systems were reached beyond the localhost examples, nor the program, severity or bounty.

Fix

Variants to test

  1. Inject <img src=http://localhost/<path> alt=Blind?> for known and unknown paths. A positive result is an empty PDF for existing paths and "Blind?" for missing ones.
  2. Batch many <img> tags with distinct alt values in one document. A positive result is a PDF in which only the alt values of non-existent endpoints appear.
  3. Point src at internal hosts and ports rather than localhost. A positive result is the same presence/absence signal, showing the generator can reach those services.
  4. Try the same technique against other HTML to PDF generators that support alt fallbacks. A positive result is any generator whose alt handling depends on reachability rather than renderability.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

A website let people put some content into a document that the server then turned into a PDF file. The server used a tool called WeasyPrint to do that conversion. The website tried to protect itself by cleaning the content people submitted, and it only let one kind of tag through: the image tag, <img>. The thinking behind that restriction is that an image tag can only make the server fetch a picture, and the person submitting it never gets to see the picture, so the worst case is a "blind" request. This article shows why that thinking is wrong. Because of a quirk in how WeasyPrint handles the alt text of an image, the person submitting the content can tell whether an internal address exists or not, just by looking at the PDF that comes back. That turns a harmless-looking image tag into a tool for mapping the server's internal network, one address at a time.

Background: what a PDF generator is and why it is risky

Many websites offer a "download as PDF" button. You fill in a form, or write a report, and the site produces a PDF file for you. Behind that button there is usually a program on the server that takes HTML (the language web pages are written in) and converts it into a PDF. WeasyPrint is one such program.

The danger starts when the HTML being converted is not fully controlled by the website. If a user can slip their own HTML into that document, the converter will happily process it. And an HTML document can tell a browser, or a PDF generator, to go and fetch things: images, stylesheets, fonts. So injected HTML can make the server itself send requests to addresses the user cannot reach directly. That is the heart of the vulnerability class called SSRF, server-side request forgery: the attacker uses the server as a proxy to reach places the attacker has no access to.

HTML to PDF generators are, in general, known to be "very challenging" when it comes to security. If a user is able to inject HTML and/or JavaScript into the HTML that will be used for generating a PDF by the server, SSRF and local file read vulnerabilities may occur. The report points to a list of things that could go wrong in the HackTricks page on server-side XSS in dynamic PDF generation.

Allowing users to inject <img> tags is often considered "safer", because even if the PDF generator is initiating server-side HTTP requests from a privileged environment, the actual SSRF is just the blind one. "Blind" here means the attacker fires a request but gets no content back: the server fetches the image, but the attacker only ever sees the finished PDF, not the image itself. That is not entirely true: you can try to include internal images, and if the server is vulnerable you will be able to extract data you should not have access to. The report links to a write-up by mike-n1 on turning SSRF into P4 to P2 for that technique.

The researcher came across this exact problem while working on a private bug bounty program. A bug bounty program is a scheme where a company invites outside researchers to look for security problems in its systems, usually with a reward for valid findings. The PDF generator in use was WeasyPrint. The HTML sanitiser only allowed injection of <img> tags, and the researcher was able to leak some internal images, such as Apache icons, by injecting an image that looks like this:

HTML
<img src=http://localhost/path/to/image>

Line by line, this is what that snippet does:

  • <img starts an image tag. In HTML, a tag is an instruction to the page.
  • src=http://localhost/path/to/image is the address of the picture to display. localhost is a special name that always means "this same machine". So the server is being told to fetch a picture from itself, from an address only the server can reach.
  • > closes the tag.

A sanitiser is a filter that inspects user-submitted HTML and removes anything dangerous, keeping only an approved list of tags. Here the approved list was just <img>. The researcher could not run scripts or embed other kinds of content, but could still make the server fetch internal pictures. Apache icons are small logo images that the Apache web server ships with its default pages.

The setup

The report does not describe the program, the application, accounts, roles or the WeasyPrint version. What matters is stated directly: the application generates PDFs from HTML with WeasyPrint, the user can inject HTML into that document, and the sanitiser restricts the injection to <img> tags. The researcher's payloads showed the generator could reach localhost.

That last point is worth unpacking. A server often runs several services on the same machine: a database, an admin panel, an internal API. These are usually bound to localhost, meaning they accept connections only from the machine itself, not from the internet. That is a common security measure. But the PDF generator runs on that same machine, so when it fetches an image from localhost, it can reach all of those internal services. The attacker, sitting on the internet, cannot. The generator becomes a bridge.

Finding it

The researcher did not stop at leaking internal images and kept exploring different payloads and tags. A payload, in this context, is the piece of injected content sent to the application. There the researcher noticed a strange behaviour in WeasyPrint and its handling of the alt tag.

The alt attribute is the text alternative of an image. In normal HTML, if a picture cannot be loaded, the browser shows the alt text in its place. Think of a restaurant menu where a photo of a dish is missing and the caption underneath still tells you what the dish is. The two images below compare two different PDFs generated by WeasyPrint. On the left is the injected HTML and on the right is the generated PDF.

From the original on medium.com

The expected behaviour is that if an image is broken or inaccessible, the string entered as the value of the alt tag should be printed instead of the image, so nothing should go wrong there. With WeasyPrint, however, if the img src endpoint is accessible by the server (it does not return 404), the alt tag is not printed. Whether the response is a valid image or not does not matter, and that is the core of the bug.

A 404 is the standard HTTP status code for "not found". When your browser asks a web server for a page that does not exist, the server answers with 404. So "accessible" here means simply: the server answered with something other than 404. It could be a picture, it could be an error page, it could be a login form. WeasyPrint does not care. If anything came back, it treats the image as present and hides the alt text. If nothing came back, it shows the alt text.

That difference is the whole trick. The alt text becomes a yes/no signal about whether an address exists on the server's own machine.

Exploitation

Step 1: Turn the alt tag into an existence oracle

An oracle, in security writing, is any behaviour that answers a yes/no question for the attacker. Here the question is "does this internal address exist?" and the answer arrives inside the PDF. The researcher sent the following payload to the PDF generator:

HTML
<img src=http://localhost/.git/HEAD alt=Blind?>
  • <img opens the image tag.
  • src=http://localhost/.git/HEAD tells the server to fetch a file called HEAD from a hidden folder called .git on its own machine. The .git folder is where the version-control tool Git keeps its internal data; it normally sits in a website's project folder and is not meant to be public. HEAD is one of its small bookkeeping files.
  • alt=Blind? sets the fallback text to the literal string Blind?.
  • > closes the tag.

If the server returns "Blind?" in the PDF, that means .git/HEAD is not accessible from localhost. If the PDF comes back empty, that means .git/HEAD exists and can be accessed from the environment where WeasyPrint was running.

If the signal works on a file whose presence you can reason about, you can trust it on addresses you know nothing about.

Step 2: Enumerate and dirbust internal systems

From this point it is straightforward how bad this can be: the researcher could run enumeration and dirbusting of the internal systems. Enumeration means systematically listing what exists. Dirbusting is the specific practice of guessing common folder and file names ("secure", "login", "admin", "backup") and checking which ones are there. Even worse, this can be done free of charge, letting the server enumerate itself and send the results back in the generated PDF. The researcher sent the following HTML and observed the generated PDF:

HTML
<img src=”[http://localhost/secure_login](http://localhost/secure_login)” alt=”secure_login”>
<img src=”[http://localhost/secureauth](http://localhost/secureauth)” alt=”secureauth”>
<img src=”[http://localhost/secured](http://localhost/secured)” alt=”secured”>
<img src=”[http://localhost/secureform](http://localhost/secureform)” alt=”secureform”>
<img src=”[http://localhost/secureprocess](http://localhost/secureprocess)” alt=”secureprocess”>
….

Each line is one guess:

  • <img src=”[http://localhost/secure_login](http://localhost/secure_login)” alt=”secure_login”> asks the server to fetch /secure_login on itself, with secure_login as the fallback text. The square brackets and repeated address are how the link was written in the original document; the address being fetched is http://localhost/secure_login.
  • The next four lines do exactly the same for /secureauth, /secured, /secureform and /secureprocess, each with its own matching alt text.
  • …. indicates the list continues with many more guesses.

If secureauth, secureprocess or secured do not appear in the PDF, those endpoints exist. At the cost of one request, the server has been tricked into running hundreds or thousands of requests and returning information about the internal infrastructure.

An endpoint is simply an address on a server that does something, like a page or a service. The logic of reading the result is the reverse of what you might expect: the names that are missing from the PDF are the interesting ones, because their absence means the server found something at that address and therefore suppressed the alt text. The names that do appear are the dead ends.

Why is this so efficient? Because the attacker sends one document containing many image tags, and the server does all the fetching in one go, then hands back a single PDF that summarises every answer. The attacker never needs to reach the internal network directly, and every request comes from a trusted machine inside it.

Root cause

WeasyPrint does not print the alt text when the img src endpoint is accessible by the server, regardless of whether the response is a valid image. The alt fallback is therefore tied to reachability rather than to whether the resource could actually be rendered, which turns the alt text into a signal about the existence of internal resources. The sanitiser allowed <img> tags, and image-based SSRF is often treated as blind.

In everyday terms: the filter assumed that letting someone order a dish without seeing it was harmless, because they would never taste it. But the kitchen's habit of leaving the plate empty when the dish exists, and writing the name on a napkin when it does not, tells the customer exactly what is in the kitchen.

Impact

An attacker who can inject <img> tags into HTML rendered to PDF by WeasyPrint can use the presence or absence of the alt text in the generated PDF to determine whether internal endpoints exist, and can enumerate and dirbust internal systems from the privileged environment where the generator runs. The report does not state which internal systems were reached beyond the localhost examples, nor the program, severity or bounty.

Fix

Variants to test

These are ways to apply the same idea in other situations, useful if you want to check a similar setup yourself:

  1. Inject <img src=http://localhost/<path> alt=Blind?> for known and unknown paths. A positive result is an empty PDF for existing paths and "Blind?" for missing ones.
  2. Batch many <img> tags with distinct alt values in one document. A positive result is a PDF in which only the alt values of non-existent endpoints appear.
  3. Point src at internal hosts and ports rather than localhost. A positive result is the same presence/absence signal, showing the generator can reach those services. A port is a numbered door on a machine; different services listen on different doors.
  4. Try the same technique against other HTML to PDF generators that support alt fallbacks. A positive result is any generator whose alt handling depends on reachability rather than renderability.

Glossary

  • alt attribute: the text alternative attached to an image, normally shown when the image cannot be displayed.
  • Apache: a widely used web server program; it ships with default pages and small icon images.
  • API: an interface that lets one program ask another for data or actions, usually over the network.
  • Blind SSRF: a server-side request forgery where the attacker can make the server send a request but does not see the response directly.
  • Bug bounty program: a scheme where a company invites outside researchers to report security problems, often for a reward.
  • Dirbusting: guessing common folder and file names on a server to discover which ones exist.
  • Endpoint: an address on a server that provides a page or service.
  • Enumeration: systematically listing or discovering what exists on a system.
  • Git: a version-control tool that keeps project history in a hidden .git folder.
  • HTML: the language web pages are written in, made of tags such as <img>.
  • HTML sanitiser: a filter that removes dangerous parts of user-submitted HTML, keeping only approved tags.
  • HTTP status code: a number a web server returns with every answer, such as 404 for "not found".
  • localhost: a special name meaning "this same machine".
  • Oracle: any behaviour that answers a yes/no question for an attacker.
  • Payload: the piece of content an attacker injects to trigger a behaviour.
  • PDF: a fixed-layout document format, often produced from HTML by a converter.
  • Port: a numbered channel on a machine that a particular service listens on.
  • Privileged environment: a place, such as a server's internal network, with access that ordinary users do not have.
  • SSRF (server-side request forgery): tricking a server into making requests on the attacker's behalf, to places the attacker cannot reach.
  • Tag: an instruction in HTML, such as <img> for an image.
  • WeasyPrint: a program that converts HTML into PDF files.
  • XSS (cross-site scripting): injecting script into a page so it runs in someone else's browser; the report references server-side variants in the context of PDF generation.

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.