Reflected DOM XSS on www.starbucks.co.uk
A reflected DOM XSS on www.starbucks.co.uk combined an HTML attribute injection into a canonical link element with a third-party prettyPhoto module that triggers a click event on any element. An attacker could execute arbitrary JavaScript in a victim's browser by tricking them into visiting a crafted URL.
- Triaged in 3 days
- Fixed in 10 months
- Paid in 3 days
- Disclosed after 22 months
Summary by the program
bayotop discovered a reflected DOM XSS on www.starbucks.co.uk. @bayotop — thank you for reporting this vulnerability and for confirming the resolution.
The report
Summary:
www.starbucks.co.uk is vulnerable to reflected DOM XSS due to 2 seemingly unexploitable issues. The first issue is unfixed for over a year now, #252908, the second issue originates in a 3rd party module called prettyPhoto.
Description:
Visiting the following link results in a JavaScript alert (use Firefox or Edge, Chrome's XSS Auditor blocks this particular payload):
https://www.starbucks.co.uk/shop/card/egift/thank-you/anything%2522onclick=%2522confirm(document.domain)#!\'\,\*\,/1
This is possible because:
- there is a seemingly harmless HTML attribute injection into a
<link rel="canonical">element (unfixed for over a year, see #252908) and - the prettyPhoto JavaScript module allows to trigger the
clickevent on any existing HTML element.
The following is done by prettyPhoto in https://www.starbucks.com/static/resource/shop_js/676938998_en-US:
function d() {
url = location.href;
hashtag = (url.indexOf("#!") != -1) ? decodeURI(url.substring(url.indexOf("#!") + 2, url.length)) : false;
return hashtag
}
hashIndex = d();
hashRel = hashIndex;
hashIndex = hashIndex.substring(hashIndex.indexOf("/") + 1, hashIndex.length - 1);
hashRel = hashRel.substring(0, hashRel.indexOf("/"));
hashIndex = parseInt(hashIndex);
hashRel = hashRel.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/])/g, "\\$1");
setTimeout(function() {
b("a[rel^='" + hashRel + "']:eq(" + hashIndex + ")").trigger("click")
}, 50)
Notice how the user-controlled hashRel variable is sanitized to prevent DOM XSS in a quite obscure manner. It only works because it prefixes = with a \ ruining all standard DOM XSS payloads known to me. Also notice that \ is not escaped which means that it's possible to inject arbitrary valid jQuery selectors.
Combining these two issues makes it possible to execute arbitrary JavaScript, by injecting an onclick HTML attribute into the <link rel="canonical"> element and triggering it via the prettyPhoto JavaScript module by setting hashRel to \'\,\*\,. Due to the used jQuery version and it's lax parsing the following triggers the click event on all existing elements:
$("a[rel^='\\\\'\\\\,\\\\*\\\\,']:eq(NaN)").trigger("click")
Steps To Reproduce:
Tested on latest Firefox and Edge:
https://www.starbucks.co.uk/shop/card/egift/thank-you/anything%2522onclick=%2522confirm(document.domain)#!\'\,\*\,/1
Recommendation:
Regarding the HTML attribute injection I suggested a fix in #252908. Regarding prettyPhoto, I don't believe it's actively maintained anymore so a customization will be necessary in my opinion. White-listing allowed characters in hashRel is the way to go with something like \w+.
Impact
Attackers can execute arbitrary JavaScript in the victims' browsing context by tricking them into visiting an URL under the attackers' control. I believe you are aware of the dangers of XSS, but I am more then happy to show an actual exploit if needed.
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
Impact
Attackers could execute arbitrary JavaScript in the victims' browsing context by tricking them into visiting an attacker-controlled URL, though Chrome's XSS Auditor blocks this particular payload.
What the attacker needed
Victim uses Firefox or Edge; victim clicks a crafted link
The fix
The HTML attribute injection should be fixed as suggested in the earlier report, and the prettyPhoto module should whitelist allowed characters in the hashRel variable (for example, using a word-character pattern).
How it was found
- Open the crafted URL in Firefox or Edge (Chrome's XSS Auditor blocks this particular payload).
- The page reflects the injected attribute into the canonical link element.
- The prettyPhoto module reads the hash fragment and builds a jQuery selector.
- The module triggers a click event on the matching element, executing the injected JavaScript.
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.
The website took part of the web address and used it to build a link tag without cleaning it properly, so an attacker could sneak in an extra attribute. A separate photo gallery script then automatically 'clicked' that element, running the attacker's JavaScript. This lets an attacker run code in the victim's browser if the victim opens a specially crafted link.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.