Is It Possible to Sandbox JavaScript Running In the Browser?

前端 未结 15 638
北海茫月
北海茫月 2020-11-22 13:58

I\'m wondering if it\'s possible to sandbox JavaScript running in the browser to prevent access to features that are normally available to JavaScript code running in an HTML

相关标签:
15条回答
  • 2020-11-22 14:37

    As of 2019, vm2 looks like the most popular and most regularly-updated solution to running JavaScript in Node.js. I'm not aware of a front-end solution.

    0 讨论(0)
  • 2020-11-22 14:38

    Google Caja is a source-to-source translator that "allows you to put untrusted third-party HTML and JavaScript inline in your page and still be secure."

    0 讨论(0)
  • 2020-11-22 14:43

    Have a look at Douglas Crockford's ADsafe:

    ADsafe makes it safe to put guest code (such as third party scripted advertising or widgets) on any web page. ADsafe defines a subset of JavaScript that is powerful enough to allow guest code to perform valuable interactions, while at the same time preventing malicious or accidental damage or intrusion. The ADsafe subset can be verified mechanically by tools like JSLint so that no human inspection is necessary to review guest code for safety. The ADsafe subset also enforces good coding practices, increasing the likelihood that guest code will run correctly.

    You can see an example of how to use ADsafe by looking at the template.html and template.js files in the project's GitHub repository.

    0 讨论(0)
提交回复
热议问题