CVE-2025-23207: KaTeX Vulnerability in \htmlData Attribute Validation
Summary
CVE-2025-23207: KaTeX \htmlData does not validate attribute names. Affects katex versions >= 0.12.0, < 0.16.21. Fixed in 0.16.21. How to fix ↓
Also tracked for
- node-katex · Debian:11
The same CVE-2025-23207 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
KaTeX is a popular open-source library used for rendering mathematical expressions in web applications. It provides a fast and efficient way to display complex equations and symbols using LaTeX syntax. However, it has a vulnerability related to the \htmlData command, which allows users to embed HTML directly into the rendered output. This feature, while powerful, can be exploited if not properly validated, leading to potential security risks.
Vulnerability Detail
The vulnerability arises from KaTeX's \htmlData command, which does not validate the attribute names provided to it. This oversight allows an attacker to inject arbitrary HTML or JavaScript into the rendered output, potentially leading to cross-site scripting (XSS) attacks or the generation of invalid HTML. Users who render untrusted mathematical expressions with the renderToString function are particularly at risk, as malicious input could execute scripts in the context of the user's browser.
How To Fix
Latest published version: 0.19.0 as of 22 Oct 2026
npm install katex@0.19.0
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
0.16.21
This is the first release that contains the fix.
npm install katex@0.16.21
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If upgrading is not immediately possible, consider the following workarounds: 1. Avoid using or disable the 'trust' option in KaTeX, or set it to forbid \htmlData commands. 2. Implement input validation to reject any inputs containing the substring '\htmlData'. 3. Sanitize the HTML output from KaTeX to remove any potentially harmful content.
Conclusion
The KaTeX vulnerability identified as CVE-2025-23207 poses a significant risk to applications that render untrusted mathematical expressions. By updating to version 0.16.21 or implementing the suggested workarounds, developers can protect their applications from potential exploitation. Regular monitoring for vulnerabilities using tools like Vulert is also recommended to maintain application security.
See every vulnerability recorded for katex →
FAQ
The vulnerability can lead to cross-site scripting (XSS) attacks, allowing attackers to execute arbitrary JavaScript in the context of the user's browser.
If your application uses KaTeX versions prior to 0.16.21 and renders untrusted mathematical expressions with the renderToString function, it may be affected.
Implement the suggested workarounds to mitigate the risk until you can upgrade to the patched version.
Yes, you can use Vulert to monitor and alert for open-source vulnerabilities in your software without needing to access the code or installation.
You can use the Vulert playground at Vulert Scanner to check if your application is affected by this vulnerability without any signup.
References
Related vulnerabilities
Recent vulnerabilities recorded for katex.