OpenCut/apps/web/src/utils
Rayan Salhab eb66e03f0e
fix(security): replace new Function() with safe math expression parser (#753)
* fix(security): replace new Function() with safe math expression parser

Replace the dangerous new Function() constructor in evaluateMathExpression()
with a recursive descent parser that safely evaluates basic arithmetic
expressions.

The Function constructor is a security anti-pattern that could enable
arbitrary code execution if the validation regex is ever bypassed or
relaxed. The new parser:

- Only supports numbers, +, -, *, /, parentheses, and whitespace
- Has no eval-like functionality that could execute arbitrary code
- Maintains backward compatibility with existing expressions
- Handles operator precedence and parentheses correctly

Fixes #725

* Apply suggestion from @coderabbitai[bot]

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Maze <167211895+mazeincoding@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-03-29 18:27:05 +02:00
..
__tests__ fix(security): replace new Function() with safe math expression parser (#753) 2026-03-29 18:27:05 +02:00
browser.ts feat: masks, properties refactor, shaders, storage migrations, and more 2026-03-29 15:48:22 +02:00
color.ts chore: normalize line endings 2026-03-29 15:56:48 +02:00
date.ts codebase overhaul (#697) 2026-01-31 00:20:04 +01:00
geometry.ts codebase overhaul (#697) 2026-01-31 00:20:04 +01:00
id.ts chore: normalize line endings 2026-03-29 15:56:48 +02:00
math.ts fix(security): replace new Function() with safe math expression parser (#753) 2026-03-29 18:27:05 +02:00
platform.ts codebase overhaul (#697) 2026-01-31 00:20:04 +01:00
string.ts codebase overhaul (#697) 2026-01-31 00:20:04 +01:00
ui.ts codebase overhaul (#697) 2026-01-31 00:20:04 +01:00