简体   繁体   English

Wordpress 内容安全策略问题

[英]Wordpress Content Security Policy Problem

Our website is designed based on WordPress tool and published on Azure web service.我们的网站是基于 WordPress 工具设计的,并发布在 Azure 网络服务上。 Our goal is to use google analytic for checking traffic.我们的目标是使用谷歌分析来检查流量。 Due to this fact, the google analysis tag was added in the header part of our page which causes the following error:由于这个事实,谷歌分析标签被添加到我们页面的标题部分,导致以下错误:

Refused to load the script 'https://www.googletagmanager.com/gtag/js?id=??'拒绝加载脚本“https://www.googletagmanager.com/gtag/js?id=??” because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval' 'unsafe-inline' *.msecnd.net *.google.com *.gstatic.com".因为它违反了以下内容安全策略指令:“script-src 'self' 'unsafe-eval' 'unsafe-inline' *.msecnd.net *.google.com *.gstatic.com”。 Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.请注意,'script-src-elem' 未明确设置,因此使用 'script-src' 作为后备。

I understand that violation of the Content Security Policy is the main problem.我了解违反内容安全政策是主要问题。 Therefore, I added meta in the header (Content-Security-Policy: script-src 'unsafe-inline') but the issue did not disappear.因此,我在标题中添加了元 (Content-Security-Policy: script-src 'unsafe-inline') 但问题并没有消失。 I will appreciate any help.我将不胜感激任何帮助。

Since you have got a Content Security Policy (CSP) violation, you already have a first CSP published at the page.由于您违反了内容安全策略 (CSP),因此您已经在该页面上发布了第一个 CSP。
Adding a second CSP via meta tag (or even via second HTTP header) will not solve a problem, because all sources should pass through both CSPs to be allowed.通过元标记(甚至通过第二个 HTTP 标头)添加第二个 CSP 不会解决问题,因为所有源都应该通过两个 CSP 才能被允许。

Therefore you have to add blocked source ( https://www.googletagmanager.com ) in first CSP into script-src 'self' 'unsafe-eval' 'unsafe-inline' *.msecnd.net *.google.com *.gstatic.com;因此,您必须在第一个 CSP 中将被阻止的源 ( https://www.googletagmanager.com ) 添加到script-src 'self' 'unsafe-eval' 'unsafe-inline' *.msecnd.net *.google.com *.gstatic.com; . .
Check if your WP has some installed plugins to manage CSP, or CSP is published in the .htaccess file.检查您的 WP 是否安装了一些插件来管理 CSP,或者 CSP 发布在.htaccess文件中。

Since you have 'unsafe-eval' 'unsafe-inline' in the script-src , you should not have problems with Google Tag Manager (GTM).由于您在script-src'unsafe-eval' 'unsafe-inline' ,您应该不会遇到 Google 标签管理器 (GTM) 的问题。
Anyway you can check CSP for your GTM-XXXXXX ID - which additional scripts are loaded by GTM and which tokens are required in you specific case.无论如何,您可以检查您的 GTM-XXXXXX ID 的 CSP - GTM 加载了哪些附加脚本以及在您的特定情况下需要哪些令牌。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM