Why is eval unsafe in javascript? [duplicate]

The danger of eval only rears its ugly head when you are serving a script written by alice to user bob for bob’s browser to eval.

e.g. if bob enters his password on your page, alice could have written a keylogger in the user input you evaled and arrange for the data to be encoded in a script that bob will (unknowingly) submit to be served to alice. This is, as @Hunter2 has suggested in the comments, an XSS attack.

If you are not serving to other people, you are correct in assuming it is equivalent to firing up firebug

Leave a Comment