Maybe you should give an example or two to make it easier to comprehend.
Let's say I'm putting a game on my server, and I want to have a leaderboard, so there's going to be some updating from client to server of high scores. If, apart from that plugin, I have NO other plugins, there is ONE place where we all know eval is used - in a damage formula. Can you give an example of how someone could do damage to the server, or to the client, through the damage formula's eval? How could they access what's currently about to be passed in to the command in order to change it from what the dev put in there?
Injection attacks is one thing. So lets say you are evaluating some code on the client that gets sent to the server, for damage formulas this isnt an issue because typically you would do all calculations and damage jazz client side and send back the resulting data to the server at the end of the battle or what have you.
But lets say you want to do something like: enemy hits, players HP is updated on the server (or something like that)
I can inject code into your eval statement at the right moment so that when you evaluate your javascript I can evaluate some of my own as well. eval will evaluate what ever code is passed at the programs permission level, that is who have has permission to run the code is what eval will use. So if you have some code that sets values all the time I can sneak my stuff in there and it will also execute. Lets say your sending some data back to server, ok, well while your there (heres my code) get me the visa numbers from your database and console.log them to my screen.
Now, after doing some reading, eval is also bad - because: when you are debugging you don't get line numbers in stack traces, so if an error is thrown and its code being evaluated, I wont know where to look for the error.
Eval also uses more memory then other ways. The main concern here is passing user input directly into eval because thats when I can latch on to what ever your doing and execute my own code to say get our visa cards, look inside your database or do what ever else. This is called code injection.
eval is also like goto, code debugging and maintenance becomes a nightmare when inexperienced developers use it all willy nilly.
So to reiterate:
- Code Injection via user input
- Code maintainability and debugging
- Reduces the confidence of security (again with user input)
- Performance issues can arise
Here is a good example, not so much a security issue but a scriptors nightmare:
// Lets say you have a function:function messageForPlayers(messageForPlayer) { eval(messageForPlayers)}var helloThere = messageForPlayers('Hello Player
😀');// So how does it get bad?var helloThere = messageForPlayers('function hahahaIamEvil() { ... }');// Uhoh ...// So how do we "fix this" - scope to the rescue:function messageForPlayers(messageForPlayer) { (function() { eval(messageForPlayers); })();}// Now its safe for the outer user because of the concept of scope.So what have we learned?
code injection === bad, scopes can help, performance is a nightmare, debuggabillity and code readability becomes a nightmare.