javascript - 对于不受信任的代码,工作人员是否足够安全

标签 javascript security iframe sandbox

我有一个用户提交的不受信任的代码,我需要在浏览器的沙盒环境中执行它。

我被告知 Web-Workers 对此不够安全,最好使用沙盒化的 iframe。本页:

https://www.owasp.org/index.php/HTML5_Security_Cheat_Sheet#Web_Workers

还说 worker 不适合不受信任的代码。

但是如果我从 Blob 创建一个 worker,它的 url 甚至有一个不同的协议(protocol) (blob://)。在这种情况下,是否对 worker 代码应用了单独的来源政策?

如果有其他原因,为什么与沙盒 iframe(访问 IndexedDB 或其他东西)相比,worker(默认情况下)受到的限制更少,是否有机会以某种方式设置 worker 以使其受到足够的限制,还是我仍然应该使用沙盒 iframe?

最佳答案

Is separate origin policy applied to the worker code in this case?

不,来自 the current editor's draft of the File API specification :

The origin of a Blob URL must be the same as the effective script origin specified by the incumbent settings object at the time the method that created it -- either URL.createObjectURL or URL.createFor -- was called.


additional reasons, why a worker is (by default) less restricted comparing to the sandboxed iframe

沙盒 iframe 可以指定除跨源通信之外的一些权限。例如,您可以防止沙盒内容打开弹出窗口。尽管 Web Worker 目前没有 API 来做很多这样的事情。


is there any chance to set-up a worker somehow so that it would be restricted enough

网络 worker 没有任何安全机制。 Web 平台中还有其他工具用于隔离不受信任的代码,如您指出的沙盒 iframe。如果更好的话,您可以使用沙盒 iframe 创建网络 worker 。

关于javascript - 对于不受信任的代码,工作人员是否足够安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25964015/

相关文章:

Facebook 登录 - 如何在本地主机和生产环境中进行开发?

javascript - XHR跨域限制的目的是什么?

html - CSS 使 iframe 占据页面的其余高度?

javascript - 如何在 iframe 中打印特定内容

javascript - 单击链接提交表单模拟特定按钮

php - Html 组合框到数据库记录 ID

javascript - Chai-as-promised - 带有promise的expect总是转变成一个空对象

javascript - 使用 Crossfilter 和 D3 重绘直方图

c# - 使用 HTTPPOST 或不使用它的操作有什么区别

javascript - 如何在iframe中启动JavaScript函数在父页面中运行?