CVE-2024-28243: KaTeX maxExpand bypass via \edef token expansion

CVE-2024-28243 · Severity: low · CVSS 3.1 · Published 2024-03-25

KaTeX is a popular JavaScript library for rendering mathematical expressions. Attackers can craft malicious mathematical expressions using the \edef command that cause the library to enter a near-infinite loop and consume excessive memory, despite the maxExpand safety limit being configured. This can render a web application unresponsive, disrupting service for all users viewing the affected content.

Technologies: katex (npm). Vendors: npm.

Quick answers

Is CVE-2024-28243 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2024-28243 being exploited in the wild.
How severe is CVE-2024-28243?
Low severity, with a CVSS score of 3.1, published 25 March 2024.
Which products and versions are affected?
katex (npm) SEMVER:introduced=0.12.0,fixed=0.16.10.
Is there a fix for CVE-2024-28243?
Yes. katex (npm): upgrade to 0.16.10 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2024-28243 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2024-28243?
Check whether you run katex (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

  • katex (npm): upgrade to 0.16.10 or later
    npm install katex@0.16.10

Technical details

KaTeX implements a maxExpand option to prevent infinite recursion in macro expansion from consuming all memory and causing stack overflow. The vulnerability exists because maxExpand counts "a single macro expanding to any number of tokens" as one expansion unit. The \edef (expand-and-define) TeX command can exponentially multiply tokens using only a linear number of expansions—for example, by repeatedly doubling a definition. An attacker providing untrusted mathematical expressions can exploit this to bypass maxExpand protection, causing denial of service via memory overflow, main thread blocking, or stack overflow. The vulnerability requires the attacker to be able to supply rendering input to a KaTeX instance. The fix, released in KaTeX v0.16.10, counts every expanded token within \edef as a separate expansion against the maxExpand limit.

Affected products

  • KaTeX KaTeX >= v0.10.0-beta, < 0.16.10

Identifiers

  • CVE-2024-28243
  • GHSA-64fm-8hw2-v72w

Timeline

  • 2024-03-25: disclosed: GHSA-64fm-8hw2-v72w published
  • 2024-03-25: patched: KaTeX v0.16.10 released with fix

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.