plantain-00 / expression-engine

An expression tokenizer, parser and evaluator.
MIT License
8 stars 1 forks source link

Avoid common security risks #5

Closed OpportunityLiu closed 3 years ago

OpportunityLiu commented 3 years ago

Version(if relevant): 1.8.1

Environment(if relevant):

Code(if relevant):

import { tokenizeExpression, parseExpression, evaluateExpression, printExpression } from "expression-engine";

const tokens = tokenizeExpression(`(a => a).constructor("return this")().alert(12)`)
const ast = parseExpression(tokens)
const result = evaluateExpression(ast, { b: 2 })
const expression = printExpression(ast)

Expected:

Access to special members in the prototype chain should be avoided to prevent common attacks.

For reference: https://github.com/josdejong/mathjs/blob/47a493d70ac92daa47b26f9eea88513a7efa4408/src/utils/customs.js

plantain-00 commented 3 years ago

v1.8.2 should fix this