Stored XSS in https://checkout.shopify.com/
A gift card design upload field accepted a URL instead of a file, and the checkout page later rendered that URL as a clickable link without validating its scheme. An attacker could store a javascript: URL that executes script in the checkout origin when a victim clicks the artwork link.
- Triaged in 19 hours
- Fixed in 44 hours
- Paid in 2 days
- Disclosed after 2 days
STEPS TO REPRODUCE
- Go to http://hardware.shopify.com/products/custom-gift-card?variant=976094353 and Design your own gift card.
- Change file type to url on the upload field.
- Add the payload
javascript:alert(document.domain);//https://cdn.shopify.com/s/files/1/0224/0965/uploads/1fc1042c960abdb2f35c0950900a7b2c.svg - Then add the item to the cart and go to checkout.
- On the checkout page click the Artwork File and the XSS will trigger.
What the report shows
This is a stored cross-site scripting report against Shopify's checkout flow, disclosed on HackerOne on 15 March 2016 and credited to the researcher niyaax. The platform records the weakness as generic cross-site scripting and a bounty of 500.00 USD. No severity rating or CVSS score is given.
The feature involved is the custom gift card designer on the Shopify hardware store. A shopper designs a gift card, uploads artwork, adds the item to the cart and proceeds to checkout. The checkout page then displays the uploaded artwork file as a clickable link.
The researcher's reproduction steps are short and direct:
- Open the custom gift card product page at
http://hardware.shopify.com/products/custom-gift-card?variant=976094353and design a gift card. - Change the file type of the upload field to
url. - Supply the following value as the artwork:
javascript:alert(document.domain);//https://cdn.shopify.com/s/files/1/0224/0965/uploads/[redacted].svg
- Add the item to the cart and go to checkout.
- On the checkout page, click the Artwork File link, and the script runs.
The payload is a javascript: URI. The // turns the remainder of the string, a legitimate CDN URL ending in .svg, into a comment, so the value still looks like a plausible file reference while the browser executes the leading JavaScript when the link is followed. The report does not include the HTTP requests, the server response, or any detail about how the upload field's type was changed beyond the single instruction.
The report text does not describe a fix, and it does not state whether the payload fired in the context of the checkout origin or a related one.
Root cause
The reproduction steps show a user-supplied URL being accepted and later rendered as a link. The artwork value is accepted as a URL, stored, and later rendered as the destination of a link on the checkout page without validating that its scheme is safe. A javascript: value is accepted as the artwork and later activated as a link on the checkout page. When a victim clicks the link, the browser treats the value as script to execute in the page's origin rather than as a navigation target.
The report does not identify the specific validation routine or the storage layer.
Impact
The report demonstrates script execution in the victim's browser after a click on the Artwork File link on the checkout page. The payload used calls alert(document.domain), which shows the origin the script runs in. The value is carried with the cart item to the checkout page, which is why the report treats it as stored.
What an attacker could actually achieve beyond the alert is not shown in the report. A checkout page is a sensitive context, so script running there could in principle read page content or act on the user's behalf, but the report makes no claim about session theft, payment data or account takeover, and none should be assumed from it.
How this kind of bug works
Stored cross-site scripting happens when input that one user supplies is persisted and later rendered into another user's page without correct output encoding. The browser cannot tell developer-written markup from injected markup, so any script that reaches the DOM as HTML or as an executable URL runs with the privileges of the page's origin.
The javascript: scheme is a special case. It is not HTML injection at all: the attacker only needs to control a URL that ends up in an href, src or similar attribute. When the link is activated, the browser evaluates the remainder of the URI as script in the context of the current document. This bypasses HTML-escaping defences, because escaping < and > does nothing to a javascript: string. The defence has to be scheme allow-listing, not character escaping.
Defences that stop this class are contextual output encoding for HTML, attribute and JavaScript contexts; a strict allow-list of URL schemes (https, and http where needed) applied both on input and again at render time; and a Content Security Policy that blocks inline and javascript: execution. Server-side validation alone is fragile if the same value is rendered in several places, so the render step should re-check the scheme.
How to test for it
Look for features where a user-supplied URL is stored and later shown as a link: profile websites, uploaded artwork or attachments referenced by URL, avatar URLs, redirect targets, and any field where the client lets you switch between uploading a file and pasting a link.
- Identify every place a URL you control is echoed back, especially in a different user's view or a later step of a flow such as a cart or checkout.
- Submit a benign URL first and confirm it is stored and rendered as a link, and note the exact attribute it lands in.
- Replace the scheme with
javascript:and a harmless probe such as an alert of the document domain, keeping the rest of the value looking legitimate. - Trigger the link as a second user or in a fresh session to confirm the value is stored rather than reflected.
- Record the origin shown by the probe, since that determines the real impact.
A positive result is script executing when the link is activated, with the probe confirming the origin. Common false positives are values that are escaped into text and never become a live href, links that are rewritten to a safe scheme server-side, and cases where the payload only fires for the submitter because the value is not actually persisted. Also check whether a Content Security Policy blocks execution, which would reduce or remove impact.
How it is fixed
Re-apply the same check when rendering the link, so older stored values are neutralised. Encode the value correctly for the attribute context, and add a Content Security Policy that disallows javascript: navigation and inline script. Where a URL is only ever meant to point at an uploaded asset, consider storing the asset and serving it from a controlled host instead of accepting an arbitrary URL.
Hunting notes
This class tends to hide in multi-step commerce and account flows where a value is entered early and displayed late: carts, checkouts, order confirmations, invoices, and admin views of customer-supplied data. Fields that accept either a file or a URL are strong candidates, because the URL branch often gets weaker validation than the upload branch.
Useful recon signals are client-side controls that let you change an input's type, upload widgets that expose a URL option, and any parameter whose value reappears inside an href or src. Watching how a value is transformed between submission and display shows whether validation happens at all.
Keep the proof minimal and reproducible, and avoid claims about data theft you have not demonstrated.
What happened, in plain words
This report describes a stored cross-site scripting (XSS) bug in Shopify's checkout. It was disclosed on HackerOne on 15 March 2016 and credited to the researcher niyaax. The platform records the weakness as generic cross-site scripting and a bounty of 500.00 USD. No severity rating or CVSS score is given.
The feature involved is the custom gift card designer on the Shopify hardware store. A shopper designs a gift card, uploads artwork, adds the item to the cart and goes to checkout. The checkout page then shows the uploaded artwork file as a clickable link.
To understand the bug, two ideas help. First, a URL is an address the browser can follow, like a street address for a web page. Most start with http:// or https://, but the part before the colon is called the scheme, and other schemes exist. Second, cross-site scripting means getting a browser to run code that the site's owners did not write. When the code is saved on the server and shown to later visitors, it is called stored XSS, because the bad value is stored rather than just reflected back once.
The researcher's reproduction steps are short and direct:
- Open the custom gift card product page at
http://hardware.shopify.com/products/custom-gift-card?variant=976094353and design a gift card. - Change the file type of the upload field to
url. - Supply the following value as the artwork:
javascript:alert(document.domain);//https://cdn.shopify.com/s/files/1/0224/0965/uploads/[redacted].svg
- Add the item to the cart and go to checkout.
- On the checkout page, click the Artwork File link, and the script runs.
Step 2 matters because the upload field normally expects a file. Switching its type to url is the step the researcher took before supplying a web address as the artwork. Step 3 is the payload itself. It is a javascript: URI, a scheme that tells the browser to run the text after the colon as code rather than to fetch a page. The // turns the rest of the string, a legitimate CDN URL ending in .svg, into a comment, so the value still looks like a plausible file reference while the browser executes the leading JavaScript when the link is followed. alert(document.domain) is a harmless probe that pops up a box showing which site the code is running on. Steps 4 and 5 show the value carried with the cart item and activated on the checkout page.
The report does not include the HTTP requests, the server response, or any detail about how the upload field's type was changed beyond the single instruction. It does not describe a fix, and it does not state whether the payload fired in the context of the checkout origin or a related one.
In general, how this kind of bug works
Stored cross-site scripting happens when input that one user supplies is saved and later shown in another user's page without correct output encoding. Output encoding means converting special characters so the browser treats them as text, not as instructions. The browser cannot tell developer-written markup from injected markup, so any script that reaches the page as HTML or as an executable URL runs with the privileges of the page's origin. The origin is the combination of scheme, host and port that the browser uses to decide which site a page belongs to.
The javascript: scheme is a special case. It is not HTML injection at all: the attacker only needs to control a URL that ends up in a link's href attribute or a similar place. When the link is activated, the browser evaluates the rest of the URI as script in the context of the current document. This bypasses HTML-escaping defences, because escaping < and > does nothing to a javascript: string. The defence has to be scheme allow-listing, not character escaping.
Defences that stop this class are contextual output encoding for HTML, attribute and JavaScript contexts; a strict allow-list of URL schemes (https, and http where needed) applied both on input and again at render time; and a Content Security Policy (a set of rules the server sends telling the browser which scripts may run) that blocks inline and javascript: execution. Server-side validation alone is fragile if the same value is shown in several places, so the render step should re-check the scheme.
In general, how to test for it
Look for features where a user-supplied URL is saved and later shown as a link: profile websites, uploaded artwork or attachments referenced by URL, avatar URLs, redirect targets, and any field where the client lets you switch between uploading a file and pasting a link.
- Identify every place a URL you control is echoed back, especially in a different user's view or a later step of a flow such as a cart or checkout.
- Submit a benign URL first and confirm it is saved and shown as a link, and note the exact attribute it lands in.
- Replace the scheme with
javascript:and a harmless probe such as an alert of the document domain, keeping the rest of the value looking legitimate. - Trigger the link as a second user or in a fresh session to confirm the value is stored rather than reflected.
- Record the origin shown by the probe, since that determines the real impact.
A positive result is script executing when the link is activated, with the probe confirming the origin. Common false positives are values that are escaped into text and never become a live href, links that are rewritten to a safe scheme server-side, and cases where the payload only fires for the submitter because the value is not actually saved. Also check whether a Content Security Policy blocks execution, which would reduce or remove impact.
In general, how it is fixed
Validate the scheme of every stored URL against an allow-list on the server, rejecting anything that is not http or https. Re-apply the same check when rendering the link, so older stored values are neutralised. Encode the value correctly for the attribute context, and add a Content Security Policy that disallows javascript: navigation and inline script. Where a URL is only ever meant to point at an uploaded asset, consider storing the asset and serving it from a controlled host instead of accepting an arbitrary URL.
In general, where to look
This class tends to hide in multi-step commerce and account flows where a value is entered early and displayed late: carts, checkouts, order confirmations, invoices, and admin views of customer-supplied data. Fields that accept either a file or a URL are strong candidates, because the URL branch often gets weaker validation than the upload branch.
Useful signals are client-side controls that let you change an input's type, upload widgets that expose a URL option, and any parameter whose value reappears inside an href or src. Watching how a value is transformed between submission and display shows whether validation happens at all.
Keep the proof minimal and reproducible, and avoid claims about data theft you have not demonstrated.
Glossary
- URL: an address the browser can follow, made of a scheme, a host and a path.
- Scheme: the part of a URL before the colon, such as
http,httpsorjavascript, which tells the browser how to handle it. - Cross-site scripting (XSS): getting a browser to run code on a site that the site's owners did not write.
- Stored XSS: XSS where the bad value is saved on the server and shown to later visitors.
- Reflected XSS: XSS where the bad value is bounced straight back in one response and not saved.
- Payload: the value an attacker submits to trigger the bug.
javascript:URI: a URL whose scheme tells the browser to run the text after the colon as code.alert(document.domain): a harmless probe that shows a pop-up containing the current site's domain.- Origin: the scheme, host and port that the browser uses to decide which site a page belongs to.
- Output encoding: converting special characters so the browser treats them as text, not instructions.
href: the HTML attribute that holds a link's destination.- Allow-list: a list of values that are permitted, with everything else rejected.
- Content Security Policy (CSP): rules the server sends telling the browser which scripts may run.
- CVSS: a standard scoring system for rating the severity of a vulnerability.
- Bounty: a payment a company makes to a researcher who reports a valid bug.