XSS in $shop$.myshopify.com/admin/ via "Button Objects" in malicious app
The Shopify Embedded App SDK did not sanitise the href parameter of button objects, allowing a malicious app to execute JavaScript in the admin interface when an admin clicked a button. An attacker could run arbitrary script in the context of the shop admin.
Originally disclosed on HackerOne
- Triaged in 38 hours
- Fixed in 34 days
- Paid in 44 days
- Disclosed after 51 days
This report is similar in impact, exploitability and root-cause as report #205701 requiring an additional step of user-interaction.
#Description
The Shopify Embedded App SDK is used to facilitate limited interactions with parent page (/admin/apps/$id) from an embedded app within the shop admin interface. The SDK has multiple methods which accept a buttons parameter which is defined under the button objects section of the SDK documentation. Buttons can define a href parameter which will open when the button is clicked. The href parameter is not properly sanitized allowing a malicious app to execute JavaScript in the context of the admin interface.
#Technical Details
When a button is clicked the clickButton method is called, the method is defined as follows:
clickButton = function(_, data) {
if ((data.loading || "undefined" == typeof data.loading && "app" === data.target) && Shopify.Loading.start(), href = data.href) {
switch (data.target) {
case "parent":
case "shopify":
Page.visit(href, {
reload: true
});
break;
case "app":
break;
default:
Page.open(href)
}
}
}
If no target parameter is specified (and the application is already loaded) Page.open will be called. This method is defined like this:
Page.open = function() {
return window.open.apply(window, arguments);
}
You would expect window.open is safe to call with untrusted URLs as it will open in a new window/tab however this is not the case. When window.open is called with a javascript: URL a new window/tab will be opened with the domainless about:blank location (or similar depending on the browser) however the document.domain property will be shared with the opener window. Because the documents share document.domain the new window will be able to access the opener window and trigger JavaScript execution. You can test this yourself like this:
window.open("javascript:window.opener.alert('bored-engineer')")
In the context of Shopify this means an application can create a button that will trigger XSS on the admin interface when the button is clicked. The following script was used to demonstrate the issue:
window.parent.postMessage(JSON.stringify({
message: "Shopify.API.Bar.initialize",
data: {
buttons: {
primary: {
label: "Click here for XSS",
href: "javascript:setTimeout('window.close()',1);window.opener.eval('alert(document.domain)');",
}
}
}
}), "*");
I wanted to note that this needs to be fixed in the Shopify.EmbeddedAppButtons class since this issue affects all methods which render buttons. For example the following script will also trigger XSS using a different method:
window.parent.postMessage(JSON.stringify({
message: "Shopify.API.Modal.open",
data: {
src: "https://attackerdoma.in",
buttons: {
primary: {
label: "Click here for XSS",
href: "javascript:setTimeout('window.close()',1);window.opener.eval('alert(document.domain)');",
}
}
}
}), "*");
#Exploitability You need to convince an administrator to authorize your malicious application, however the exploit does not require any specific permissions to trigger so an admin may be more willing to authorize the application. Once the administrator has loaded the application it is likely they will click at least one of the multiple entry-points for buttons.
#Proof of Concept
I've created an example malicious application associated with my partner account [email protected] to demonstrate the issue...
Open the following URL on on $your-shop$.myshopify.com:
/admin/oauth/authorize?client_id=18cc7056a1476994411e3d21971289a7&scope=read_products&redirect_uri=https://attackerdoma.in/1b61d988-374e-48c8-ae6a-6eb28a0f25de.html&state=nonce
After authorizing the application and click the "Click here for XSS" button in the upper-right corner. An alert should appear on the /admin window containing document.domain.
#Remediation
The application should sanitize the href parameter for all "button objects" either before creating the elements in the DOM, or in the clickButton method before calling Page.open.
Context
Shopify's admin interface can host third-party applications inside the merchant's own admin page. The mechanism for this is the Embedded App SDK, which lets an embedded app talk to its parent page at /admin/apps/$id and perform a limited set of interactions there. Among those interactions are buttons: several SDK methods accept a buttons parameter, and each button is described by a button object as documented in the SDK's "button objects" section. A button object can carry a href, which the admin page opens when the merchant clicks the button.
The report describes a cross-site scripting flaw in that flow. The href value is not properly sanitised, so a malicious app can supply a javascript: URL and get JavaScript executed in the context of the admin interface. The researcher notes that the report is similar in impact, exploitability and root cause to report #205701, with the additional requirement of user interaction.
Setup
To demonstrate the issue the researcher created an example malicious application associated with a partner account. The proof of concept is run against a shop's admin, and the only precondition is that an administrator authorises the malicious application. No specific permissions are needed to trigger the exploit, which the researcher points out may make an admin more willing to grant authorisation. Once the application is loaded, the admin is likely to click at least one of the multiple entry points that render buttons.
Finding it
The starting point is the SDK's button object: a button can define a href parameter that opens when the button is clicked. The researcher traced what happens to that href when the button is clicked and found that it reaches window.open without adequate sanitisation.
When a button is clicked, the clickButton method runs. It is defined as follows:
clickButton = function(_, data) {
if ((data.loading || "undefined" == typeof data.loading && "app" === data.target) && Shopify.Loading.start(), href = data.href) {
switch (data.target) {
case "parent":
case "shopify":
Page.visit(href, {
reload: true
});
break;
case "app":
break;
default:
Page.open(href)
}
}
}
If no target parameter is specified and the application is already loaded, the default branch calls Page.open. That method is a thin wrapper around the browser API:
Page.open = function() {
return window.open.apply(window, arguments);
}
The intuition the researcher challenges is that window.open is safe with untrusted URLs because it opens a new window or tab. That is not the case for javascript: URLs. When window.open is called with a javascript: URL, a new window or tab opens at the domainless about:blank location (or something similar depending on the browser), but the document.domain property is shared with the opener window. Because the documents share document.domain, the new window can reach back into the opener and trigger JavaScript execution there.
The behaviour can be checked directly in a browser:
window.open("javascript:window.opener.alert('bored-engineer')")
Exploitation
Step 1: Send a button definition to the parent admin page
An embedded app can post messages to its parent. The following script was used to demonstrate the issue. It initialises the admin's button bar with a single primary button whose href is a javascript: URL:
window.parent.postMessage(JSON.stringify({
message: "Shopify.API.Bar.initialize",
data: {
buttons: {
primary: {
label: "Click here for XSS",
href: "javascript:setTimeout('window.close()',1);window.opener.eval('alert(document.domain)');",
}
}
}
}), "*");
The data.buttons.primary object is the button definition: a visible label and the malicious href.
Step 2: The admin clicks the button
When the merchant clicks the button, clickButton runs. No target is set in the button object, so the default branch calls Page.open(href), which calls window.open with the javascript: URL. The new window shares document.domain with the opener, so the payload executes in the admin context and the alert shows the admin's document.domain.
Step 3: The same payload through a different method
The researcher notes that the fix belongs in the Shopify.EmbeddedAppButtons class, because the issue affects every method that renders buttons. A second script triggers the same XSS through a different SDK method:
window.parent.postMessage(JSON.stringify({
message: "Shopify.API.Modal.open",
data: {
src: "https://attackerdoma.in",
buttons: {
primary: {
label: "Click here for XSS",
href: "javascript:setTimeout('window.close()',1);window.opener.eval('alert(document.domain)');",
}
}
}
}), "*");
Here the message is Shopify.API.Modal.open, with a src pointing at the attacker's domain and the same button object.
Step 4: Proof of concept with a real application
The researcher created an example malicious application on a partner account to demonstrate the issue end to end. The first step is to open the following URL on $your-shop$.myshopify.com:
/admin/oauth/authorize?client_id=[redacted]&scope=read_products&redirect_uri=https://attackerdoma.in/1b61d988-374e-48c8-ae6a-6eb28a0f25de.html&state=nonce
After authorising the application, the admin clicks the "Click here for XSS" button in the upper-right corner. An alert should then appear on the /admin window containing document.domain.
Root cause
The href of a button object is passed through to Page.open, which is window.open, without sanitisation. The design assumption that window.open isolates untrusted URLs is wrong for javascript: URLs: the opened document is domainless but shares document.domain with its opener, so it can execute code in the opener's context. The vulnerable code is not in a single method: the button rendering is centralised in the Shopify.EmbeddedAppButtons class, and every SDK method that renders buttons inherits the flaw, which is why the researcher stresses fixing it there rather than in one caller.
Impact
A malicious application that an administrator has authorised can execute JavaScript in the context of the Shopify admin interface when the admin clicks a button it controls. The exploit requires user interaction (the click) and the admin's authorisation of the app, but no specific permissions, so the authorisation prompt is less alarming than it would be for a powerful scope. Because buttons appear at multiple entry points in the admin, the researcher considers it likely that an admin will click at least one of them after loading the app.
Fix
The report recommends sanitising the href parameter for all button objects, either before the elements are created in the DOM or in the clickButton method before Page.open is called. The researcher explicitly asks for the fix to live in the Shopify.EmbeddedAppButtons class so that every method which renders buttons is covered.
- Other SDK methods that accept a
buttonsparameter: send the samejavascript:hrefthrough each and check whether a click executes code in the parent. A positive result is an alert showing the admin'sdocument.domain. - Different
targetvalues on the button object: theparentandshopifybranches callPage.visitrather thanPage.open, so test whether ajavascript:URL survives that path too. - Other URL-bearing fields in postMessage-driven SDK calls, such as the
srcused byShopify.API.Modal.open, to see whether they are sanitised wherehrefis not. - Other embedded-app frameworks that render host-controlled buttons or links from app-supplied data, checking whether
javascript:URLs reachwindow.openor an anchorhrefin the host page.
This class of bug hides in the bridge between an embedded third-party app and its host page: postMessage handlers, SDK methods that accept structured UI definitions, and any field that ends up in window.open, location or an anchor href. During recon, look for documented SDK parameters that accept URLs or button objects, and read the host's client-side handler code to see whether values are validated before use. The impact argument that carried this report is concrete: a minimal OAuth scope (read_products), a single click, and an alert on document.domain in the admin window, plus a second method showing the flaw is systemic rather than a one-off.
What happened, in plain words
Shopify is a platform for running online shops. Every shop has an admin area, a private website where the shop owner manages products, orders and settings. Shopify also lets other companies build small applications that plug into that admin area, so the owner can use extra tools without leaving it.
To make that work, Shopify provides a toolkit called the Embedded App SDK. An SDK (software development kit) is a set of ready-made functions that a programmer can call instead of writing everything from scratch. Here the SDK lets the embedded app talk to the surrounding admin page, which is called its parent page, and ask it to do a small number of things, such as showing a button or opening a pop-up window.
One of those requests is about buttons. Several SDK functions accept a buttons parameter, which is a description of the buttons to draw. Each button is described by a button object, a small bundle of settings with fields such as the text on the button and a href. A href is the address a browser goes to when a link is clicked. When the shop owner clicks the button, the admin page opens whatever address is in that href.
The bug is that the admin page does not check what kind of address the href contains. A malicious app can put a javascript: address there. A javascript: address is not a website at all: it is a piece of JavaScript code, the language that web pages use to make things happen, and a browser will run it instead of navigating. The result is that the app's code runs inside the admin page. This kind of flaw, where an attacker gets their code to run in someone else's page, is called cross-site scripting, usually shortened to XSS.
The researcher also notes that this report is similar in impact, exploitability and root cause to an earlier report, #205701, but needs one extra step from the victim: a click.
Setup
To show the problem, the researcher built an example malicious application and registered it on a partner account. A partner account is a developer account on Shopify, separate from a shop, used to create and manage apps.
The demonstration runs against a shop's admin area. The only thing needed beforehand is that an administrator of the shop authorises the malicious application. Authorising means the shop owner reviews the app's request for access and clicks to allow it, the same way you approve an app on a phone.
No specific permissions are needed to trigger the exploit. Permissions (also called scopes) are the individual rights an app asks for, such as reading products or changing orders. Because no specific permissions are needed to trigger the exploit, the approval screen is less alarming. and the researcher points out that an admin may therefore be more willing to approve it. Once the app is loaded, the admin is likely to click at least one of the several places in the admin where buttons appear.
Finding it
The starting point is the button object in the SDK documentation. A button can define a href parameter, and that address is opened when the button is clicked. The researcher followed what happens to that href after the click and found that it arrives at a browser function called window.open without being properly cleaned up. Cleaning up input so that dangerous content cannot get through is called sanitisation.
When a button is clicked, a function called clickButton runs. It is defined as follows:
clickButton = function(_, data) {
if ((data.loading || "undefined" == typeof data.loading && "app" === data.target) && Shopify.Loading.start(), href = data.href) {
switch (data.target) {
case "parent":
case "shopify":
Page.visit(href, {
reload: true
});
break;
case "app":
break;
default:
Page.open(href)
}
}
}
Line by line, in plain words:
clickButton = function(_, data) {defines the function. It receives two pieces of information:_, which is ignored, anddata, which holds the details of the button that was clicked.- The long
if (...)line does two things at once. It checks whether a loading indicator should be started, and it copies the button's address into a variable calledhrefwithhref = data.href. The rest of the function only runs if there is an address to work with. switch (data.target)looks at the button'stargetsetting, which says where the address should be opened.case "app":does nothing at all, so the address is ignored.- It calls
Page.open(href). - The closing braces end the switch and the function.
So if the button does not specify a target and the application is already loaded, the address ends up in the default branch and Page.open is called. That function is a very thin wrapper around a browser feature:
Page.open = function() {
return window.open.apply(window, arguments);
}
This means: Page.open takes whatever arguments it was given and passes them straight to window.open, a built-in browser function that opens a new window or tab.
The common assumption the researcher challenges is that window.open is safe to use with untrusted addresses, because it opens a separate window or tab and so the untrusted content is kept apart. That assumption fails for javascript: addresses. When window.open is given a javascript: address, a new window or tab opens at about:blank, a blank page that belongs to no website (or something similar, depending on the browser). But that blank page still shares a property called document.domain with the window that opened it, known as the opener. document.domain is the domain the page reports for itself, and pages that share it are allowed to reach into each other. Because the two documents share document.domain, the new window can reach back into the opener and run code there.
You can check this behaviour yourself in a browser:
window.open("javascript:window.opener.alert('bored-engineer')")
In plain words: window.open opens a new window using the javascript: address. That address runs window.opener.alert('bored-engineer'), where window.opener means the window that did the opening, and alert shows a pop-up box with the given text. If the box appears in the original page, the new window has successfully run code in the opener.
Exploitation
Step 1: Send a button definition to the parent admin page
An embedded app can send messages to its parent page. The following script was used to demonstrate the issue. It sets up the admin's button bar with a single primary button whose href is a javascript: address:
window.parent.postMessage(JSON.stringify({
message: "Shopify.API.Bar.initialize",
data: {
buttons: {
primary: {
label: "Click here for XSS",
href: "javascript:setTimeout('window.close()',1);window.opener.eval('alert(document.domain)');",
}
}
}
}), "*");
Line by line:
window.parentrefers to the page that contains the app, which is the admin page.postMessageis a browser feature that lets one window send a message to another.- JSON is a simple text format for structured data.
data: { buttons: { primary: { ... } } }is the description of the buttons to draw.primaryis the main button.label: "Click here for XSS"is the text the admin will see on the button.evalruns a piece of text as code, anddocument.domainis the site name the admin page belongs to, so the alert displays that name.}), "*");closes the call.
Step 2: The admin clicks the button
When the shop owner clicks the button, clickButton runs. The button object has no target, so the default branch calls Page.open(href), which calls window.open with the javascript: address. The new window shares document.domain with the opener, so the code runs in the admin's context and the alert shows the admin's document.domain.
Step 3: The same payload through a different method
The researcher notes that the fix belongs in a class called Shopify.EmbeddedAppButtons, because the problem affects every function that draws buttons. A class is a reusable piece of code that groups related behaviour; here it is the shared code that builds buttons. A second script triggers the same XSS through a different SDK function:
window.parent.postMessage(JSON.stringify({
message: "Shopify.API.Modal.open",
data: {
src: "https://attackerdoma.in",
buttons: {
primary: {
label: "Click here for XSS",
href: "javascript:setTimeout('window.close()',1);window.opener.eval('alert(document.domain)');",
}
}
}
}), "*");
This is the same structure as before, with two differences. The message is now Shopify.API.Modal.open, which asks the admin to open a modal, a pop-up panel inside the page. The button object is identical. Because both functions use the same button-building code, the payload fires in the same way.
Step 4: Proof of concept with a real application
The researcher created an example malicious application on a partner account to demonstrate the issue from start to finish. The first step is to open the following address on $your-shop$.myshopify.com:
/admin/oauth/authorize?client_id=[redacted]&scope=read_products&redirect_uri=https://attackerdoma.in/1b61d988-374e-48c8-ae6a-6eb28a0f25de.html&state=nonce
/admin/oauth/authorizeis the admin page that shows the approval screen.client_id=[redacted]identifies which application is asking, like an application number.scope=read_productsasks for one small permission: reading products.redirect_uri=https://attackerdoma.in/1b61d988-374e-48c8-ae6a-6eb28a0f25de.htmlis where the browser is sent after approval, here a page on the attacker's domain.state=nonceis a random value the requester can use to recognise the reply. A nonce is a value used once.
After approving the application, the admin clicks the "Click here for XSS" button in the upper-right corner. An alert should then appear on the /admin window containing document.domain.
Root cause
The href of a button object is passed through to Page.open, which is window.open, without sanitisation. The design assumption that window.open keeps untrusted addresses safely apart is wrong for javascript: addresses: the opened document belongs to no site, but it shares document.domain with its opener, so it can run code in the opener's context. The faulty code is not in one single function: button drawing is centralised in the Shopify.EmbeddedAppButtons class, and every SDK function that draws buttons inherits the flaw. That is why the researcher stresses fixing it there rather than in one caller.
Impact
A malicious application that an administrator has approved can run JavaScript in the context of the Shopify admin interface when the admin clicks a button the app controls. The exploit needs the admin to click and to approve the app, but no specific permissions, so the approval screen is less alarming than it would be for a powerful permission. Because buttons appear in several places in the admin, the researcher considers it likely that an admin will click at least one of them after loading the app.
Fix
The report recommends sanitising the href parameter for all button objects, either before the elements are created in the DOM or in the clickButton method before Page.open is called. The DOM, short for Document Object Model, is the browser's in-memory model of the page, the structure that the page's elements are built into. The researcher explicitly asks for the fix to live in the Shopify.EmbeddedAppButtons class so that every function which draws buttons is covered.
- Other SDK functions that accept a
buttonsparameter: send the samejavascript:hrefthrough each and check whether a click runs code in the parent. A positive result is an alert showing the admin'sdocument.domain. - Different
targetvalues on the button object: theparentandshopifybranches callPage.visitrather thanPage.open, so test whether ajavascript:address survives that path too. - Other address-bearing fields in messages sent to the SDK, such as the
srcused byShopify.API.Modal.open, to see whether they are sanitised wherehrefis not. - Other embedded-app frameworks that draw buttons or links in the host page from data supplied by the app, checking whether
javascript:addresses reachwindow.openor a link'shrefin the host page.
This class of bug hides in the bridge between an embedded third-party app and its host page: the code that receives messages, SDK functions that accept structured descriptions of interface elements, and any field that ends up in window.open, location or a link's href. During recon, look for documented SDK parameters that accept addresses or button objects, and read the host's client-side code to see whether values are checked before use. The impact argument that carried this report is concrete: a minimal OAuth permission (read_products), a single click, and an alert on document.domain in the admin window, plus a second function showing the flaw is systemic rather than a one-off.
Glossary
- Admin interface: the private area of a Shopify shop where the owner manages products, orders and settings.
- Embedded app: a third-party application whose pages are shown inside a frame within the shop admin page.
- SDK (software development kit): a set of ready-made functions provided so programmers can build on a platform without writing everything themselves.
- Parent page: the page that contains another page in a frame; here, the admin page that hosts the embedded app.
- Parameter: a named value passed to a function to tell it what to work with.
- Button object: a small bundle of settings describing a button, such as its label and its
href. href: the address a browser goes to when a link or button is clicked.javascript:URL: an address that contains JavaScript code instead of a website location; the browser runs the code instead of navigating.- JavaScript: the programming language that web pages use to make things happen in the browser.
- Cross-site scripting (XSS): a flaw where an attacker gets their code to run inside someone else's web page, with that page's access.
- Sanitisation: cleaning up input so that dangerous content cannot get through.
window.open: a built-in browser function that opens a new window or tab.- Opener: the window that opened another window.
document.domain: the browser's record of which site a page belongs to; pages that share it may reach into each other.about:blank: a blank page that belongs to no website.postMessage: a browser feature that lets one window send a message to another.- JSON: a simple text format for structured data.
eval: a function that runs a piece of text as code.setTimeout: a function that runs a piece of code after a short delay.- Target origin: in
postMessage, the site the message is intended for;"*"means any site. - Class: a reusable piece of code that groups related behaviour.
- Modal: a pop-up panel shown inside a page.
- OAuth: a system that lets one website ask you to grant another website access to your account without sharing your password.
client_id: the identifier of the application making an OAuth request.- Scope: a single named permission an application asks for, such as reading products.
redirect_uri: the address the browser is sent to after an OAuth request is approved.state/ nonce: a value used once, so the requester can recognise the reply to its request.- Partner account: a developer account on Shopify, separate from a shop, used to create and manage apps.
- DOM (Document Object Model): the browser's in-memory model of the page, the structure its elements are built into.
- Recon: the information-gathering phase of security testing, before attempting an exploit.