我正在使用一个插件来翻译一个Wordpress网站,使用谷歌翻译。我已经为网站设置了一个内容安全策略,这将导致Wordpress插件无法翻译网站,因为CSP会阻止它。当CSP设置在网站上时,是否有一种方法可以启用Google翻译功能?我在谷歌地图上也遇到了同样的问题,我已经通过将google.com地址添加到CSP中来解决这个问题,但是通过翻译,我不知道如何继续下去。
CSP设置:
<?php
header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://www.google.com; img-src 'self' data:; style-src 'self' 'unsafe-inline' https://www.google.com; font-src 'self' data:; object-src 'none'; frame-src https://www.google.com; ");
?>(索引):1拒绝加载脚本'a/element.js?cb=GoogleLanguageTranslatorInit‘,因为它违反了以下内容安全策略指令:" script -src 'self’不安全-内联‘https://www.google.com https://translate.googleapis.com/“。请注意,“script-src-elem”没有显式设置,因此“script-src”用作回退。
发布于 2019-04-02 12:43:15
您需要将所有要允许的域添加到CSP头中:
https://translate.google.com和https://www.google.com不是一回事https://translate.google.com和https://translate.googleapis.com/不是一回事试着:
<?php
header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://www.google.com https://translate.google.com; img-src 'self' data:; style-src 'self' 'unsafe-inline' https://www.google.com; font-src 'self' data:; object-src 'none'; frame-src https://www.google.com; ");
?>注意到一旦脚本被允许,CSP可能会阻止来自同一个域的其他类型的资源(比如CSS,iframe),如果是这样的话,也可以将这个域添加到这些类型中。
https://stackoverflow.com/questions/55450828
复制相似问题