Skip to content
XSS Write-up Intermediate

Stealing passwords from infosec Mastodon without bypassing CSP

An HTML injection vulnerability in the Glitch fork of Mastodon allowed an attacker to inject arbitrary HTML into a post, which could spoof a login form and steal credentials via Chrome autofill without bypassing CSP. The attacker could also make the attack wormable by re-posting the vector.

Gareth Heyes Follow

Published on portswigger.net

Everybody on our Twitter feed seemed to be jumping ship to the infosec.exchange Mastodon server, so I decided to see what the fuss was all about. After figuring out why exactly you had to have loads of @ symbols in your username, I began to have a look at how secure it was.

Gareth Heyes (@garethheyes), on portswigger.net

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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The HTML sanitiser failed to properly handle the expansion of the :verified: emoji inside an attribute, allowing an attacker to break out of the attribute and inject arbitrary HTML.

Impact

An attacker could steal credentials from users of the affected Mastodon instance, and the attack could be wormable by re-posting the vector.

What the attacker needed

Victim uses Chrome with autofill enabled; victim views the malicious post; attacker can post HTML (enabled in preferences)

The fix

The issue was fixed in Mastodon 4.0.1, 3.5.5, and 3.4.10, and the Glitch fork was patched to fix replacement of placeholders such as :verified:.

How it was found

  1. Enable HTML posting in preferences.
  2. Post a message containing an abbr tag with a title attribute that includes an anchor with the :verified: emoji and an iframe.
  3. Observe that the filter is bypassed and arbitrary HTML is injected.
  4. Inject a form with username and password inputs, styled to be invisible using a CSS class with opacity:0.
  5. Spoof the toolbar with buttons to make the form look legitimate.
  6. When a victim views the post, Chrome autofills the credentials and the attacker can steal them.

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 write-up has not been written yet. The Original tab links to the source.

The website allowed users to post HTML, but tried to filter out dangerous tags. The filter could be tricked by using a special emoji that expanded into an image tag, breaking out of an attribute and letting the attacker insert any HTML. The attacker then created a fake login form that looked like part of the site, and the browser's password manager automatically filled in the victim's username and password, which were sent to the attacker's server.

What is XSS?

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

More by Gareth Heyes

View all

15 more disclosed reports, best first.

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.