H1514 DOM XSS on checkout.shopify.com via postMessage handler on /:id/sandbox/google_maps
The sandbox pages on checkout.shopify.com that render Google Maps and address autocomplete validate the origin of incoming postMessages but then trust all subsequent messages. A malicious shop can send a crafted message that injects arbitrary HTML into a map label, which executes as script on checkout.shopify.com.
Originally disclosed on HackerOne
- Triaged in 18 hours
- Fixed in 5 months
- Paid in 16 hours
- Disclosed after 13 months
Description:
The /:id/sandbox/google_maps and /:id/sandbox/google_autocomplete routes on checkout.shopify.com are used to render the Google Map on the "Order Status" page as well as the address prediction on checkout pages. The page performs origin validation on incoming postMessages making sure the origin matches the shop associated with :id but then trusts all communication after that validation. A malicious shop can render a Google Map (on checkout.shopify.com) with arbitrary HTML injected as a label which executes on checkout.shopify.com
Technical Details:
Create a shop, capture it's ID (4736483384 in this case). Then add the following script to the shop template:
var frame = document.createElement("iframe");
frame.src = "https://checkout.shopify.com/4736483384/sandbox/google_maps";
frame.onload = function() {
frame.contentWindow.postMessage("shopify_google_api:" + JSON.stringify({
action: "createMapAndMarkers",
body: [{
title: "<img src=xx: onerror=alert(document.domain)>"
}]
}), "*");
}
document.body.appendChild(frame);
Steps To Reproduce:
Open bored-engineering-whitehat-2.myshopify.com/#pwn, wait for the popup.
Impact
XSS on checkout.shopify.com which hosts maps and other information for order statuses and cart checkouts.
Context
checkout.shopify.com hosts two sandbox routes, /:id/sandbox/google_maps and /:id/sandbox/google_autocomplete, where :id is a shop identifier. They exist to render the Google Map shown on the "Order Status" page and to provide address prediction on checkout pages. Because the map and the autocomplete widget are served from the checkout origin rather than from the shop's own domain, the shop page has to talk to them across origins, and it does so with postMessage.
The page validates the origin of incoming messages, checking that it matches the shop associated with :id. Once a message passes that check, however, everything in it is trusted. The report's point is that a shop owner controls the content of those messages, so the validation only proves which shop is talking, not that what it says is safe.
Setup
The only precondition is the ability to create a shop, which gives the attacker both a shop ID and a place to host the page that sends the messages. The researcher created a shop and captured its ID, 4736483384, which is used in the iframe URL throughout the report. No other accounts, roles or tooling are described.
Finding it
The message uses a createMapAndMarkers action whose body carries marker data, including a title field. That title is rendered as a label on the map inside checkout.shopify.com. Since the origin check only confirms that the sender is the shop tied to :id, and the shop owner is the sender, the check passes for attacker-controlled content by design.
Exploitation
Step 1: create a shop and note its ID
Create a shop and capture its ID. In this case the ID was 4736483384, and it appears as the :id path segment in the sandbox URL.
Step 2: add a script to the shop template
The following script is placed in the shop template. It creates an iframe pointing at the sandbox route for the attacker's shop, and on load posts a message to it.
var frame = document.createElement("iframe");
frame.src = "https://checkout.shopify.com/4736483384/sandbox/google_maps";
frame.onload = function() {
frame.contentWindow.postMessage("shopify_google_api:" + JSON.stringify({
action: "createMapAndMarkers",
body: [{
title: "<img src=xx: onerror=alert(document.domain)>"
}]
}), "*");
}
document.body.appendChild(frame);
The important parts:
frame.srctargets thegoogle_mapssandbox for the attacker's own shop ID, so the origin check inside the frame will see the shop it expects.- The message is a string with the prefix
shopify_google_api:followed by a JSON document, which is the format the handler parses. action: "createMapAndMarkers"selects the map rendering path, andbodyis an array of marker objects.- The
titleof the marker is animgelement with a deliberately brokensrc(xx:) and anonerrorhandler that callsalert(document.domain). If the title is inserted as HTML, the image fails to load and the handler runs. - The target origin is
"*", which is fine here because the frame is same-page controlled and the message contains no secrets.
Step 3: load the page and observe the popup
Open the shop page with the fragment that triggers the script:
https://bored-engineering-whitehat-2.myshopify.com/#pwn
Wait for the popup. Wait for the popup, which shows that the injected markup executed.
Root cause
The sandbox page performs origin validation on incoming postMessage events, checking that the origin matches the shop associated with :id, but then trusts all communication after that validation. The marker title from the message body is injected as a label and executes in the checkout.shopify.com document. The origin check is not a defence against this: the shop owner is exactly the party the check is meant to allow, and the check says nothing about the safety of the payload's contents.
Impact
Script execution on checkout.shopify.com, the origin that hosts maps and other information for order statuses and cart checkouts. The report frames the impact in those terms and does not go further into which users or sessions could be reached.
Fix
The report does not describe a fix or a change that was made.
- Other actions on the same handler. Send messages with actions other than
createMapAndMarkersand look for fields that end up in the DOM. A positive result is any field whose value is parsed as HTML, shown by an element with an event handler firing. - The sibling route. Repeat the same message against
/:id/sandbox/google_autocompletefor the attacker's shop ID. A positive result is the same execution of injected markup oncheckout.shopify.com. - Other fields in the marker object. Beyond
title, try the other properties the map renderer consumes. A positive result is any of them being inserted unencoded into the label or surrounding markup. - Other
postMessageconsumers on the checkout origin. Look for handlers that validate the sender's origin and then act on the payload without encoding. A positive result is execution in the checkout document from a message the attacker's own shop is authorised to send.
This kind of bug hides where a page on a shared origin is designed to be driven by content from a less trusted origin, typically through postMessage, and where the receiving side checks who sent the message but not what it contains. During recon, the signals are sandbox or embed routes on a checkout or payment host that take an identifier for the merchant, plus client-side code that parses a prefixed message format and dispatches on an action field. Once such a handler is found, the useful question is which fields of the payload reach the DOM and whether they are inserted as HTML.
To show impact, the researcher used a shop they controlled, sent the message from a page on that shop to the sandbox route for the same shop ID so the origin check passed, and demonstrated execution with alert(document.domain), which makes the executing origin explicit. That is enough to show the boundary crossed: markup from the shop running on checkout.shopify.com.
What happened, in plain words
Shopify is a platform that lets anyone open an online shop. When a customer buys something, the checkout and the "Order Status" page are served from Shopify's own address, checkout.shopify.com, not from the shop's address. Those pages show a Google Map and offer address suggestions while the customer types.
To draw that map and those suggestions, Shopify loads a small helper page from checkout.shopify.com. The shop's own page and this helper page live on different addresses, so the browser treats them as different origins and normally stops them from reading each other's content. To get around that, the two pages talk using a browser feature called postMessage, which lets one page send a message to another page in a frame.
The helper page checks who sent the message: it confirms the sender is the shop that owns the identifier in the URL. But after that check, it trusts everything inside the message. The researcher showed that a shop owner can put HTML into one of the fields of that message, and the helper page inserts it into the map label as if it were part of the page. The HTML then runs as code on checkout.shopify.com.
That is a DOM-based cross-site scripting bug (DOM XSS): a script that is already running in the browser takes data from somewhere untrusted and writes it into the page in a way that turns it into live markup. The result here is that code controlled by a shop owner executes on Shopify's checkout address.
The pieces involved
Before the steps, here are the parts of the system the report touches, explained from scratch.
- Origin: the combination of protocol, host and port that a browser uses to decide whether two pages are the same site.
https://checkout.shopify.comandhttps://your-shop.myshopify.comare different origins, even though both belong to Shopify. Pages from different origins are kept apart on purpose. - iframe: a box inside a web page that loads another web page. Think of it as a window cut into a wall, through which you see a different room. The outer page and the page inside the frame are separate documents.
postMessage: the browser's built-in way for two pages to send each other text messages, even across origins. It is like passing notes through a slot in the wall: the receiving side gets the note, but must decide whether to trust it.- API: a defined set of requests a program accepts and the responses it gives. A restaurant menu is a fair comparison: it lists what you can order and how to order it, and the kitchen handles those orders in a fixed way. Here the helper page accepts messages in a particular format and performs actions named in them.
- JSON: a text format for structured data, made of names and values in curly braces and square brackets. It is how the message describes which action to take and what data to use.
- DOM: the browser's in-memory model of a page, the tree of elements that makes up what you see. "DOM XSS" means the dangerous data flows into that model while the page is running, rather than being baked into the page the server sent.
- HTML injection: putting text that looks like HTML (for example, an
<img>tag) into a place where the browser treats it as markup instead of as plain characters. The browser then creates real elements from it. - Event handler: an attribute on an HTML element that tells the browser what to do when something happens to that element, such as an image failing to load.
alert(document.domain): a way to prove which site the code is running on.document.domainis the address of the page the script is executing in, andalertshows it in a popup.
Context: the two sandbox routes
checkout.shopify.com hosts two sandbox routes:
/:id/sandbox/google_maps/:id/sandbox/google_autocomplete
A route is simply a path on a website, the part after the domain name. The :id part is a placeholder for a shop identifier, a number that tells Shopify which shop is asking. The first route renders the Google Map on the "Order Status" page; the second provides address prediction on checkout pages.
Because these helpers are served from the checkout origin and not from the shop's own domain, the shop page has to talk to them across origins, and it does so with postMessage. The helper page validates the origin of incoming messages, checking that it matches the shop associated with :id. Once a message passes that check, however, everything in it is trusted.
The report's point is that a shop owner controls the content of those messages. The validation only proves which shop is talking, not that what it says is safe. A bouncer checking that you are on the guest list does not inspect what is in your bag.
Setup: what the attacker needs
The only precondition is the ability to create a shop. That gives the attacker both a shop ID and a place to host the page that sends the messages. The researcher created a shop and captured its ID, 4736483384, which is used in the iframe URL throughout the report. No other accounts, roles or tooling are described.
Finding it
The message uses a createMapAndMarkers action whose body carries marker data, including a title field. That title is rendered as a label on the map inside checkout.shopify.com.
Since the origin check only confirms that the sender is the shop tied to :id, and the shop owner is the sender, the check passes for attacker-controlled content by design. If it is inserted as text, the browser shows the characters <img ...> on the map and nothing happens. If it is inserted as HTML, the browser builds a real image element, and anything attached to that element runs.
Exploitation
Step 1: create a shop and note its ID
Create a shop and capture its ID. In this case the ID was 4736483384, and it appears as the :id path segment in the sandbox URL. This step matters because the origin check compares the sender against the shop named in the URL. Using your own shop ID means the check is satisfied by your own page, which is exactly the situation the check is designed to allow.
Step 2: add a script to the shop template
The following script is placed in the shop template. A shop template is the page content the shop owner controls, so anything placed there runs when a visitor opens the shop page.
var frame = document.createElement("iframe");
frame.src = "https://checkout.shopify.com/4736483384/sandbox/google_maps";
frame.onload = function() {
frame.contentWindow.postMessage("shopify_google_api:" + JSON.stringify({
action: "createMapAndMarkers",
body: [{
title: "<img src=xx: onerror=alert(document.domain)>"
}]
}), "*");
}
document.body.appendChild(frame);
Line by line:
var frame = document.createElement("iframe");creates a new iframe element in memory. It is not on the page yet; it is just an object the script can configure.frame.src = "https://checkout.shopify.com/4736483384/sandbox/google_maps";sets the address the frame will load. It points at thegoogle_mapssandbox for the attacker's own shop ID, so the origin check inside the frame will see the shop it expects. This is the key choice: the frame is Shopify's page, not the attacker's page, but it is told to serve the attacker's shop.frame.onload = function() { ... }registers code to run once the frame has finished loading. Sending a message before the frame's page is ready would be like shouting at an empty room.frame.contentWindow.postMessage(...)sends a message into the frame's page.contentWindowis the frame's own window object, the handle used to talk to it.- The first argument to
postMessageis the message itself. It is built as"shopify_google_api:" + JSON.stringify({...}): a fixed prefix string, then the JSON text of an object. The prefix is the format the handler parses; the JSON carries the instructions. action: "createMapAndMarkers"selects the map rendering path. The receiving page reads this field to decide what to do, like choosing an item from the menu.body: [{ ... }]is an array of marker objects. The square brackets mean a list; here the list has one marker.title: "<img src=xx: onerror=alert(document.domain)>"is the marker's label. It is animgelement with a deliberately brokensrc(xx:) and anonerrorhandler that callsalert(document.domain). Thexx:address cannot load, so the browser fires the error event, and the handler runs. If the title is inserted as HTML, the image fails to load and the handler executes.- The second argument to
postMessage,"*", is the target origin. It means "deliver to whatever origin the frame is on, no restriction". That is fine here because the frame is controlled by the same page and the message contains no secrets. document.body.appendChild(frame);finally puts the frame on the page, which starts the load and, later, theonloadcode.
Step 3: load the page and observe the popup
Open the shop page with the fragment that triggers the script:
https://bored-engineering-whitehat-2.myshopify.com/#pwn
The #pwn part is a fragment, the piece after the # in a URL. It is not sent to the server; it is read by the page's own scripts. Here it is the trigger that causes the shop page to run the code above.
Wait for the popup. Wait for the popup, which shows that the injected markup executed. That distinction is the whole finding: the code did not run on the attacker's shop, where the attacker already has control, but on Shopify's checkout address.
Root cause
The sandbox page performs origin validation on incoming postMessage events, checking that the origin matches the shop associated with :id, but then trusts all communication after that validation. The marker title from the message body is injected as a label and executes in the checkout.shopify.com document.
The origin check is not a defence against this. The shop owner is exactly the party the check is meant to allow, and the check says nothing about the safety of the payload's contents. Encoding means turning characters that have special meaning in HTML, such as < and >, into harmless representations so the browser displays them instead of acting on them.
Impact
Script execution on checkout.shopify.com, the origin that hosts maps and other information for order statuses and cart checkouts. The report frames the impact in those terms and does not go further into which users or sessions could be reached.
Fix
The report does not describe a fix or a change that was made.
- Other actions on the same handler. Send messages with actions other than
createMapAndMarkersand look for fields that end up in the DOM. A positive result is any field whose value is parsed as HTML, shown by an element with an event handler firing. - The sibling route. Repeat the same message against
/:id/sandbox/google_autocompletefor the attacker's shop ID. A positive result is the same execution of injected markup oncheckout.shopify.com. - Other fields in the marker object. Beyond
title, try the other properties the map renderer consumes. A positive result is any of them being inserted unencoded into the label or surrounding markup. - Other
postMessageconsumers on the checkout origin. Look for handlers that validate the sender's origin and then act on the payload without encoding. A positive result is execution in the checkout document from a message the attacker's own shop is authorised to send.
This kind of bug hides where a page on a shared origin is designed to be driven by content from a less trusted origin, typically through postMessage, and where the receiving side checks who sent the message but not what it contains. During recon, the signals are sandbox or embed routes on a checkout or payment host that take an identifier for the merchant, plus client-side code that parses a prefixed message format and dispatches on an action field. Once such a handler is found, the useful question is which fields of the payload reach the DOM and whether they are inserted as HTML.
To show impact, the researcher used a shop they controlled, sent the message from a page on that shop to the sandbox route for the same shop ID so the origin check passed, and demonstrated execution with alert(document.domain), which makes the executing origin explicit. That is enough to show the boundary crossed: markup from the shop running on checkout.shopify.com.
Glossary
- Origin: the combination of protocol, host and port that a browser uses to decide whether two pages are the same site; pages from different origins are kept apart.
- iframe: a box inside a web page that loads another web page, as a separate document.
postMessage: the browser feature that lets two pages send each other text messages, even across origins.- API: a defined set of requests a program accepts and the responses it gives, like a menu of allowed orders.
- JSON: a text format for structured data, made of names and values in braces and brackets.
- DOM: the browser's in-memory tree of elements that makes up the page you see.
- DOM XSS: cross-site scripting where untrusted data is written into the page by running script, turning it into live markup.
- Cross-site scripting (XSS): a bug where attacker-controlled content is treated as code by a victim's browser.
- HTML injection: placing text that looks like HTML where the browser treats it as markup instead of plain characters.
- Event handler: an attribute on an element that tells the browser what to do when something happens to it, such as an image failing to load.
onerror: the event handler that fires when an element, such as an image, fails to load its resource.alert: a browser popup used to display a message, often to prove that code ran.document.domain: the address of the page a script is running in, used here to show which origin executed the code.- Route: a path on a website, the part after the domain name.
- Sandbox route: a helper page on a shared origin that is driven by messages from another origin.
- Shop ID: the number that identifies a shop, used as the
:idplaceholder in the sandbox URL. - Shop template: the page content a shop owner controls, which runs when a visitor opens the shop page.
- Fragment: the part of a URL after the
#, read by the page's own scripts and not sent to the server. - Output encoding: converting characters with special meaning in HTML into harmless representations so they are displayed rather than acted on.
- Recon: the information-gathering phase of security testing, looking for routes, formats and handlers worth probing.