I'm making a web application that needs to use logical statements written by the administrators. These will originally be stored in a database on the server, but will be loaded and evaluated client side.
var success = false;
var apples = 15;
eval (logic_from_server);
// where logic_from_server might be "success = apples > 10";
My question is now, could eval
be exploited even though the string comes from the server and is never changed by another user. Could someone open the Chrome console and change the value of apples to a string which then executes some xmlHttpRequest
and retrieves information from the server?
I.e. are the permissions granted to the eval()
in my code different from what is granted to the Chrome console itself, so some code run through eval would be able to do more harm than code run directly in the console?
I mean, I could just type into the console "eval ('some evil code')" - is this different than modifying the string sent to the eval which is originally embedded in my code?
Are there any other security risks with using eval for the purpose I describe above?
[EDIT]
Adding after first 2 answers just to be completely clear:
I read in many places that you should never use eval()
on user submitted text. But a user with bad intentions could easily submit text to my eval()
by going to Chrome console and type apples = "false; {..INSERT_EVIL_CODE..} ;apples ";
. So my question is - is this any more harmful than typing the EVIL_CODE
directly into the console of chrome?