I have an html page with a textfield for the user to put expressions like these:
(x+23)*2
((x-y)*(x+y))
x*2/z+y
The user enters them and I use the ‘eval’ method to execute them.
Before calling eval I make a check that there is nothing dodgy (like attempting to define a function or similar).
It seems to me that I should be fine.
But am I introducing a security hole because I call ‘eval’ on user’s string.
what’s the risk ?
All the user can do is to evaluate stuff in the scope of this page.
If the user types in horrible script, what can it do to anyone except the user him/herself?
There is nothing the user can eval in that field that could not also be put in the location bar as a bookmarklet – all is run in the scope of the client browser.