使用内容安全策略>插件类型在chrome中打开嵌入iframe的PDF

yr9zkbsy  于 2023-03-10  发布在  Go
关注(0)|答案(2)|浏览(228)

我有CSP(内容安全策略)插件类型策略设置为白名单PDF类型如下.当试图打开一个PDF文件在iframe与src属性,它是工作良好的浏览器IE 11,和Firefox 47+,但在Chrome 50+失败.还有什么是必要的,使其在Chrome中工作?

Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; object-src 'self'; style-src 'self'; frame-src 'self' plugin-types application/pdf;

chrome控制台出错

Resource interpreted as Document but transferred with MIME type application/pdf
Refused to load 'http://127.0.0.1/module123/open.do?id=10000' (MIME type '') because it violates the following Content Security Policy Directive: 'plugin-types application/pdf'. When enforcing the 'plugin-types' directive, the plugin's media type must be explicitly declared with a 'type' attribute on the containing element (e.g. '<object type="[TYPE GOES HERE]" ...>').
k3fezbri

k3fezbri1#

我也有类似的问题。
要解决这个问题,我需要添加blob:添加到object-src指令。
而且,我不需要指定插件类型。
所以它应该是:
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; object-src 'self' blob:; style-src 'self'; frame-src 'self';

lmvvr0a8

lmvvr0a82#

添加blob:对我来说并没有起到作用,但以下代码起到了作用:

frame-src data:;

相关问题