[英]how use CSP with pdf.js? I have a problem with worker
MVC c# application. MVC C# 应用程序。 I'm using CSP, with this format:我正在使用 CSP,格式如下:
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
script-src 'self' https://mozilla.github.io/pdf.js/build/pdf.js https://mozilla.github.io/pdf.js/build/pdf.worker.js;
style-src 'self' https://meyerweb.com/eric/tools/css/reset/reset.css;
object-src 'self';
base-uri 'self';
connect-src 'self';
font-src 'self';
frame-src 'self';
img-src 'self';
manifest-src 'self';
media-src 'self';
worker-src blob:;"/>
In the proyect, i use pdf.js for base64 pdfs.在项目中,我将pdf.js用于 base64 pdf。 I see my documents, but I dont see the buttons bar from pdf.js.我看到了我的文档,但我没有看到 pdf.js 中的按钮栏。 My browser console shows:我的浏览器控制台显示:
and my javascript function use:和我的 javascript 函数使用:
var DivContenedorPDF = document.createElement("div");
DivContenedorPDF.id = "pdf-viewer";
var pdfData = atob(b64);
var pdfjsLib = window['pdfjs-dist/build/pdf'];
pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';....
I tried add blob: in default-src, using local pdf.js (this has not errors but not work)...我尝试添加 blob: 在 default-src 中,使用本地 pdf.js(这没有错误但不起作用)...
extra info:额外信息:
thanks in advance!提前致谢!
尝试将 blob: 添加到 script-src。
Your browser console shown CSP:您的浏览器控制台显示 CSP:
default-src https: data: 'unsafe-inline' *.google.com
that differs you shown in the meta-tag:这与您在元标记中显示的不同:
default-src 'self'; ...
Looks like in fact you does issue Content-Security-Policy elsewhere than you think (and edit).看起来实际上您确实在您认为(和编辑)之外的其他地方发布了 Content-Security-Policy。
worker-src blob: in the meta-tag is totally enough to allow worker creation from blob-URL. worker-src blob:在元标记中完全足以允许从 blob-URL 创建工作线程。
@granty gave me the answer: the message in console isn't generic. @granty 给了我答案:控制台中的消息不是通用的。 I don't know why, but my IIS used another CSP configuration.我不知道为什么,但我的 IIS 使用了另一个 CSP 配置。 My code works deleting the configuration in response header section of IIS.我的代码可以删除 IIS 响应标头部分中的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.