Answer the question
In order to leave comments, you need to log in
How to check the security of user code before executing in eval?
It is necessary to provide users of the online service with the ability to create formulas (arithmetic and logical operations, branching, variables are allowed).
To solve the problem, I suppose to run user code through eval, after checking for prohibited functions and expressions. We wrote the following regular expression to search for forbidden constructs in the code:
'/[^$\w]([a-zA-Z][\w_]+)|(\$this)/i'
Is such a check sufficient for the safety of running user code ? Maybe there are better solutions to the problem?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question