Strored Cross Site Scripting
A stored cross-site scripting flaw existed on a Shopify subdomain where a crafted product property value containing a javascript: URL was saved and later executed. An attacker could use a CSRF form to inject the payload into a cart, potentially running script in a victim's browser.
Originally disclosed on HackerOne
- Triaged in 7 hours
- Fixed in 55 days
- Paid in 55 days
- Disclosed after 3 months
Hello , There is a stored cross site scripting at http://hardware.shopify.com . I saw that you recently fixed a bug on this sub-domain , so I'm reporting this.
Video Proof of Concept : https://www.youtube.com/watch?v=cP66Bfb0IoE&feature=youtu.be
Payload used : javascript:alert(document.domain) //http://google.com/uploads/pwned.jpg
Here is a CSRF PoC also :
<html>
<!-- CSRF PoC -->
<body>
<form action="http://hardware.shopify.com/cart/add" method="POST" enctype="multipart/form-data">
<input type="hidden" name="properties[Artwork file]" value="javascript:alert("XSS by Hussein98d") //http://google.com/uploads/powned.jpg" />
<input type="hidden" name="properties[Custom text line 1]" value=" " />
<input type="hidden" name="properties[Custom text line 2]" value=" " />
<input type="hidden" name="properties[Custom text line 3]" value=" " />
<input type="hidden" name="production-time" value="standard" />
<input type="hidden" name="id" value="976094353" />
<input type="submit" value="Submit request" />
</form>
</body>
</html>
Kind Regards Hussein
Context
Shopify runs a storefront platform, and the report concerns http://hardware.shopify.com, a Shopify sub-domain that hosts a shop. The feature involved is the cart's line-item properties: when a customer adds a product to the cart, the shop can collect extra per-item fields, here Artwork file, Custom text line 1, Custom text line 2 and Custom text line 3, alongside the product id and a production-time option. Those property values are stored with the cart and later rendered back to the user, which is exactly the surface where a stored cross-site scripting bug can live.
The researcher notes that a bug on this sub-domain had recently been fixed, which is why the area was worth another look.
Setup
No accounts, roles, tools or versions are described in the report. The only precondition visible from the material is that the attacker needs a way to make a victim submit the cart form, which the researcher demonstrates with a cross-site form POST. The proof of concept is delivered as a video and as an HTML page.
Finding it
The researcher identified a stored cross-site scripting issue at http://hardware.shopify.com. The signal was the cart property fields: values supplied by the client are persisted and later reflected into the page, so a value that the browser interprets as a URL scheme rather than as text becomes script execution. The report does not describe the exact page or element where the stored value is rendered.
Exploitation
Step 1: Choose the payload
The payload placed into the artwork property is:
javascript:alert(document.domain) //http://google.com/uploads/pwned.jpg
The leading javascript: scheme is what turns the stored value into executable script when it is used as a link target. The trailing //http://google.com/uploads/pwned.jpg is a JavaScript comment, so the browser ignores it.
Step 2: Submit the cart form
The researcher provides a CSRF proof of concept that adds the item with the malicious property value:
<html>
<!-- CSRF PoC -->
<body>
<form action="http://hardware.shopify.com/cart/add" method="POST" enctype="multipart/form-data">
<input type="hidden" name="properties[Artwork file]" value="javascript:alert("XSS by Hussein98d") //http://google.com/uploads/powned.jpg" />
<input type="hidden" name="properties[Custom text line 1]" value=" " />
<input type="hidden" name="properties[Custom text line 2]" value=" " />
<input type="hidden" name="properties[Custom text line 3]" value=" " />
<input type="hidden" name="production-time" value="standard" />
<input type="hidden" name="id" value="976094353" />
<input type="submit" value="Submit request" />
</form>
</body>
</html>
The form posts to http://hardware.shopify.com/cart/add with multipart/form-data. The field names use HTML-escaped brackets and spaces, so properties[Artwork file] is the cart property properties[Artwork file], and the three custom text lines are sent as empty values (a carriage return). The production-time field is set to standard and the product is identified by id=976094353. The artwork value is the same payload as above, HTML-encoded: javascript:alert("XSS by Hussein98d") //http://google.com//uploads/powned.jpg, which decodes to javascript:alert("XSS by Hussein98d") //http://google.com/uploads/pwned.jpg.
Because the form is plain HTML with hidden inputs, it can be hosted anywhere and submitted by a victim's browser to the shop, which is what makes the stored value land in the victim's cart without any interaction beyond loading the page and submitting the form.
Step 3: Trigger the stored value
Video Proof of Concept :
The report links a video proof of concept. The report does not describe the page on which the stored value fires or the exact user action that triggers it.
Root cause
The cart property values are stored as supplied and later rendered into a context where the browser treats them as a URL, so a javascript: scheme is honoured instead of being neutralised.
Impact
An attacker can store script in a victim's cart through a cross-site form submission and have it execute in the origin of http://hardware.shopify.com when the stored value is rendered. The payload used in the proof of concept calls alert(document.domain), which demonstrates execution in the shop's domain. The program paid a bounty of 500.00 USD and disclosed the report on 2016-03-13.
Fix
The appropriate fix follows from the root cause: validate that stored property values used as URLs carry an allowed scheme (for example http and https only) and encode the value for the context in which it is rendered, so a javascript: scheme cannot be interpreted as a link target.
Variants to test
- Other cart and checkout property fields: submit the same
javascript:payload in each property and check whether it executes when the cart or order is viewed. - Other URL-bearing fields: image, artwork and file reference fields on product and cart forms, testing whether the scheme is validated on storage or only on render.
- Alternative schemes and encodings:
javascript:with mixed case, HTML-entity encoding and whitespace or control characters before the scheme, looking for a value that still executes. - Cross-site delivery: reuse the same hidden-form technique against other state-changing endpoints that persist user-controlled strings, checking whether the stored value fires for a different user.
A positive result is script execution in the target origin, shown by alert(document.domain) or an equivalent callback, after the value has been stored through a request the victim did not intend to make.
Hunting notes
This kind of bug hides in features that persist free-text or URL-like values and render them back later: cart line-item properties, order notes, custom artwork or file references, and any field whose value is used as a link. During recon, look for forms that post to cart or checkout endpoints with properties[...] style parameter names, and for values that are echoed into href or src attributes. The researcher supplied a ready-made CSRF page that stores the payload in a victim's cart.
What happened, in plain words
A security researcher found a bug on a Shopify shop at http://hardware.shopify.com. The shop lets customers add products to a shopping cart, and for some products it asks for extra details, such as an artwork file and a few lines of custom text. Those details are saved with the cart and shown back to the customer later.
The problem is that one of those saved details, the artwork field, can hold a javascript: value that the browser runs as code. If someone puts a special kind of link address in that field, one that starts with javascript:, the browser does not treat it as a normal web address. It runs it as a small program instead. Because the value is saved on the shop's server and shown to whoever views the cart, the small program runs inside the shop's own website. That is called stored cross-site scripting, or stored XSS.
The researcher also built a small web page that quietly submits the cart form for a visitor, so the malicious value ends up in that visitor's cart without them meaning to do it. That trick is called cross-site request forgery, or CSRF. The proof is a video link plus the HTML page that delivers the payload.
Shopify paid a bounty of 500.00 USD and the report was disclosed on 2016-03-13.
Background you need first
A few ideas come up again and again below, so here they are from zero.
- A sub-domain is a name that sits under a main domain. If the main domain is
shopify.com, thenhardware.shopify.comis a sub-domain of it. It is still part of the same company's website family, but it can run a separate shop. - A storefront is the public-facing part of an online shop: the pages where you browse products, add them to a cart and pay.
- A cart is the temporary list of things you intend to buy. Shops often let you attach extra information to each item, for example a note or a file. These extra fields are called line-item properties. On this shop the properties are
Artwork file,Custom text line 1,Custom text line 2andCustom text line 3. - Stored means the server keeps the value. It is not just shown once and forgotten; it is saved and shown again later, possibly to a different person or on a different page.
- Cross-site scripting (XSS) means getting your own little program to run inside someone else's website, in the browser of a person who visits it. The browser trusts the site, so the program runs with the site's privileges. Think of slipping a fake page into a trusted book: the reader believes it because it is inside the book.
- A URL scheme is the first part of a web address, before the colon.
http:andhttps:mean a normal web page.javascript:is different: it tells the browser that what follows is program code, not an address. That is the heart of this bug. - CSRF (cross-site request forgery) means making a visitor's browser send a request to a site the visitor is logged into, without the visitor intending it. A common way is a hidden form on another website that submits itself. Think of a signed permission slip that someone else fills in and hands to the clerk on your behalf.
multipart/form-datais one of the ways a browser can package form data when sending it to a server. It is the format used when a form may include files, and it can carry ordinary text fields too.- HTML encoding means writing special characters in a coded form so they survive the trip through a web page. For example
[is the code for[, is a space, and:is a colon. The browser decodes these back to the real characters when it reads the page.
The setup
The report does not describe any accounts, tools or software versions. The only thing an attacker needs is a way to make a victim's browser submit the cart form. The researcher shows that with a plain HTML page containing a hidden form, which can be hosted anywhere.
Finding it
The researcher spotted a stored cross-site scripting issue at http://hardware.shopify.com. The clue was the cart property fields. Values typed into those fields are saved by the shop and later placed back into a page. If such a value is used as a link address rather than shown as plain text, and it starts with javascript:, the browser runs it as code.
The researcher also mentions that a bug on this sub-domain had recently been fixed, which is why the area was worth another look.
Exploitation
Step 1: Choose the payload
The value placed into the artwork property is:
javascript:alert(document.domain) //http://google.com/uploads/pwned.jpg
Line by line, in plain words:
javascript:tells the browser that what follows is code, not a web address. This is the part that turns a saved text value into something that runs.alert(document.domain)is the code itself.alertopens a small pop-up box.document.domainis the browser's way of naming the website the page belongs to. So the pop-up shows the shop's domain name, which proves the code ran inside the shop's own site rather than somewhere harmless.//http://google.com/uploads/pwned.jpgstarts with two slashes, which in JavaScript means "ignore the rest of this line". It is a comment.
Step 2: Submit the cart form
The researcher supplies a CSRF proof of concept: a small HTML page that adds the item to the cart with the malicious property value already filled in.
<html>
<!-- CSRF PoC -->
<body>
<form action="http://hardware.shopify.com/cart/add" method="POST" enctype="multipart/form-data">
<input type="hidden" name="properties[Artwork file]" value="javascript:alert("XSS by Hussein98d") //http://google.com/uploads/powned.jpg" />
<input type="hidden" name="properties[Custom text line 1]" value=" " />
<input type="hidden" name="properties[Custom text line 2]" value=" " />
<input type="hidden" name="properties[Custom text line 3]" value=" " />
<input type="hidden" name="production-time" value="standard" />
<input type="hidden" name="id" value="976094353" />
<input type="submit" value="Submit request" />
</form>
</body>
</html>
What each part does:
<html>,<body>and</body>,</html>are the ordinary opening and closing tags of any web page. They just wrap the content.<!-- CSRF PoC -->is an HTML comment. It is not shown to the visitor; it only labels the page for a human reader.<form action="http://hardware.shopify.com/cart/add" method="POST" enctype="multipart/form-data">opens a form.actionis the address the form sends its data to: the shop's cart-add endpoint.method="POST"means the data is sent in the body of the request rather than in the address bar.enctype="multipart/form-data"is the packaging format described above.- The first
<input type="hidden" ...>carries the artwork property.type="hidden"means the visitor never sees it; it is sent silently. Thenameisproperties[Artwork file], which the browser decodes toproperties[Artwork file], the cart property calledArtwork file. Thevalueis the payload, HTML-encoded:javascript:alert("XSS by Hussein98d") //http://google.com/uploads/powned.jpg. Decoded, that isjavascript:alert("XSS by Hussein98d") //http://google.com/uploads/pwned.jpg. It is the same idea as Step 1, with a slightly different pop-up message. - The next three hidden inputs send
properties[Custom text line 1],properties[Custom text line 2]andproperties[Custom text line 3]. Their value is , which is the code for a carriage return, an empty line. They are filled in only so the form matches what the shop expects. <input type="hidden" name="production-time" value="standard" />sends the production-time option set tostandard.<input type="hidden" name="id" value="976094353" />identifies which product is being added, by its numeric id.<input type="submit" value="Submit request" />is the only visible control: a button labelled "Submit request". In a real attack the page could submit itself, but here the button makes the demonstration easy to run.
Why this matters: the page is plain HTML with no scripts of its own. It can sit on any website. When a victim opens it and the form is submitted, their browser sends the request to the shop, and the malicious artwork value is saved in that victim's cart. The victim does nothing beyond loading the page and submitting the form.
Step 3: Trigger the stored value
Video Proof of Concept :
The report links a video proof of concept. The report does not say which page displays the saved value or exactly what the user does to make it run.
Why it works
A link address that begins with javascript: is then run as code instead of being treated as a harmless address. The report does not include the server or template code, so the exact mistake is not described. The report does not include the server or template code, so the exact mistake is most likely a gap in output encoding or scheme checking, not a missing input filter.
What an attacker could do
An attacker can plant code in a victim's cart through a form on another website, and that code runs inside the site http://hardware.shopify.com when the saved value is displayed. The payload used in the proof calls alert(document.domain), which shows the code ran in the shop's domain. The program paid a bounty of 500.00 USD and disclosed the report on 2016-03-13.
The fix
The right fix follows from the cause: check that any saved property value used as a link address carries an allowed scheme, such as http and https only, and encode the value for the place where it is shown, so a javascript: scheme can never be treated as a link.
Other things to test
- Other cart and checkout property fields: put the same
javascript:payload in each property and see whether it runs when the cart or order is viewed. - Other fields that hold addresses: image, artwork and file reference fields on product and cart forms, checking whether the scheme is checked when the value is saved or only when it is shown.
- Other schemes and encodings:
javascript:in mixed case, written with HTML codes, or with spaces or control characters before the scheme, looking for a value that still runs. - Delivering it from another site: reuse the same hidden-form trick against other endpoints that save text a user controls, checking whether the saved value runs for a different person.
A positive result is code running in the target site, shown by alert(document.domain) or a similar signal, after the value was saved through a request the victim did not intend to make.
Notes for hunting
This kind of bug hides in features that save free text or address-like values and show them again later: cart line-item properties, order notes, custom artwork or file references, and any field whose value is used as a link. While looking around, watch for forms that post to cart or checkout endpoints with parameter names in the properties[...] style, and for values that end up inside href or src attributes. The researcher supplied a ready-made CSRF page that saves the payload in a victim's cart.
Glossary
- Sub-domain: a name under a main domain, such as
hardware.shopify.comundershopify.com. - Storefront: the public part of an online shop where people browse and buy.
- Cart: the temporary list of items a shopper intends to buy.
- Line-item property: an extra field attached to one item in a cart, such as a note or an artwork file.
- Stored: saved on the server so it can be shown again later.
- Cross-site scripting (XSS): getting your own code to run inside someone else's website in a visitor's browser.
- Stored XSS: XSS where the malicious value is saved on the server and runs when it is shown later.
- Payload: the value an attacker sends to cause the unwanted behaviour.
- URL scheme: the first part of an address before the colon, such as
http:,https:orjavascript:. javascript:scheme: a URL scheme that tells the browser the rest is code to run, not an address to visit.document.domain: the browser's name for the website the current page belongs to.alert(): a browser function that opens a small pop-up box with a message.- Comment (in code): text the browser ignores; in JavaScript, everything after
//on a line. - CSRF (cross-site request forgery): making a visitor's browser send a request to a site without the visitor intending it.
- CSRF PoC: a small page built to demonstrate a CSRF attack.
multipart/form-data: a way of packaging form data for sending to a server, often used when files may be included.- HTML encoding: writing special characters as codes such as
[so they survive the trip through a page. - Hidden input: a form field the visitor cannot see but the browser still sends.
- Endpoint: the specific address on a server that a request is sent to, such as
/cart/add. - POST: an HTTP method that sends data in the body of the request rather than in the address.
href/srcattribute: HTML attributes that hold an address, for a link or for an embedded resource.- Output encoding: converting a value so it is shown as harmless text in the place it appears, instead of being treated as code or an address.
- Scheme validation: checking that an address uses an allowed scheme, such as only
httpandhttps. - Origin: the combination of scheme, host and port that a browser uses to decide which site a page belongs to.
- Bounty: a payment a company makes to a researcher who reports a valid security bug.