How to run javascript inside browser safely and securely? [duplicate]

落花浮王杯 提交于 2019-12-08 01:03:37

问题


I need to eval() the code inside my page because I am working on something jsFiddle-like. Since eval has such a bad reputation, how can I interpret the user input code safely and securely? Or as safely and securely as possible?


回答1:


I would suggest you have a look at the following resources:

  • https://code.google.com/p/jsreg/
  • https://www.owasp.org/index.php/OWASP_JavaScript_Sandboxes
  • http://www.thespanner.co.uk/2012/10/18/mentaljs-sandboxparser/

Anyway, you should consider running the code that's coming from untrusted users/sources on another domain than where your main site/content is located.



来源:https://stackoverflow.com/questions/21408343/how-to-run-javascript-inside-browser-safely-and-securely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!