Launchpad security advisory: cross-site-scripting in site search
Summary
Mohamed Alaa reported that Launchpad’s Bing site search implementation had a cross-site-scripting vulnerability. This was introduced on 2018-03-29, and fixed on 2018-04-10. We have not found any evidence of this bug being actively exploited by attackers; the rest of this post is an explanation of the problem for the sake of transparency.
Details
Some time ago, Google announced that they would be discontinuing their Google Site Search product on 2018-04-01. Since this served as part of the backend for Launchpad’s site search feature (“Search Launchpad” on the front page), we began to look around for a replacement. We eventually settled on Bing Custom Search, implemented appropriate support in Launchpad, and switched over to it on 2018-03-29.
Unfortunately, we missed one detail. Google Site Search’s XML API returns excerpts of search results as pre-escaped HTML, using <b>
tags to indicate where search terms match. This makes complete sense given its embedding in XML; it’s hard to see how that API could do otherwise. The Launchpad integration code accordingly uses TAL code along these lines, using the structure
keyword to explicitly indicate that the excerpts in question do not require HTML-escaping (like most good web frameworks, TAL’s default is to escape all variable content, so successful XSS attacks on Launchpad have historically been rare):
<div class="summary" tal:content="structure page/summary" />
However, Bing Custom Search’s JSON API returns excerpts of search results without any HTML escaping. Again, in the context of the API in question, this makes complete sense as a default behaviour (though a textFormat=HTML
switch is available to change this); but, in the absence of appropriate handling, this meant that those excerpts were passed through to the TAL code above without escaping. As a result, if you could craft search terms that match a portion of an existing page on Launchpad that shows scripting tags (such as a bug about an XSS vulnerability in another piece of software hosted on Launchpad), and convince other people to follow a suitable search link, then you could cause that code to be executed in other users’ browsers.
The fix was, of course, to simply escape the data returned by Bing Custom Search. Thanks to Mohamed Alaa for their disclosure.