本地资源的Content-Security-Policy



我正在尝试使用apache tomcat作为容器在本地部署web应用程序。我得到了一个简单的页面,在标题部分如下:

<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.

我在这里读过文档,它看起来像'self'将足以加载我自己的资源(css和javascript)。我做错了什么?

感谢

可以有两个问题:

  1. 'self'令牌在Safari中不覆盖localhost:8080(带端口号)。但在这种情况下,你应该有额外的2 CSS阻塞,而不是只有js。
    要修复,只需将localhost:8080添加到default-src指令。

  2. 您的Apache Tomcat服务器通过HTTP头发布默认的CSP。在这种情况下,你不能使用元标签缓解CSP,必须修改CSP响应HTTP头。
    检查你是否有一个CSP HTTP头发布,教程在这里。

这个错误只在Safari浏览器中观察到吗?Chrome/Firefox呢?

最新更新