Introduction
I'm currently working on a project called draw.js. The idea behind the project is to have an online code editor linked to a drawing space so you can draw using code.
I got this idea when I first discovered the two.js library. I wanted to get started drawing right away but couldn't since I had to set up files etc. first. Setting up the files once and hosting it online with the code editor right there next to it made it much easier to get started and on top of that, I could do it from anywhere I wanted (school, home etc.) without having something like a usb stick handy.
Having the code editor right there also made getting the results much quicker. So only big plus points there.
I had to figure out a way to actually run the code I put into the code editor part of my web-app. I did some research online and found out the easiest solution would be to take the code, put the string in a variable and then pass the variable into the eval() function built into java-script.
My problem
This solution works flawlessly and it was super easy to set up. However, research online, along with common sense tells me that this is a really insecure solution.
You can basically put in any valid js and it will run.
Now this is a problem for stuff like $("body").html("");
but this is not the end of the world. Editing the html like that is powerful, but only client side. You can practically do this by opening your dev tools in chrome.
My question
I wasn't able to think of any serious problems with this security flaw myself. However I'm not really a specialist in this field. That's why I'm asking this question.
Are there any real dangers when using eval() in this way? WHAT ARE THOSE DANGERS?
If there are any...
Is there a way to fix this hole in security? Perhaps only allowing access to certain library's?
If there is a way to fix this, please tell me how I would go about fixing it?