Skip to content
XSS Write-up Advanced

Re-moo-te Code Execution in Mailcow: Always Sanitize Error Messages

Mailcow's admin panel had an XSS flaw where exception details, including attacker-controlled function arguments, were rendered without HTML escaping, and a path traversal flaw where a validation bypass allowed overwriting compiled Twig template files. An attacker could combine these to execute arbitrary code on the admin panel server when an admin views a malicious email.

Paul Gerste Follow

Published on sonarsource.com

Mailcow is an easy-to-use email solution that can be set up in minutes. It features SMTP, IMAP, and POP3 servers, a webmail client, an admin panel, and more.

Paul Gerste, on sonarsource.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.

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

Likely the combination of unescaped exception output in a notification library and a validation loop that continued instead of aborting on invalid input, allowing path traversal.

What the attacker needed

Admin logged into admin panel; admin views malicious email; no link click required

The fix

The XSS was fixed by encoding HTML special characters in exception details, and the path traversal was fixed by correcting the validation logic to enforce an allowlist; additional hardening with Sec-Fetch-Dest header checks was added.

How it was found

  1. Craft an HTML email with a CSS background image pointing to the API endpoint with a malicious query parameter.
  2. The admin views the email in the webmail client, causing the browser to load the background image and send the request.
  3. The API request triggers an exception that includes the attacker-controlled argument, which is stored in the session.
  4. The next time the admin loads a page, the stored exception is rendered without escaping, executing the XSS payload.
  5. Using the XSS, the attacker sends a request to the vulnerable rspamd_maps function with a path traversal payload to overwrite a compiled Twig template file.
  6. The attacker requests the page that uses the overwritten template, executing the malicious PHP code.

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.

This report describes two bugs in mailcow, an email server with a web admin panel. One bug let an attacker sneak JavaScript into the admin's browser by sending a crafted email; the other let them overwrite a file on the server. Together, these allowed running commands on the server, but only if an admin was logged in and viewed the email.

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 Paul Gerste

View all

7 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.