Stored XSS in blog comments through Shopify API
The Shopify comment API accepted an unsanitised body_html field, letting an app with comment permission inject HTML and JavaScript into a comment, which executed in the Shopify admin panel when viewing comments.
Originally disclosed on HackerOne
- Triaged in 32 hours
- Fixed in 3 months
- Paid in 3 months
- Disclosed after 3 months
Summary by the program
Though html content can be set through the API for many locations in the Shopify storefront, this report was a special case. We were also displaying the body_html of these comments in Shopify admin, leading to XSS in admin rather than the storefront.
The report
Hi there!
As far I understand the Shopify Shop have blogs which allow users to comment on blog posts, however the comments with HTML content automatically gets sanitised and then posted to avoid XSS issue. However using the API for comment modification, any application with comment permission can modify a comment and include arbitrary HTML leading to XSS.
Steps to Reproduce
- Open the Shopify Shop's blog and post a comment on a blogpost through a browser.
- Note the comment id, this can be easily grabbed by checking the HTML after the comment is posted:
Eg. <div id="comment-2929551246" class="comment border-bottom clearfix">
3. Now setup an application with comment permission on the Shop
4. Send the following JSON to the API endpoint /admin/comments/<comment-id>.json
{ "comment": { "id": <comment-id>, "body": "blahblah", "body_html": "blah<img src=x onerror=alert(0);>" } }
5. Send request twice.
6. Visit the blog post, JS in the comment should execute.
I believe this is a valid bug as the comment should get stripped of HTML, which is not the case in case of the above request, however it does gets stripped when posted via web or modified through the comment API documentation at https://help.shopify.com/api/reference/comment#update. To insert arbitrary HTML I've purposely added body_html in the request, which is not mentioned in the API reference, the allows me to add HTML, in the comment. The HTML even executes in the Shop's Admin Panel when viewing comments for a particular blog.
PoC (see comment section for JS execution): https://derp-10.myshopify.com/blogs/news/43260355-first-post
Video: https://www.dropbox.com/s/7ie1tiex1eo4kk9/Comment%20XSS.mov?dl=0
Thanks, Prakhar Prasad
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 comment update API did not sanitise the body_html field, unlike the web form and documented API fields.
Impact
An attacker with an app that has comment permission could store JavaScript that executes for anyone viewing the comment, including store administrators in the admin panel.
What the attacker needed
An app with comment permission on the shop; a blog post with comments enabled
How it was found
- Post a comment on a blog post through the browser.
- Note the comment id from the page HTML.
- Set up an application with comment permission on the shop.
- Send a JSON request to the comment API endpoint including a body_html field with HTML.
- Send the request twice.
- Visit the blog post or admin comments view and observe JavaScript execution.
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 blog comment normally has its HTML removed so that any JavaScript is harmless. Here, an extra field in an API request let an app sneak HTML back in, and that HTML ran as code when someone viewed the comment. This is called stored XSS because the malicious content is saved and later shown to other users.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.