最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can workers be secure enough for an untrusted code - Stack Overflow

programmeradmin4浏览0评论

I have an untrusted code submitted by a user, and I need to execute it in a sandboxed environment in a browser.

I was advised that Web-Workers cannot be secure enough for that, and that a sandbxed iframe should better be used. This page:

.php/HTML5_Security_Cheat_Sheet#Web_Workers

also says workers are not suitable for untrusted code.

But if I create a worker from a Blob, its url even has a different protocol (blob://). Is separate origin policy applied to the worker code in this case?

If there are additional reasons, why a worker is (by default) less restricted paring to the sandboxed iframe (accesing IndexedDB or something else), is there any chance to set-up a worker somehow so that it would be restricted enough, or should I still use sandboxed iframe anyway?

I have an untrusted code submitted by a user, and I need to execute it in a sandboxed environment in a browser.

I was advised that Web-Workers cannot be secure enough for that, and that a sandbxed iframe should better be used. This page:

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

also says workers are not suitable for untrusted code.

But if I create a worker from a Blob, its url even has a different protocol (blob://). Is separate origin policy applied to the worker code in this case?

If there are additional reasons, why a worker is (by default) less restricted paring to the sandboxed iframe (accesing IndexedDB or something else), is there any chance to set-up a worker somehow so that it would be restricted enough, or should I still use sandboxed iframe anyway?

Share Improve this question asked Sep 21, 2014 at 21:24 asvdasvd 99411 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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

No, from 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 paring to the sandboxed iframe

Sandboxed iframes can specify some permissions on things other than cross-origin munication. For example, you can prevent the sandboxed content from opening popups. Although web workers currently don't have APIs to do many of these things.


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

There just isn't any security mechanism for web workers. There are other tools in the web platform for isolating untrusted code, like a sandboxed iframe as you point out. You could have a sandboxed iframe create a web worker, if that's any better.

发布评论

评论列表(0)

  1. 暂无评论