简体   繁体   English

CSP,拒绝加载脚本,违反了以下内容安全策略指令:“script-src 'self'”

[英]CSP, Refused to load the script, violates the following Content Security Policy directive: "script-src 'self'"

Can someone explain me how can i add CSP meta tag to my header?有人可以向我解释如何将 CSP 元标记添加到我的 header 吗? i tried adding different meta tag to my header but i get more error from CSP我尝试向我的 header 添加不同的元标记,但我从 CSP 收到更多错误

<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:*//api.mapbox.com/mapbox-gl-js/v2.3.1/mapbox-gl.js;">

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data:gap 'unsafe-eval' ws: ; style-src 'self' 'unsafe-inline' script-src *; media-src *; font-src *;  connect-src *; img-src 'self' data: content:;">

console error stack控制台错误堆栈

It looks like you already have a published CSP via an HTTP header because a console error saying:看起来您已经通过 HTTP header 发布了 CSP,因为控制台错误提示:

it violates the following Content Security Policy directive " default-src 'self' "它违反了以下内容安全策略指令“ default-src 'self'

while your meta tag contains other default-src sources: default-src 'self' https:*//api.mapbox.com/mapbox-gl-js/v2.3.1/mapbox-gl.js而您的元标记包含其他default-src来源: default-src 'self' https:*//api.mapbox.com/mapbox-gl-js/v2.3.1/mapbox-gl.js

You can check the CSP response HTTP header that you have, the tutorial is here .您可以查看您拥有的 CSP 响应 HTTP header,教程在这里

In this case by adding meta tag you'll have 2 CSPs which will work independently each other, therefore CSP in HTTP header will continue to block your scripts.在这种情况下,通过添加元标记,您将拥有 2 个相互独立工作的 CSP,因此 HTTP header 中的 CSP 将继续阻止您的脚本。

Node.js has a Helmet middleware in dependancies, Helmet 4 automatically publishes a default CSP via HTTP header. Check it. Node.js 在依赖项中有一个 Helmet 中间件, Helmet 4通过 HTTP header 自动发布默认 CSP。检查它。
In this case you have 2 opts:在这种情况下,您有 2 个选择:

  • disable Helmet's CSP: app.use( helmet({ contentSecurityPolicy: false, }) );禁用 Helmet 的 CSP: app.use( helmet({ contentSecurityPolicy: false, }) ); and use a meta tag.并使用元标记。
  • configure CSP header via Helmet (preferred way).通过 Helmet(首选方式)配置 CSP header。

BTW you have errors in the:顺便说一句,您在以下方面有错误:

default-src 'self' data:gap 'unsafe-eval' ws: ; style-src 'self' 'unsafe-inline' script-src *; media-src *; font-src *;  connect-src *; img-src 'self' data: content:;
  1. data:gap is a wrong source, use data: or data: gap: depending on what you need. data:gap是一个错误的来源,使用data:data: gap:取决于你需要什么。
  2. missed ;错过了; before script-srcscript-src之前

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gmail Chrome 扩展“拒绝加载脚本,因为它违反了以下内容安全策略指令:“script-src 'self'”。Manifest v3 - Gmail Chrome Extension "Refused to load script because it violates the following Content Security Policy directive: "script-src 'self'". Manifest v3 Javascript抛出:拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“script-src'self' - Javascript throwing : Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' 内联脚本,因为它违反了以下内容安全策略指令:“script-src 'self'” - Inline script because it violates the following Content Security Policy directive: “script-src 'self'” 因为它违反了以下内容安全策略指令:“script-src &#39;self&#39; blob:”。 请注意,&#39;script-src-elem&#39; 没有明确设置, - because it violates the following Content Security Policy directive: "script-src 'self' blob:". Note that 'script-src-elem' was not explicitly set, 拒绝加载脚本,因为它违反了以下内容安全策略指令:“style-src 'self' 'unsafe-inline' - Refused to load the script because it violates the following Content Security Policy directive: "style-src 'self' 'unsafe-inline' 拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“default-src 'self'” - Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'" 拒绝加载脚本,因为它违反了以下内容安全策略指令 - Refused to load the script because it violates the following Content Security Policy directive 没有内联脚本,仍然因“内容安全策略指令而拒绝”:script-src&#39;self&#39;“ - No inlined script, still getting “Refused due to Content Security Policy directive: ”script-src 'self'" Chrome扩展程序“拒绝加载脚本,因为它违反了以下内容安全策略指令” - Chrome Extension “Refused to load the script because it violates the following Content Security Policy directive” Chrome 扩展“拒绝加载脚本,因为它违反了以下内容安全策略指令” - Chrome Extension “Refused to load the script because it violates the following Content Security Policy directive”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM