# CVE-2025-59526: Mailgen HTML injection vulnerability in plaintext emails

Source: https://junglewise.ai/threats/cve-2025-59526-mailgen-html-injection-vulnerability-in-plaintext-emails  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2025-09-22. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2025-59526 · Severity: low · CVSS 3.1 · Published 2025-09-22

Mailgen is a popular Node.js library for generating transactional emails in both HTML and plaintext formats. A flaw in the plaintext email generator allows attackers to inject HTML code and bypass filters when user-controlled content is processed, potentially enabling malicious scripts to be embedded in plaintext emails.

Technologies: [mailgen (npm)](https://junglewise.ai/threats/technologies/mailgen). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2025-59526 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2025-59526 being exploited in the wild.

**How severe is CVE-2025-59526?** Low severity, with a CVSS score of 3.1, published 22 September 2025.

**Which products and versions are affected?** mailgen (npm) SEMVER:introduced=0,fixed=2.0.30.

**Is there a fix for CVE-2025-59526?** Yes. mailgen (npm): upgrade to 2.0.30 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2025-59526 attacked?** It is attacked over the network.

**Am I affected by CVE-2025-59526?** Check whether you run mailgen (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- mailgen (npm): upgrade to 2.0.30 or later

  ```sh
  npm install mailgen@2.0.30
  ```


## Technical details

The vulnerability is an HTML injection flaw in the generatePlaintext() function caused by incorrect filter ordering. The code first converts HTML break tags to newlines, then attempts to strip all HTML tags with a regex. By nesting an HTML tag inside a break tag (e.g., &lt;img&lt;br&gt; src=xyz onerror=alert(1)&gt;), attackers can bypass the HTML tag removal regex. The vulnerability requires the application to pass user-generated content directly to generatePlaintext() without prior sanitization. An attacker can inject JavaScript payloads that execute in email clients supporting HTML rendering. The issue was patched in version 2.0.30 (commit 741a019).

## Affected products

- Mailgen Mailgen < 2.0.30

## Identifiers

- CVE-2025-59526
- GHSA-j2xj-h7w5-r7vp

## Timeline

- 2025-09-22: disclosed
- 2025-09-22: patched: Version 2.0.30 released to npm

## References

- [https://github.com/eladnava/mailgen/security/advisories/GHSA-j2xj-h7w5-r7vp](https://github.com/eladnava/mailgen/security/advisories/GHSA-j2xj-h7w5-r7vp)

## Related threats

- [Mailgen HTML injection and XSS filter bypass in plaintext emails](https://junglewise.ai/threats/cve-2025-62380-mailgen-html-injection-and-xss-filter-bypass-in-plaintext-emails)
- [Mailgen HTML injection and XSS filter bypass in plaintext emails](https://junglewise.ai/threats/cve-2025-62366-mailgen-html-injection-and-xss-filter-bypass-in-plaintext-emails)
