WarUI

Safe expression parser (no eval)

GRID-A13-F02P0baselinePlanned

Formulas are tokenized and parsed by a hand-written recursive-descent parser into an AST, which an interpreter then evaluates. The parser never uses eval, new Function or dynamic script injection, so it works under a strict Content-Security-Policy and cannot execute arbitrary JavaScript. The demo exposes the AST so developers can see how a formula is structured.

Planned. This page shows the specification from issue #192. The live example, source for every framework and the API reference replace it when the feature ships.

Live example

A formula input box with a live AST tree viewer next to it, showing =SUM(A1:A3)*2+IF(B1>0,1,-1). The page is served with a strict CSP header.

Expected behavior

Each keystroke updates the token list and AST tree. Malicious input such as =constructor.constructor('alert(1)')() produces a #NAME? or parse error and runs nothing. Input that exceeds maxAstDepth returns #ERROR! with a 'too complex' message.

Planned API surface

method: formulaEngine.parse(text)method: formulaEngine.validate(text)type: FormulaAstoption: formulas.maxFormulaLengthoption: formulas.maxAstDepth

Acceptance criteria

  • No eval, Function constructor or setTimeout with a string exists in the module (enforced by a lint rule and a CI grep). (pending)
  • The demo runs without CSP violations under script-src 'self'. (pending)
  • Property-access syntax, prototype names and JS identifiers are not resolved to JS objects. (pending)
  • Parse errors report a character offset and a message. (pending)
  • Expressions deeper than maxAstDepth are rejected without a stack overflow. (pending)