是的,关于CSP不能加载base64映像的另一个问题是我已经研究了很多并且找不到解决方案。我已经尝试了所有已建立的配置,但仍然无法使用。
因此,我正在尝试通过Javascript加载Base64图像。
var dataString = jQuery('#signature').jSignature('getData');
JQuery('#sig').append("<img class='imported' src='" + dataString + "'></img>");
如您所见,追加base64映像没什么大不了的(在localhost中,它可以工作)。
然后,在搜索CSP时,我发现避免使用带有Base64映像的CSP的正确配置是(这就是我的配置方式):
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data:; font-src 'self' data:";
我对base64字体没有问题,但是对于图像,它总是会引发此错误:
Refused to load the image 'data:image/png;base64,...' because it violates the following Content Security Policy directive: "default-src *". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.
任何想法都会受到赞赏,我真的不知道发生了什么。