How to set CSS for embedded PDF viewer with CSP enabled

生来就可爱ヽ(ⅴ<●) 提交于 2020-07-20 10:28:27

问题


I got the following problem: Having set

Content-Security-Policy style-src 'self' 

within .htacess file, chrome complains in the developer console when displaying PDF files linked like <a href="file.pdf">.

Refused to apply inline style because it violates the following
Content Security Policy directive: "style-src 'self'". Either the
'unsafe-inline' keyword, a hash ('sha256-[deleted]'), or a nonce
('nonce-...') is required to enable inline execution.

I can also see that chrome applies some css to the PDF display:

element.style {
background-color: rgb(38,38,38);
height: 100%;
width: 100%;
overflow: hidden;
margin: 0;
}

Of course, the easy way would be to just change the CSP settings in .htaccess to

Content-Security-Policy style-src 'self' 'unsafe-inline'

but that would damage security. Also I hesitate to give a hash to code I can not control. So the question is: How do I specify CSS code for PDF files I link to?

来源:https://stackoverflow.com/questions/49358335/how-to-set-css-for-embedded-pdf-viewer-with-csp-enabled

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