Skip to content
SSRF Write-up Advanced

Unleashing the power of CSS injection: The access key to an internal API

A CSS injection flaw in an accounting application's PDF generator allowed an attacker to use the url() directive to read local files and access internal services, including an internal API exposing other customers' data.

Sander Wind Follow

Published on sanderwind.medium.com

In this write-up, we will be explaining a vulnerability that was discovered in an online accounting application. The vulnerability was a CSS injection flaw that could be exploited in the application’s PDF generator.

Sander Wind, on sanderwind.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. 6 min read.

Context

This write-up covers a CSS injection vulnerability found in an online accounting application. The feature at the centre of it is the application's invoice generation: users create invoices and download them as PDFs. The application also lets users configure the global styling of those invoice documents, and it offers a preview of the styling being configured. The goal of the research was to find an injection point inside the PDF generation feature that would lead to code execution.

Photo by FIN on Unsplash From the original on sanderwind.medium.com

Setup

The report does not describe accounts, roles or specific tooling beyond the following: the team tested payloads in the invoice input fields and in the global styling configuration, used a local copy of the PrinceXML documentation to test its custom HTML tags and CSS directives, used a script to automate PDF generation, used wordlists against the generator, and used securitytrails.com to enumerate subdomains. The PDF generator was identified as Prince 13.2 from the metadata of generated PDFs. The report does not state which version of the accounting application was tested.

Finding it

The first step was to identify entry points for injecting code. The team focused on the invoice generation feature, hoping to find injection points within PDF generation that would allow malicious payloads to lead to code execution.

They injected payloads into the different user input fields for invoices that get included in the generated PDF. None of those fields led to execution of the payloads. That pushed them to the global styling configuration for invoice documents. Most configuration options had validation and sanitisation in place, except one: the colour of the text used in the documents.

HTML
<style>  body {    color: #7c878e;     font-family: Arial, Helvetica, sans-serif;   }  .identity-text {    color: #f3f3f3;}Hi there! I am some new css but I can not escape the style tag to become xss : (  ; </style>

Because the application allowed previewing the styling options, the team quickly learned that the injection point was less exciting than hoped. The characters <>'" were escaped, making it impossible to close the <style> tag and inject HTML such as <script> or <iframe>. At first this looked like a dead end, but the CSS injection was rendered by the PDF generator. Fiddling with the CSS revealed that SSRF was possible by using the url() directive without encapsulating the URL in quotes.

Text
[[redacted]] Received DNS interaction (AAAA) from xx.xxx.xx.xx at 2021-11-01 17:32:35[[redacted]] Received DNS interaction (A) from xx.xxx.xx.xxx at 2021-11-01 17:32:35[[redacted]] Received HTTP interaction from xx.xxx.xx.xxx at 2021-11-01 17:32:35

Again the excitement was short-lived: no interesting data could be extracted. Images did not render because they were not valid images, and timing attacks by polling for alive internal IPs and hosts were not possible because PDF generation time was not consistent enough.

At that point the team started looking into the PDF generation software. Viewing the metadata of generated PDFs showed that Prince 13.2 was being used.

Exploitation

Step 1: Read the PrinceXML documentation

PrinceXML's documentation is extensive, so the team ran a local copy to test possibilities. They looked at custom HTML tags and custom CSS directives, which looked promising to abuse. Nothing seemed to work, because they were limited by the escaped characters in the CSS injection point.

Step 2: Try the prince-pdf-script property

When testing the prince-pdf-script property, they thought it did not work at first. The documentation says:

This property can be used to include JavaScript code that will be executed when the PDF file is opened. A common use case is to activate the "Print" dialog automatically. The script can be located in an external JavaScript file, referenced with the url() function.

Text
@prince-pdf {  prince-pdf-script: "this.print();"}

Nothing happened: no print box popped up, and no custom code was executed during generation of the PDF. Then the second sentence of the documentation stood out: the script can be located in an external JavaScript file, referenced with the url() function.

Step 3: Include a local file with url()

The team tried to include a local file with the url() function.

Text
@prince-pdf {   prince-pdf-script: url(/etc/hostname);}

Looking at the source of the generated PDF, the content of the given file was included as JavaScript, encoded in HEX UTF16.

Text
4 0 obj<</S /JavaScript/JS <[redacted]>>>endobj

Decoding the UTF16 string showed the hostname of the generator service: 03f827eaea5c. Retrieving other files such as /etc/passwd worked perfectly fine. PrinceXML apparently does not validate the content type of the included file and includes the content as is.

Step 4: Automate and enumerate

Generating one PDF document took six separate requests, so the team wrote a script to automate the process. This made it possible to run wordlists against the PDF generator and extract the included "JavaScript" in one run. A list of common UNIX files did not expose much interesting material, so they moved on to requesting internal hosts. Using securitytrails.com they obtained an accurate list of subdomains to enumerate.

Step 5: Reach internal hosts

After enumerating a few domains, they found they had access to:

  • A NuGet gallery, exposing other applications available for download.
  • An Elastic Search instance, which allowed querying all public and internal network requests.
  • The internal API, making it possible to query all available data of other customers.

Root cause

The injection point was the text colour in the global styling configuration, which lacked the validation and sanitisation applied to the other options. The escaping of <>'" prevented closing the <style> tag and injecting HTML, but it did not prevent CSS-level abuse. PrinceXML's prince-pdf-script property accepts a url() reference to an external JavaScript file, and the generator includes the referenced file's content as JavaScript in the PDF without validating its content type. The prince-pdf-script property's url() reference turned a limited CSS injection into arbitrary local file read, and an unquoted url() directive gave SSRF against internal hosts.

Impact

Under the conditions described, an attacker who can configure the invoice text colour could read local files from the PDF generator host and make the generator request internal hosts. In this engagement that access reached a NuGet gallery, an Elastic Search instance exposing public and internal network requests, and the internal API, which allowed querying all available data of other customers. The company assessed this as a critical vulnerability. The report notes that extracting data through images was not possible because they did not render as valid images, and that timing attacks against internal IPs and hosts were not possible because PDF generation time was not consistent enough.

Fix

PrinceXML changed the functionality of the prince-pdf-script property in version 15.

Variants to test

  1. Other style fields rendered by a PDF generator. Inject an unquoted url() into any CSS value that reaches the generator and watch for DNS or HTTP callbacks. A positive result is an interaction from the generator's infrastructure.
  2. Generator-specific script directives. Test properties such as prince-pdf-script with a url() pointing at a local file, then inspect the PDF source for the file content. A positive result is the file's content appearing in the PDF, encoded or otherwise.
  3. Local file reads through other url() sinks. Point url() at files such as /etc/hostname or /etc/passwd in any property the generator resolves. A positive result is the file content reflected into the output.
  4. Internal host enumeration. Automate PDF generation and run subdomain lists against the generator, extracting included content each run. A positive result is a reachable internal service whose responses appear in the generated document.
  5. Character-set escaping gaps. Where <>'" are escaped, check whether unquoted url(), @ rules or other CSS syntax still works. A positive result is any directive that the generator resolves despite the escaping.

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. 17 min read.

What happened, in plain words

An online accounting application lets businesses keep track of money: invoices, customers, payments. One of its features turns an invoice into a PDF file that you can download and send to a client. To make those PDFs look consistent, the application also lets you set the global styling of invoice documents, for example the colour of the text, and it shows you a preview of what that styling will look like.

A small team of security researchers looked at this feature and found a way to slip their own instructions into the text colour setting. Those instructions were not ordinary text but CSS, the language that tells a document how to look. The application tried to block the obvious attacks, but it missed one detail, and that detail let the researchers make the PDF generator read files from its own machine and contact other computers inside the company's network. Among those internal computers was an internal API that held the data of other customers.

The company rated this a critical vulnerability. The PDF software involved, PrinceXML, later changed the behaviour that made the attack possible.

Photo by FIN on Unsplash From the original on sanderwind.medium.com

The pieces you need to know

Before following the steps, here are the ideas the story relies on, explained from scratch.

CSS. CSS (Cascading Style Sheets) is the language that describes how a web page or a document should look: which colour the text is, which font, how wide the margins are. A rule looks like body { color: #7c878e; }, which means "for the body of the document, use this grey colour". CSS is normally written by the site's developers, not by visitors. If a visitor can add their own CSS, that is called CSS injection.

Injection. Injection means that a program takes something a user typed and treats it as instructions instead of as plain data. Think of a form where you write your name, and the system accidentally reads your name as a command. Most security bugs of this family come from the same mistake: data and instructions get mixed up.

HTML tags. HTML is the language that structures a document: headings, paragraphs, images. It uses tags such as <style> (here comes styling), <script> (here comes a program) and <iframe> (here comes another page embedded in this one). If an attacker can close a tag early, they can start a new one of their own, which is how many attacks begin.

Escaping. Escaping means replacing dangerous characters with harmless stand-ins before storing or displaying them. If the characters <> are escaped, a <script> tag written by a user no longer works as a tag; it is shown as text. It is like a receptionist who rewrites any mention of "the safe combination" in a letter so that the reader sees a placeholder instead.

PDF. PDF is a file format for documents whose layout stays fixed wherever you open it. A PDF generator is the software that builds such a file from data and styling. In this application, the generator is a separate program that the accounting app calls whenever a user downloads an invoice.

SSRF. SSRF stands for Server-Side Request Forgery. It means tricking a server into making a request on your behalf, usually to a destination you cannot reach yourself. The server sits inside the company network, so it can talk to internal machines that are invisible from the internet. It is like persuading a staff member who has keys to every door to fetch something from a locked room for you.

DNS and HTTP callbacks. When a computer looks up a name such as example.com, it asks a DNS server, and that lookup is visible to whoever runs the DNS server. When it fetches a web page, it speaks HTTP, and that request is visible to whoever runs the web server. Researchers use their own servers to watch for these callbacks: if a machine they do not control suddenly contacts them, they know it made a request. It is a way of confirming "something on the inside reached out".

Internal hosts and subdomains. Companies often run services that are not reachable from the public internet, only from inside their own network. Those are internal hosts. A subdomain is a name like shop.example.com under the main domain example.com. Listing subdomains is a common way to discover which services a company runs.

API. An API (Application Programming Interface) is a way for one program to ask another for data or actions, without a human clicking around a website. Think of it as the service counter at a shop: you state what you want in a fixed format and get an answer back. An internal API is one that is only meant to be used from inside the company network.

Metadata. Metadata is information about a file rather than its contents: who made it, when, with which program. For a PDF, the metadata often names the software and version that produced it.

Wordlist. A wordlist is simply a long list of candidate names, such as common file paths or common subdomain names, that a script tries one after another. It is brute force with a dictionary instead of guesses.

Timing attack. A timing attack infers something from how long an operation takes. If asking about a machine that exists takes noticeably longer than asking about one that does not, you can map a network by timing alone. It only works if the timing is consistent enough to tell the two cases apart.

Step 1: Looking for a way in

The team's goal was to find a place inside the PDF generation feature where their own input would be treated as instructions, ideally leading to code execution, meaning their code running on the server. They started with the invoice input fields: the boxes where a user types the customer name, the invoice lines and so on, all of which end up in the generated PDF.

They put their payloads, meaning the snippets of code they wanted to try, into those fields. None of the fields executed anything. That is a normal result: most fields are handled carefully.

So they moved to the global styling configuration for invoice documents. Most of the options there had validation and sanitisation in place, two layers of defence: validation rejects input that does not fit the expected shape, sanitisation cleans up input that is accepted. One option had neither: the colour of the text used in the documents.

Here is what the styling looked like with their addition in place:

HTML
<style>  body {    color: #7c878e;     font-family: Arial, Helvetica, sans-serif;   }  .identity-text {    color: #f3f3f3;}Hi there! I am some new css but I can not escape the style tag to become xss : (  ; </style>

Line by line:

  • <style> opens a block in which the document expects CSS rules.
  • body { color: #7c878e; font-family: Arial, Helvetica, sans-serif; } is a rule for the whole document body: grey text in Arial or a fallback font.
  • .identity-text { color: #f3f3f3;} is a rule for elements marked with the class identity-text, giving them a near-white colour.
  • Hi there! I am some new css but I can not escape the style tag to become xss : ( is the researchers' own text, placed where the colour value should go. It is a message to themselves: they wanted to break out of the style block and turn the injection into XSS (cross-site scripting, running their own JavaScript in a page), and they could not.
  • ; ends the declaration, and </style> closes the block.

Because the application offered a preview of the styling, the team could see the result immediately. The characters <>'" were escaped, so they could not close the <style> tag and open their own, for example a <script> or an <iframe>. At first this looked like a dead end.

But something caught their attention: the CSS injection was actually rendered by the PDF generator. The generator was reading their CSS and applying it. That meant the generator, not just the browser preview, was processing attacker-controlled styling. Fiddling with the CSS, they found that SSRF was possible by using the url() directive without putting the URL in quotes. In CSS, url(...) means "fetch this resource", normally an image or a font. If the generator fetches whatever address you put there, you can make it fetch an address of your choosing.

They confirmed this with a callback service, which logs any machine that contacts it:

Text
[[redacted]] Received DNS interaction (AAAA) from xx.xxx.xx.xx at 2021-11-01 17:32:35[[redacted]] Received DNS interaction (A) from xx.xxx.xx.xxx at 2021-11-01 17:32:35[[redacted]] Received HTTP interaction from xx.xxx.xx.xxx at 2021-11-01 17:32:35

Line by line:

  • The first line records a DNS lookup of type AAAA, which asks for the IPv6 address of a name.
  • The second line records a DNS lookup of type A, which asks for the IPv4 address of the same name.
  • The third line records an HTTP request, meaning the machine went further and actually tried to fetch a web resource.
  • The long string in brackets is the identifier of the callback, so the researchers could tell which of their tests produced which hit.

In plain terms: a machine they did not control looked up their name and then contacted their server. The generator had made a request on their behalf. That is SSRF.

Again the excitement was short-lived. They could not extract any interesting data. Images did not render because what came back was not a valid image, so the generator had nothing useful to show them. And timing attacks, polling for internal IP addresses and hosts and measuring how long each answer took, were not possible because the time to generate a PDF was not consistent enough to tell a hit from a miss.

At that point they stopped guessing about the application and started looking at the PDF generation software itself. They opened the metadata of a generated PDF and found that Prince 13.2 was being used. Knowing the exact product and version is what made the next steps possible: they could read that product's documentation and look for features the application's developers had never intended to expose.

Step 2: Reading the manual

PrinceXML's documentation is very extensive, so the team ran a local copy of it to test the possibilities. They looked at custom HTML tags and custom CSS directives, features specific to PrinceXML that looked promising to abuse. Nothing seemed to work, because they were still limited by the escaped characters in the CSS injection point: they could not open new tags.

Step 3: The property that seemed useless

They tested a PrinceXML-specific property called prince-pdf-script. The documentation says:

This property can be used to include JavaScript code that will be executed when the PDF file is opened. A common use case is to activate the "Print" dialog automatically. The script can be located in an external JavaScript file, referenced with the url() function.

In other words: you can attach a small program to a PDF, and that program runs when someone opens the file. A common use is to pop up the print dialog automatically. And the program does not have to be written inline; it can live in a separate file that you point to with url().

Their first attempt put the program inline:

Text
@prince-pdf {  prince-pdf-script: "this.print();"}

Line by line:

  • @prince-pdf { opens a special block of settings that only PrinceXML understands, not a normal browser.
  • prince-pdf-script: "this.print();" says: attach the JavaScript this.print(); to the PDF. That snippet asks the viewer to open its print dialog.
  • } closes the block.

Nothing happened. No print box popped up, and no custom code ran while the PDF was being generated. It looked like another dead end.

Then the second sentence of the documentation stood out: the script can be located in an external JavaScript file, referenced with the url() function. If the generator fetches whatever url() points at and treats the result as JavaScript, then pointing it at a file on the generator's own disk would make the generator read that file for them.

Step 4: Reading files from the generator

They tried exactly that:

Text
@prince-pdf {   prince-pdf-script: url(/etc/hostname);}

Line by line:

  • @prince-pdf { opens the PrinceXML settings block again.
  • prince-pdf-script: url(/etc/hostname); says: the script for this PDF is not inline, it is the file at the path /etc/hostname. On Linux and similar systems, /etc/hostname is a small text file containing the machine's own name.
  • } closes the block.

They then looked at the source of the generated PDF, and the content of the file was there, included as JavaScript, encoded in HEX UTF16. UTF16 is a way of storing text where each character takes two bytes; HEX here means those bytes are written as hexadecimal digits.

Text
4 0 obj<</S /JavaScript/JS <[redacted]>>>endobj

Line by line:

  • 4 0 obj starts object number 4 inside the PDF. A PDF is built from numbered objects, and this one holds the script.
  • <</S /JavaScript/JS <...>>> is a dictionary, a set of key and value pairs. /S /JavaScript says the object is of type JavaScript. /JS is the key whose value is the script itself.
  • <[redacted]> is the script, written as hexadecimal. FEFF at the start is the byte order mark that signals UTF16. The pairs that follow are the characters: 0030 is 0, 0033 is 3, 0066 is f, and so on. 000A at the end is a newline.
  • >> closes the dictionary and endobj closes the object.

Decoding the UTF16 string showed the hostname of the generator service: 03f827eaea5c. That is the name the machine calls itself, and it is not something a user of the accounting application is supposed to see. Retrieving other files, such as /etc/passwd, worked perfectly fine. On Linux, /etc/passwd is a file listing the user accounts on the machine. PrinceXML apparently does not check what kind of file it is including and includes the content as is, whether it is a script or a system file.

At this point the CSS injection had become an arbitrary local file read: the ability to ask the generator to hand back the contents of any file it can access.

Step 5: Automating the boring part

Generating one PDF document took six separate requests, so doing this by hand for every candidate file or host would have been painfully slow. The team wrote a script to automate the process. That made it possible to run wordlists against the PDF generator and extract the included "JavaScript" in one run: feed in a list of paths, generate a PDF for each, pull the file content out of the result.

A list of common UNIX files did not expose much interesting material. System files are useful for confirming the bug, but they rarely contain customer data. So they moved on to requesting internal hosts. Using securitytrails.com, a service that collects information about domains, they obtained an accurate list of subdomains to enumerate. Each subdomain name became another entry to try, with the generator making the request from inside the network.

Step 6: What was on the inside

After enumerating a few domains, they found they had access to:

  • A NuGet gallery, exposing other applications available for download. NuGet is the package manager for the .NET world; a gallery is the server that hosts packages.
  • An Elastic Search instance, which allowed them to query all public and internal network requests. Elasticsearch is a search and analytics engine that stores and indexes large amounts of data.
  • The internal API, making it possible to query all available data of other customers.

That last item is the serious one. The internal API made it possible to query all available data of other customers.

Being able to access the hosts listed above, the company decided this was enough to assess the severity as a critical vulnerability.

Why it worked

The injection point was the text colour in the global styling configuration, which lacked the validation and sanitisation applied to the other options. The escaping of <>'" stopped the researchers from closing the <style> tag and injecting HTML, but it did nothing about abuse at the CSS level: url() is valid CSS, and no tag needs to be closed to use it.

PrinceXML's prince-pdf-script property accepts a url() reference to an external JavaScript file, and the generator includes the referenced file's content as JavaScript in the PDF without validating its content type. The prince-pdf-script property's url() reference turned a limited CSS injection into arbitrary local file read, and an unquoted url() directive gave SSRF against internal hosts. The report does not describe the application-side code, so the exact reason the colour field escaped validation is not stated.

What the impact was

Under the conditions described, an attacker who can configure the invoice text colour could read local files from the PDF generator host and make the generator request internal hosts. In this engagement that access reached a NuGet gallery, an Elasticsearch instance exposing public and internal network requests, and the internal API, which allowed querying all available data of other customers. The company assessed this as a critical vulnerability.

The report notes that extracting data through images was not possible because they did not render as valid images, and that timing attacks against internal IP addresses and hosts were not possible because PDF generation time was not consistent enough.

How it was fixed

PrinceXML changed the functionality of the prince-pdf-script property in version 15. The report does not describe any changes made by the accounting application itself, such as validating the colour field or restricting the generator's network and file access.

Things worth trying elsewhere

  1. Other style fields rendered by a PDF generator. Inject an unquoted url() into any CSS value that reaches the generator and watch for DNS or HTTP callbacks. A positive result is an interaction from the generator's infrastructure.
  2. Generator-specific script directives. Test properties such as prince-pdf-script with a url() pointing at a local file, then inspect the PDF source for the file content. A positive result is the file's content appearing in the PDF, encoded or otherwise.
  3. Local file reads through other url() sinks. Point url() at files such as /etc/hostname or /etc/passwd in any property the generator resolves. A positive result is the file content reflected into the output.
  4. Internal host enumeration. Automate PDF generation and run subdomain lists against the generator, extracting included content each run. A positive result is a reachable internal service whose responses appear in the generated document.
  5. Character-set escaping gaps. Where <>'" are escaped, check whether unquoted url(), @ rules or other CSS syntax still works. A positive result is any directive that the generator resolves despite the escaping.

Glossary

  • API: a fixed way for one program to ask another for data or actions, without a human using a website.
  • Callback: a request that a target machine makes to a server the researcher controls, used as proof that the target made a request.
  • Code execution: the situation where an attacker's own instructions run as a program on someone else's machine.
  • CSS: the language that describes how a document or page looks: colours, fonts, spacing.
  • CSS injection: getting your own CSS into a document that was not meant to accept it.
  • DNS: the system that translates names such as example.com into addresses, and whose lookups can be observed by the server answering them.
  • Elasticsearch: a search and analytics engine that stores and indexes large amounts of data.
  • Escaping: replacing dangerous characters with harmless stand-ins so they are treated as text, not as instructions.
  • HEX UTF16: a way of writing text where each character takes two bytes, and those bytes are written as hexadecimal digits.
  • HTML: the language that structures a document with tags such as <style>, <script> and <iframe>.
  • HTTP: the protocol browsers and servers use to request and deliver web resources.
  • Injection: a bug where user input is treated as instructions instead of data.
  • Internal host: a machine reachable only from inside a company's network, not from the public internet.
  • Internal API: an API meant to be used only from inside the company network.
  • JavaScript: the programming language that runs programs in browsers and in many PDF viewers.
  • Metadata: information about a file rather than its contents, such as the program and version that produced it.
  • NuGet gallery: the server that hosts .NET packages, the building blocks of .NET applications.
  • Payload: the snippet of code or input an attacker uses to test or exploit a bug.
  • PDF: a file format for documents whose layout stays fixed wherever it is opened.
  • PDF generator: the software that builds a PDF from data and styling.
  • PrinceXML: the PDF generation software used here, identified as version 13.2.
  • Sanitisation: cleaning up input that is accepted, removing anything dangerous from it.
  • SSRF: Server-Side Request Forgery, tricking a server into making a request to a destination of your choosing.
  • Subdomain: a name under a main domain, such as shop.example.com under example.com.
  • Timing attack: inferring information from how long an operation takes.
  • URL: the address of a resource, such as a web page or a file.
  • url(): the CSS function that means "fetch this resource", normally an image or a font.
  • UTF16: a way of storing text where each character takes two bytes.
  • Validation: rejecting input that does not fit the expected shape.
  • Wordlist: a long list of candidate names tried one after another by a script.
  • XSS: cross-site scripting, running your own JavaScript in someone else's page.

More by Sander Wind

View all

1 more disclosed report, best first.

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.