OpenCut/apps/web
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
..
content/changelog feat: add published status to changelog entries 2026-03-29 15:58:46 +02:00
migrations chore: normalize line endings 2026-03-29 15:56:48 +02:00
public chore: remove accidentally committed Zone.Identifier stream 2026-03-29 18:25:43 +02:00
scripts chore: normalize line endings 2026-03-29 15:56:48 +02:00
src fix(security): replace new Function() with safe math expression parser (#753) 2026-03-29 18:27:05 +02:00
.env.example chore: normalize line endings 2026-03-29 15:56:48 +02:00
.gitignore chore: normalize line endings 2026-03-29 15:56:48 +02:00
Dockerfile refactor: move packages sub-folders into web app 2026-03-29 15:58:46 +02:00
components.json chore: normalize line endings 2026-03-29 15:56:48 +02:00
content-collections.ts feat: add published status to changelog entries 2026-03-29 15:58:46 +02:00
drizzle.config.ts refactor: move packages sub-folders into web app 2026-03-29 15:58:46 +02:00
next-env.d.ts feat: add shared Rust crates for cross-platform time utilities 2026-03-29 15:58:46 +02:00
next.config.ts chore: normalize line endings 2026-03-29 15:56:48 +02:00
open-next.config.ts chore: add missing open-next config 2026-03-29 15:58:46 +02:00
package.json refactor: move packages sub-folders into web app 2026-03-29 15:58:46 +02:00
postcss.config.mjs feat: masks, properties refactor, shaders, storage migrations, and more 2026-03-29 15:48:22 +02:00
tsconfig.json chore: normalize line endings 2026-03-29 15:56:48 +02:00
tsconfig.tsbuildinfo feat: masks, properties refactor, shaders, storage migrations, and more 2026-03-29 15:48:22 +02:00
wrangler.jsonc chore: normalize line endings 2026-03-29 15:56:48 +02:00