Are web workers a secure way to sandbox untrusted javascript code

≯℡__Kan透↙ 提交于 2019-12-03 06:50:55
asvd

DOM is not available to the Web-workers, but it is possible to access same-origin stuff, like indexedDB. See my related question on this:

Can workers be secure enough for an untrusted code

The secure way is to use sandbox attribute of the iframe:

http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/

Also take a look at my library which simplifies the process and provides the convenient connection with the sandbox (function export instead of messaging):

https://github.com/asvd/jailed

The problem with that is if the developers expect DOM access. Web Workers aren't allowed to handle DOM, unless the entire code is for data only.

I suggest you sandbox the entire app from the main domain, similar to how JSFiddle runs everything in iframes. That way, all potentially hazardous code can only work in that frame while all other things, like logins, are handled outside the frame, in the main domain away from the potentially dangerous code.

Best of all, just include safe code. Review the code before merging it in your main app.

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