mathjs CVE-2026-40897
HIGHSeverity by source
AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
Network-reachable parser input with low complexity and no interaction yields total impact via arbitrary JS; PR:L reflects typical application-gated access to the evaluation feature rather than guaranteed anonymous exposure.
Primary rating from Vendor (https://github.com/josdejong/mathjs).
CVSS VectorVendor: https://github.com/josdejong/mathjs
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
Lifecycle Timeline
5Blast Radius
ecosystem impact- 24 npm packages depend on mathjs (5 direct, 20 indirect)
Ecosystem-wide dependent count for version 13.1.1.
DescriptionCVE.org
Impact
This security vulnerability allowed executing arbitrary JavaScript via the expression parser of mathjs. You can be affected when you have an application where users can evaluate arbitrary expressions using the mathjs expression parser.
Patches
The issue was introduced in mathjs v13.1.1, and patched in mathjs v15.2.0.
Workarounds
There is no workaround without upgrading to v15.2.0.
References
You can find out more via the commit fixing this issue: https://github.com/josdejong/mathjs/commit/513ab2a0e01004af91b31aada68fae8a821326ad (part of PR https://github.com/josdejong/mathjs/pull/3656).
AnalysisAI
Arbitrary JavaScript execution in the mathjs (npm) expression parser lets an attacker who can submit expressions escape the math sandbox and run code in the host JavaScript runtime. It affects mathjs versions >= 13.1.1 and < 15.2.0 and stems from an unsafe object/array property setter that failed to block dangerous properties. Publicly available exploit code exists (a proof-of-concept gist), but there is no evidence of active exploitation; EPSS is only 0.05% (16th percentile), consistent with the CISA SSVC exploitation status of 'none'.
Technical ContextAI
mathjs is a widely used JavaScript/TypeScript math library whose expression parser (math.evaluate / the compiled expression tree) is designed as a sandbox that safely evaluates user-supplied mathematical expressions. The root cause is CWE-915 (Improperly Controlled Modification of Dynamically-Determined Object Attributes). The GHSA advisory titles it an 'Unsafe object property setter': the internal getSafeProperty/setSafeProperty guards in src/utils/customs.js relied on a single isSafeProperty check that, for arrays, did not adequately restrict which property names could be read or written. The fix (PR #3656, commit 513ab2a) splits the check into isSafeObjectProperty (plain objects, rejecting anything present on Object.prototype) and a new isSafeArrayProperty that only permits numeric/integer indices and 'length', and adds an Array.isArray guard in stretch(). The affected package is identified by CPE pkg:npm/mathjs. Because mathjs runs in-process, escaping the expression sandbox yields execution in the surrounding Node.js/browser JavaScript context.
RemediationAI
Vendor-released patch: upgrade mathjs to v15.2.0 or later; the vendor explicitly states there is no workaround without upgrading. Apply the update via your package manager (for example, bump the mathjs dependency to ^15.2.0 and rebuild/redeploy), and check transitive dependencies since mathjs is frequently pulled in indirectly. If you cannot upgrade immediately, the only effective compensating control is to stop passing untrusted input to the parser: disable or gate any feature that lets end users submit arbitrary mathjs expressions, or restrict expression evaluation to trusted/authenticated operators only - accepting the trade-off that user-facing calculator/formula functionality is lost. Do not rely on string-based input filtering of expressions as a durable control, since the bypass operates through property-access semantics rather than obvious keywords. Advisory and fix references: https://github.com/josdejong/mathjs/security/advisories/GHSA-29qv-4j9f-fjw5, https://github.com/josdejong/mathjs/pull/3656, and the fixing commit https://github.com/josdejong/mathjs/commit/513ab2a0e01004af91b31aada68fae8a821326ad.
Same technique Information Disclosure
View allVendor StatusVendor
Share
External POC / Exploit Code
Leaving vuln.today
GHSA-29qv-4j9f-fjw5