URI scheme bypass in mail app lead to HTML content spoof and opener control
The mail app's HTML sanitiser only rewrote http, https and cid URI schemes through its proxy, so an attacker could use ftp or relative URLs in src and href attributes to bypass the image filter and the Content-Security-Policy. Links also received target=_blank without rel=noopener, letting a linked page control the opener window and leak the victim's accountID.
Originally disclosed on HackerOne
- Triaged in under an hour
- Fixed in 2 months
- Disclosed after 3 months
Bug
When we load a HTML mail from mailbox via api, etc
http://nextcloud/index.php/apps/mail/accounts/<accountID>/folders/SU5CT1g=/messages/<mailID>/html
Our content will be passed to HTML Purifier to strip malicious XSS patterns.
After that, an filter will apply to transform acceptable URI schemes http, https, ftp, cid to redirect/proxy service.
There's a bug in here, only http, https, cid scheme are filtered.
So we can add src attribute or href from url with scheme ftp or NULL (like '../../abc/xyz') . We can easily bypass image filter (also Content-Security-Policy)
Notice that there's a filter that append target=_blank to all <a> tag. This can lead to opener bug [https://mathiasbynens.github.io/rel-noopener/#hax] (https://mathiasbynens.github.io/rel-noopener/#hax) that I learned from [124620] (https://hackerone.com/reports/124620).
And finally it can leak accountID of user
PoC
- Attacker create a shared link of a image
http://192.168.200.117/nextcloud/index.php/s/HUw7Cwa40Phlt8v/download
- Attacker start a ftp server and create a html page.
ftp://chim:chim@localhost/test.html
- Attacker send a HTML email
<h1>test schema</h1>
<p>
<a href="http://file.trich.im">Link via redirect</a><br>
<a href='ftp://chim:chim@localhost/hihi.html'>Bypass link</a>
</p>
<p>
Filtered img{{media:0}}<br>
Bypass img {{media:1}}
</p>
Video Demo https://www.youtube.com/watch?v=BdOD49gokdI
Attachments


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 URI scheme allow-list in the sanitiser was incomplete, and the target=_blank injection omitted rel=noopener.
Impact
An attacker could bypass the image filter and CSP to spoof HTML content and use the opener to leak the victim's accountID.
What the attacker needed
Attacker-controlled FTP server; victim opens crafted HTML email
How it was found
- Attacker creates a shared link to an image.
- Attacker runs an FTP server hosting an HTML page.
- Attacker sends an HTML email containing links and images using the ftp scheme or relative paths.
- Victim opens the email and the unfiltered content loads, and the new-tab link can control the opener.
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 open an HTML email, the app cleans it up so dangerous content cannot run. The cleaner only handled some kinds of links (http, https, cid) and missed others such as ftp or relative paths, so an attacker could sneak content past it. Separately, links opened in a new tab could reach back into the original page and read information from it.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.