【发布时间】:2021-09-22 13:56:27
【问题描述】:
我在加载应用程序时遇到以下错误:
Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”). jquery-3.6.0.js:6333:7
这一行的代码:
if ( elem.nodeType === 1 ) { jQuery.cleanData( getAll( elem, false ) ); elem.innerHTML = value; // this line is causing issue }
我的 CSP 标头:
add_header Content-Security-Policy "default-src 'self' data: blob: ;
script-src 'self' data: blob: 'nonce-2726c7f26c';
style-src 'self' data: blob: ;
img-src 'self' ;
form-action 'self' ;
frame-ancestors 'self' ;" always;
我也在尝试使用“nonce”,但它不起作用。
<script src="js/jquery-3.6.0.js" nonce="2726c7f26c"></script>
我不想使用“不安全内联”。
任何人都可以帮助解决这个问题,我在谷歌上搜索了 2 天,但没有任何结果。
提前致谢。
更新 1: 在 Chrome 中出现以下错误:
jquery-3.6.0.js:6262 拒绝应用内联样式,因为它违反 以下内容安全策略指令:“style-src 'self' 数据:blob:'nonce-2726c7f26c'"。要么是 'unsafe-inline' 关键字,一个 哈希('sha256-1PxuDsPyGK6n+LZsMv0gG4lMX3i3XigG6h0CzPIjwrE='),或 nonce ('nonce-...') 是启用内联执行所必需的。
(匿名)@ jquery-3.6.0.js:6262 domManip @ jquery-3.6.0.js:6089 前置@ jquery-3.6.0.js:6259(匿名)@ angular.min.js:315
:81/uploadGrp:1 拒绝执行内联事件处理程序,因为它 违反以下内容安全策略指令:“script-src 'self' 数据:blob:'nonce-2726c7f26c'"。要么是 'unsafe-inline' 关键字、哈希 ('sha256-...') 或随机数 ('nonce-...') 是必需的 启用内联执行。请注意,哈希不适用于事件 处理程序、样式属性和 javascript: 导航,除非 存在“不安全哈希”关键字。
jquery-3.6.0.js:6262 行代码:
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
var target = manipulationTarget( this, elem );
target.insertBefore( elem, target.firstChild ); //this line is causing issue.
}
【问题讨论】:
标签: javascript jquery angularjs content-security-policy nonce