我正在尝试使用apache tomcat作为容器在本地部署一个web应用程序。我得到了一个简单的页面,在head部分如下:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<link rel="stylesheet" href="pure-min.css">
<link rel="stylesheet" href="styles.css">
<script src="app.js"></script>当我试图打开safari 14上的页面时,我得到了错误
Refused to load http://localhost:8080/webapp/app.js because it does not appear in the script-src directive of the Content Security Policy.我已经阅读了文档here,看起来'self‘足以加载我自己的资源(对于css和javascript)。我做错了什么?
谢谢
发布于 2021-02-07 09:14:45
这可能是两个问题:
'self'标记不覆盖Safari中的localhost:8080 (带端口号)。但在这种情况下,你应该另外有2个CSS被阻止,而不仅仅是js。要解决这个问题,只需在default-src指令中添加localhost:8080即可。
通过HTTP头发布默认的
检查是否发布了CSP HTTP标头,教程为here.
是否仅在Safari浏览器中观察到此错误?那Chrome/Firefox呢?
https://stackoverflow.com/questions/66077099
复制相似问题