CVE-2025-59526: Mailgen: HTML injection vulnerability in plaintext e-mails
5.3
CVSS Score
3.1
Basic Information
CVE ID
GHSA ID
EPSS Score
0.14181%
CWE
Published
9/22/2025
Updated
9/23/2025
KEV Status
No
Technology
JavaScript
Technical Details
CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N
| Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
|---|---|---|---|
| mailgen | npm | < 2.0.30 | 2.0.30 |
Vulnerability Intelligence
Miggo AI
Root 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.generatePlaintextindex.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.