Is It Possible to Sandbox JavaScript Running In the Browser?

前端 未结 15 940
北海茫月
北海茫月 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: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.

提交回复
热议问题