/

CVE-2022-50908

Severity:

HIGH RISK

(7.2)

Stored XSS in MailHog Email Attachment Handling

CVE-2022-50908

Awaiting Analysis

Vulnerability type

Category:

Stored Cross-Site Scripting (XSS)

CWE:

CWE-79

Impact:

Arbitrary Web Actions via Victim's Browser (Potential Account/Session Abuse)

Severity:

HIGH RISK

(7.2)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

MailHog 1.0.1 is vulnerable to stored cross-site scripting when malicious scripts are injected via crafted email attachments and later rendered in the web interface.

When a victim user views these emails in the MailHog UI, attacker-controlled JavaScript can execute in the browser context, enabling arbitrary API calls such as message deletion and broader browser manipulation.

Affected context

This vulnerability occurs in MailHog's web-based message viewer where email attachments are rendered or previewed in the browser.

It primarily affects environments where:

  • MailHog's web UI is exposed to developers, testers, or administrators, and
  • User-supplied content from inbound emails (including attachments) is displayed without sufficient sanitization or output encoding.

Risk increases when MailHog is shared by multiple users or exposed beyond strictly isolated development setups.

Exploit preconditions

  • Attack surface: MailHog HTTP/web UI where emails and attachments are viewed.
  • Required access: Ability to send an email to the MailHog instance (e.g., access to any system configured to use MailHog as an SMTP relay).
  • Victim interaction: A user must open or preview the crafted email/attachment in the MailHog web interface.
  • Trigger point: The web UI renders attacker-controlled content from the attachment into the page DOM without proper output encoding, causing the script to execute.
  • Why exploitation is possible: The application treats attachment content as trusted HTML/markup and fails to enforce strict sanitization and context-aware escaping before rendering in the browser.

Why this happens

The underlying issue is that MailHog's message viewer reflects untrusted attachment content into HTML responses without robust output encoding or sanitization.

This matches CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), where user-controlled data is included in a web page and interpreted as active script.

Instead of strictly treating attachment content as inert data (e.g., downloading or displaying as text with correct escaping), the UI allows it to be interpreted by the browser as executable JavaScript, enabling stored XSS.

Potential impact

  • Execution of arbitrary JavaScript in the victim's browser while using the MailHog UI.
  • Unauthorized invocation of MailHog APIs (e.g., message deletion or modification) on behalf of the logged-in user or session.
  • Manipulation of the UI to hide or alter test emails and results.
  • Exfiltration of sensitive information displayed in the MailHog interface, such as message contents, headers, or metadata.
  • Use of the MailHog UI as a stepping stone to broader browser-based attacks (e.g., opening other internal URLs from the user's browser context, clickjacking-like flows, or phishing overlays).

General mitigation guidance

Effective mitigation focuses on treating all content originating from emails and attachments as untrusted input and ensuring it cannot execute as active script:

  • Apply strict output encoding for any user-controlled data rendered in HTML, including attachment names, previews, and inlined content.
  • Render attachments using safe, non-HTML representations where possible (e.g., force download, display as plain text, or encapsulate within iframes/sandboxes with no script execution).
  • Use well-vetted HTML sanitization libraries when HTML preview is required, configured to strip scripts, event handlers, and dangerous attributes.
  • Enforce Content Security Policy (CSP) to reduce impact of any residual injection by blocking inline scripts and limiting allowed script sources.
  • Follow a security-by-default UI design, where rich HTML previews are opt-in and plain-text views are the default for untrusted email content.
  • Limit the privileges of actions that can be triggered from the UI (e.g., require explicit user confirmation for destructive actions) to reduce the effect of automated API abuse via XSS.

How teams detect issues like this

Detection of similar XSS issues typically involves both code-level and behavior-level analysis:

  • Static analysis: Configure rules to flag direct insertion of email or attachment content into HTML templates, DOM sinks, or JavaScript contexts without explicit encoding functions.
  • Code review: Look for views or components that render email bodies or attachments as HTML; verify that they use context-aware escaping and, if applicable, robust sanitization.
  • Security testing: Use automated scanners or manual penetration tests to send crafted emails with XSS probes in attachments and observe whether scripts execute when viewed.
  • Policy enforcement: Introduce coding guidelines that mandate template helpers for all user-supplied content, disallow inline event handlers, and require documented decisions for any HTML rendering of untrusted data.
  • CI integration: Integrate SAST/DAST tools into the build pipeline to catch regressions where newly added views or previews expose unencoded email content.

Sources

SourceLink
github.comgithub.com/mailhog/MailHog
exploit-db.comexploit-db.com/exploits/50971
shodan.ioshodan.io/search?query=mailhog
vulncheck.comvulncheck.com/advisories/mailhog-stored-cross-site-scripting-xss

Frequently asked

questions

The exploit primarily targets users of the MailHog web interface. An attacker can be remote if they can cause emails to be delivered to MailHog, but the malicious JavaScript runs in the context of the victim's browser when they open the UI.

An attacker generally needs the ability to send or route emails to the MailHog instance. They do not need direct access to MailHog itself; however, a user with access to the web UI must view the crafted message or attachment for the attack to succeed.

The most robust fix is to ensure all email- and attachment-derived data is properly escaped before rendering, avoid executing or inlining untrusted HTML, and prefer plain-text or download-only handling of attachments by default.

Adopting a security-first templating approach—where all dynamic output is contextually escaped by default—combined with strict code review for any exceptions, the use of sanitization libraries for rich content, and enforcement of CSP can significantly reduce the likelihood of future XSS vulnerabilities.

Find out what's already
exploitable in your codebase.