我想了解当页面中不同的REST响应具有不同的CSP标头值时如何应用CSP。我们没有任何元标签的CSP。CSP仅通过响应头应用。
让我们以3个api
为例GET /api/v1/users
-Content-Security-Policy: default-src 'self' google.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' google.com
GET /api/v1/roles
-Content-Security-Policy: default-src 'self'; script-src 'self'; img-src 'self'
GET /api/v1/permission
-Content-Security-Policy: default-src 'self' google.com; script-src 'self' 'unsafe-inline' 'unsafe-eval' google.com
在这种情况下,浏览器对后续请求考虑的CSP是什么?
另外,在我的理解中,服务器在响应头中设置CSP,以通知浏览器允许哪些内容向前移动。对吗?
CSP决定哪些资源可以加载到页面上,并且只应用于在浏览器中呈现的页面,通常内容类型为"text/html"因此,在图像,脚本,样式等上设置它没有任何好处。
对API有意义的CSP是框架祖先'none',参见https://cheatsheetseries.owasp.org/cheatsheets/REstrongecurity_Cheat_Sheet.html#security-headers了解解释。