Skip to content
XSS Disclosed report Intermediate

xss on polaris.shopify.com/demo using postMessage

The Polaris demo page listens for postMessage events and renders the supplied AST code as React without checking the message origin. An attacker could send a crafted message from another page to run arbitrary JavaScript in the victim's browser on the polaris.shopify.com origin.

coldd Follow

Originally disclosed on HackerOne

  • Triaged in 7 hours
  • Fixed in 25 hours
  • Disclosed after 8 months

Description

it's possible to run arbitrary js code using https://polaris.shopify.com/demo + postMessage

following codes are from this file which formatted using prettier

Demo component (line 381) uses addEventListener to listen for message events (line #401):

JavaScript
          componentDidMount() {
            window.addEventListener("message", this.handleMessage),
              this.throttledSendDetails(),
              window.addEventListener("click", handleAnchorClick);
          }

handleMessage method (line #499) will set data.ats as component state without checking message origin:

JavaScript
          handleMessage(e) {
            var { data: t } = e;
            console.log(e);
            var r = Object(_app_utilities_ast__WEBPACK_IMPORTED_MODULE_61__.a)(
              t.ast.code
            );
            t &&
              Object.prototype.hasOwnProperty.call(t, "ast") &&
              this.setState({
                ast: r,
                fullSizeExamples: t.fullSizeExamples,
                omitAppProvider: t.omitAppProvider,
              });
          }

ast.code later rendered as React code.

Step to Reproduce

  1. create a HTML file containing an iframe with https://polaris.shopify.com/demo as src
  2. after iframe loaded, send a message with {ast: {code: "JSX code"}} as data
HTML
    <iframe id="ifrm" src="https://polaris.shopify.com/demo" height="100%" width="100%" frameborder="0"></iframe>
    <script>
      var ifrm = document.getElementById('ifrm');
      ifrm.onload = function() {
        ifrm.contentWindow.postMessage({ast: {
          code: "{{media:0}} alert(document.location)} />;",
        }}, '*');
      }
    </script>

PoC

http://209.141.43.59/shopify-xss.html

Impact

attacker can use bug to run arbitrary js code in victims browser.

The original report as published on HackerOne, by coldd. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the message handler trusted any incoming postMessage and rendered the supplied code as React without validating the sender's origin.

Impact

An attacker could run arbitrary JavaScript in a victim's browser in the context of the polaris.shopify.com origin.

What the attacker needed

Victim visits attacker-controlled page; demo page loaded in an iframe

How it was found

  1. Create an HTML page containing an iframe whose source is the Polaris demo page.
  2. Wait for the iframe to finish loading.
  3. Send a message containing an ast object with code to the iframe's window.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A web page can receive messages from other pages through a browser feature called postMessage. This demo page accepted such messages and turned the code inside them into live page content without checking who sent them, so another site could make it run the attacker's JavaScript.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by coldd

View all

2 more disclosed reports, best first.

More from Shopify

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.