Miggo Logo

CVE-2025-59526: Mailgen: HTML injection vulnerability in plaintext e-mails

5.3

CVSS Score
3.1

Basic Information

EPSS Score
0.14181%
Published
9/22/2025
Updated
9/23/2025
KEV Status
No
Technology
TechnologyJavaScript

Technical Details

CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N
Package NameEcosystemVulnerable VersionsFirst Patched Version
mailgennpm< 2.0.302.0.30

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The analysis of the provided security advisory and the associated commit 741a019 clearly pinpoints the Mailgen.prototype.generatePlaintext function as the source of the HTML injection vulnerability. The patch directly modifies a regular expression within this function to correctly strip HTML tags that contain newlines, which was the root cause of the vulnerability. The provided PoC demonstrates how a crafted input with a <br> tag can bypass the original, flawed regex. Therefore, any runtime profile during the exploitation of this vulnerability would show Mailgen.generatePlaintext as the function processing the malicious input.

Vulnerable functions

Mailgen.generatePlaintext
index.js
The vulnerability lies in the order of operations and an incomplete regex for stripping HTML tags. The function first replaces `<br>` tags with newlines. A subsequent regex, `/<.+?>/g`, is used to strip HTML tags, but the dot (`.`) in this regex does not match newline characters. An attacker can inject a payload like `<img<br> src=xyz onerror=alert(1)>`. The `<br>` is converted to a newline, resulting in the string `<img\n src=xyz onerror=alert(1)>`. The regex fails to match and remove this malformed tag, leading to HTML injection in the plaintext email.

WAF Protection Rules

WAF Rule

# *TML Inj**tion *n* XSS *ilt*r *yp*ss in Pl*int*xt *m*ils ### Summ*ry *n *TML inj**tion vuln*r**ility in pl*int*xt *m*ils **n*r*t** *y M*il**n **s ***n *is*ov*r**. Your proj**t is *****t** i* you us* t** `M*il**n.**n*r*t*Pl*int*xt(*m*il);` m*t*o* *

Reasoning

T** *n*lysis o* t** provi*** s**urity **visory *n* t** *sso*i*t** *ommit `*******` *l**rly pinpoints t** `M*il**n.prototyp*.**n*r*t*Pl*int*xt` *un*tion *s t** sour** o* t** *TML inj**tion vuln*r**ility. T** p*t** *ir**tly mo*i*i*s * r**ul*r *xpr*ssio