Unchecked Input for Loop Condition Affecting katex package, versions >=0.15.4 <0.16.10


0.0
medium

Snyk CVSS

    Attack Complexity Low
    Availability High

    Threat Intelligence

    EPSS 0.04% (9th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk ID SNYK-JS-KATEX-6483836
  • published 26 Mar 2024
  • disclosed 25 Mar 2024
  • credit Juho Nurminen

How to fix?

Upgrade katex to version 0.16.10 or higher.

Overview

katex is a Fast math typesetting for the web.

Affected versions of this package are vulnerable to Unchecked Input for Loop Condition when handling \def or \newcommand in conjunction with Unicode sub/superscripts. An attacker can cause a near-infinite loop, leading to memory overflow, tying up the main thread, or stack overflow, by exploiting the maxExpand option which fails to limit macro executions effectively.

Note:

This vulnerability is particularly concerning when rendering untrusted mathematical expressions, as it can be used for an availability attack, rendering the service unusable.

Workaround

This vulnerability can be mitigated by forbidding inputs containing any of the characters \u208a\u208b\u208c\u208d\u208e\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089\u2090\u2091\u2095\u1d62\u2c7c\u2096\u2097\u2098\u2099\u2092\u209a\u1d63\u209b\u209c\u1d64\u1d65\u2093\u1d66\u1d67\u1d68\u1d69\u1d6a\u207a\u207b\u207c\u207d\u207e\u2070\u00b9\u00b2\u00b3\u2074\u2075\u2076\u2077\u2078\u2079\u1d43\u1d47\u1d9c\u1d48\u1d49\u1d4d\u02b0\u2071\u02b2\u1d4f\u02e1\u1d50\u207f\u1d52\u1d56\u02b3\u02e2\u1d57\u1d58\u02b7\u02e3\u02b8\u1dbb\u1d5b\u1d5d\u1d5e\u1d5f\u1d60\u1d61 before passing them to KaTeX.

References