CVE-2025-62366: Mailgen Cross-Site Scripting Vulnerability
LOWCVE-2025-62366 is a LOW cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Mailgen libraries in the npm ecosystem. The issue involves mailgen has html injection and xss filter bypass in plaintext emails. Remediation is available by upgrading affected packages to version 2.0.31.
CVE-2025-62366 at a Glance
How to Fix CVE-2025-62366
To remediate this vulnerability, upgrade all affected Mailgen dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install mailgen@2.0.31
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls mailgen
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2025-62366, inspect your project dependencies using npm:
npm ls mailgen
Analyze the terminal output to locate any version of Mailgen in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.31), your application is affected.
Note: The npm ls mailgen command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Mailgen, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2025-62366 Affected Mailgen Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
mailgen
|
npm |
< 2.0.31
|
2.0.31
|
References
Frequently Asked Questions
What is CVE-2025-62366?
Which Mailgen versions are affected?
What version fixes CVE-2025-62366?
Is mailgen affected?
What CWE is associated with CVE-2025-62366?
How can I check npm dependencies for CVE-2025-62366?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-xw6r-chmh-vpmj",
"modified" : "2025-10-14T19:49:56Z",
"published" : "2025-10-14T19:49:56Z",
"aliases" : [ "CVE-2025-62366" ],
"summary" : "Mailgen has HTML Injection and XSS Filter Bypass in Plaintext Emails",
"details" : "### Summary\n\nAn HTML injection vulnerability in plaintext emails generated by Mailgen has been discovered. Your project is affected if you use the `Mailgen.generatePlaintext(email)` method and pass in user-generated content. The issue was discovered and reported by Edoardo Ottavianelli (@edoardottt).\n\n### Details\n\nThe following function (inside index.js) is intended to strip all HTML content to produce a plaintext string.\n\n```javascript\n// Plaintext text e-mail generator\nMailgen.prototype.generatePlaintext = function (params) {\n // Plaintext theme not cached?\n if (!this.cachedPlaintextTheme) {\n throw new Error('An error was encountered while loading the plaintext theme.');\n }\n \n // Parse email params and get back an object with data to inject\n var ejsParams = this.parseParams(params);\n\n // Render the plaintext theme with ejs, injecting the data accordingly\n var output = ejs.render(this.cachedPlaintextTheme, ejsParams);\n\n // Definition of the <br /> tag as a regex pattern\n var breakTag = /(?:\\<br\\s*\\/?\\>)/g;\n var breakTagPattern = new RegExp(breakTag);\n\n // Check the plaintext for html break tag, maintains backwards compatiblity\n if (breakTagPattern.test(this.cachedPlaintextTheme)) {\n // Strip all linebreaks from the rendered plaintext\n output = output.replace(/(?:\\r\\n|\\r|\\n)/g, '');\n\n // Replace html break tags with linebreaks\n output = output.replace(breakTag, '\\n');\n\n // Remove plaintext theme indentation (tabs or spaces in the beginning of each line)\n output = output.replace(/^(?: |\\t)*/gm, \"\");\n }\n\n // Strip all HTML tags from plaintext output\n output = output.replace(/<.+?>/g, '');\n\n // Decode HTML entities such as ©\n output = he.decode(output);\n\n // All done!\n return output;\n};\n```\nThe process fails because it searches for HTML tags and attempts to strip them from the input. However, if the HTML tags are encoded, they are not removed. These encoded tags are then decoded later and become valid HTML content, which can lead to XSS vulnerabilities.\n\nA valid payload is: `<img src=xyz onerror=alert(1)>`.\n\n### PoC\n\n```javascript\nvar Mailgen = require('mailgen');\n\n// Configure mailgen by setting a theme and your product info\nvar mailGenerator = new Mailgen({\n theme: 'default',\n product: {\n // Appears in header & footer of e-mails\n name: 'Mailgen',\n link: 'https://mailgen.js/'\n // Optional product logo\n // logo: 'https://mailgen.js/img/logo.png'\n }\n});\n\nvar email = {\n body: {\n name: 'John <img src=x onerror=alert(document.body.innerHTML)> Appleseed',\n intro: 'Welcome to Mailgen! We\\'re very excited to have you on board.',\n action: {\n instructions: 'To get started with Mailgen, please click here:',\n button: {\n color: '#22BC66', // Optional action button color\n text: 'Confirm your account',\n link: 'secret-link'\n }\n },\n outro: 'Need help, or have questions? Just reply to this email, we\\'d love to help.'\n }\n};\n\nvar emailText = mailGenerator.generatePlaintext(email);\nrequire('fs').writeFileSync('emailText.html', emailText, 'utf8');\n```\n\n**Resulting output file (emailText.html)**:\n\n```HTML\nHi John <img src=x onerror=alert(document.body.innerHTML)> Appleseed,\n\nWelcome to Mailgen! We're very excited to have you on board. \n\nTo get started with Mailgen, please click here: \nsecret-link \n\nNeed help, or have questions? Just reply to this email, we'd love to help. \n\nYours truly, \nMailgen\n\n© 2025 Mailgen. All rights reserved.\n```\n\n### Impact\n\nDepending on the context/environment where the plaintext message is used, if HTML is rendered and executed can result in arbitrary code execution in the browser of the victim (potentially stealing secrets or sensitive information contained in the message).\n\n### Credits\n\nEdoardo Ottavianelli (@edoardottt)",
"severity" : [ {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N/E:P"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "mailgen"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "2.0.31"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 2.0.30"
}
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/eladnava/mailgen/security/advisories/GHSA-xw6r-chmh-vpmj"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-62366"
}, {
"type" : "WEB",
"url" : "https://github.com/eladnava/mailgen/commit/7279a983481d05c51aa451e86146f98aaa42fee9"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/eladnava/mailgen"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-79" ],
"severity" : "LOW",
"github_reviewed" : true,
"github_reviewed_at" : "2025-10-14T19:49:56Z",
"nvd_published_at" : "2025-10-14T16:15:42Z"
}
}