# CVE-2026-40897: Math.js: Unsafe object property setter in mathjs

> Attackers can execute arbitrary JavaScript via the mathjs expression parser if applications allow users to evaluate arbitrary expressions.

- **Severity:** High 8.8 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 24 Apr 2026
- **Updated:** 15 Jul 2026
- **Also known as:** GHSA-29qv-4j9f-fjw5

## What is CVE-2026-40897?

CVE-2026-40897 is a high-severity code injection vulnerability in josdejong mathjs, published on 24 Apr 2026. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

Math.js is an extensive math library for JavaScript and Node.js. From 13.1.1 to before 15.2.0, a 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. This vulnerability is fixed in 15.2.0.

Weakness: CWE-917 (Improper Neutralization of Special Elements used in an Expression Language Statement), CWE-915 (Improperly Controlled Modification of Dynamically-Determined Object Attributes)

## Which versions are affected by CVE-2026-40897?

2 open source packages ship an affected version, including mathjs. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `mathjs` | npm | From 13.1.1 | 15.2.0 |
| `mathjs` | npm | From 13.1.1 | 15.2.0 |

Products: Mathjs Mathjs.

## How do I fix CVE-2026-40897?

Upgrade mathjs to 15.2.0 or later.

## Is CVE-2026-40897 being exploited?

There is no known exploitation of CVE-2026-40897 in the wild and no public exploit code.

Public exploit code:

- Math.js Expression Parser RCE (github_poc): https://github.com/EQSTLab/CVE-2026-40897
- https://github.com/yym8538/CVE-2026-40897 (github_poc): https://github.com/yym8538/CVE-2026-40897

## Other vulnerabilities in josdejong mathjs

- [CVE-2026-41139](https://insights.sbomify.com/CVE-2026-41139/): Unsafe array index getter in mathjs (high 8.8)
- [CVE-2020-7743](https://insights.sbomify.com/CVE-2020-7743/): Prototype Pollution (high 7.3)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2026-40897 and fix it if it is affected.

What it is: CVE-2026-40897 is a high-severity code injection vulnerability in josdejong mathjs, published on 24 Apr 2026. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2026-40897 in the wild and no public exploit code.

Affected packages and fixed versions:
- mathjs (npm): affected from 13.1.1; fixed in 15.2.0
- mathjs (npm): affected from 13.1.1; fixed in 15.2.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2026-40897/ (Markdown: https://insights.sbomify.com/CVE-2026-40897/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2026-40897
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2026-40897
- OSV: https://osv.dev/vulnerability/CVE-2026-40897

---
From sbomify Insights: https://insights.sbomify.com/CVE-2026-40897/
Summaries are generated and may contain mistakes; the official description above is the record.
