Content-Security-Policy object-src blob

若如初见. 提交于 2019-12-01 13:42:30

问题


When using a content-security-policy and I try to follow a process in Chrome 41 (beta) using window.URL.createObjectURL I get an error like the following:

Refused to load plugin data from 'blob:http%3A//localhost%3A7000/f59612b8-c760-43a4-98cd-fe2a44648393' because it violates the following Content Security Policy directive: "object-src blob://*"

With a content security policy that restricts object-src or otherwise default-src one can reproduce the issue (with jQuery for convenience) like this:

blob = new Blob(
   ["%PDF-1.\ntrailer<</Root<</Pages<</Kids[<</MediaBox[0 0 3 3]>>]>>>>>>"],
   { type: "application/pdf" })
$("<embed>").attr("src", window.URL.createObjectURL(blob))
  .appendTo(document.body)

It seems from the spec that this should work, as it does for data://*. I have tried also blob, blob:, blob:*, blob:http*, blob:http:*, blob:http://*, but to no avail.

What does work, but for apparent reasons is undesirable, is object-src *.

Has anyone had any success getting blobs to load with a content security policy? Is this a problem upstream, or have I overlooked something?


回答1:


The spec compliant answer is object-src 'self' blob:

blob: should only match blob: explicitly, and not 'self' or *. This is a bug in Chrome, and was recently fixed in Firefox 40.




回答2:


For Chrome 47.0.2526.73:

default-src * blob:;

worked for me



来源:https://stackoverflow.com/questions/28467789/content-security-policy-object-src-blob

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