XSS by MathML at Active Storage
Active Storage's list of binary formats did not include application/mathml+xml, so a file uploaded with the .mml extension was served as MathML rather than as a download. An attacker could upload a MathML file containing a javascript link and get a Firefox user to click it, running script in the site's origin.
- Triaged in 25 days
- Disclosed after 2.6 years
In Active Storage, formats treated as binary have been confirmed, It does not contain application/mathml+xml.
https://github.com/rails/rails/commit/d40284b1a44773b03d78ca67a888b94fd330d1b1
In Marcel::MimeType.for, if content-type can not be determined with magic byte, since it is determined using the extension, uploading the file with .mml will be judged as application/mathml+xml.
#https://github.com/minad/mimemagic/blob/master/lib/mimemagic/tables.rb#L387
'mml' => 'application/mathml+xml',
I confirmed that MathML XSS is executable in Mac Firefox 63. (https://html5sec.org/#130)
<math xmlns="http://www.w3.org/1998/Math/MathML" href="javascript:alert(location)">click page
</math>
Upload the above contents as math.mml, open the URL directly in Firefox and click in the screen to open an alert.
Impact
It will allow attacks against Firefox users.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the binary-format allowlist in Active Storage omitted application/mathml+xml, so Marcel fell back to the .mml extension and the file was served inline as active content.
Impact
Script could run in the site's origin for Firefox users who click the uploaded file; the report only claims this for Firefox.
What the attacker needed
Ability to upload a file; victim uses Firefox; victim clicks the file link
The fix
The binary-format list should include application/mathml+xml so such uploads are not treated as binary.
How it was found
- Create a MathML file containing a javascript link and name it with the .mml extension.
- Upload it to Active Storage.
- Open the file's URL directly in Firefox.
- Click on the page to trigger the script.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you upload a file, the server decides what type it is so it knows whether to show it in the browser or offer it as a download. Here a MathML file was treated as something the browser should display, and MathML can contain clickable links that run JavaScript. So a malicious upload could run code in the victim's browser when they clicked it.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.