我在chrome扩展中使用外部JavaScript库.我有内联执行,所以我得到了一些错误
(我在控制台上得到的错误)
拒绝执行JavaScript URL,因为它违反了以下内容安全策略指令:"script-src'self'chrome-extension://".要么是'unsafe-inline'关键字,哈希('sha256 -...'),要么是nonce('nonce -...')来启用内联执行.
错误消息清楚地表明有可能解决方法.
Chrome内容安全政策说不可能.许多相关问题引用了此链接.
博客这位博主说这是可能的,但可能这只适用于较旧的Chrome扩展程序.
任何可能的工作?
PS:不想/不能改变我正在使用的整个库.
编辑:如何使用哈希或随机数启用内联执行.
google-chrome google-chrome-extension content-security-policy
创建一个简单的电子应用程序模板。我想对我的 api 执行获取请求,但不断被内容安全策略错误阻止,而且我不知道如何修复它们。
拒绝连接到“https://api.myapp.com/”,因为它违反了以下内容安全策略指令:“default-src 'self' 'unsafe-inline' data:”。请注意,“connect-src”未明确设置,因此“default-src”用作后备。
索引.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-eval' ">
<meta charset="UTF-8">
</head>
<body>
<div id="root"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
应用程序.js
const handleSubmit = async () => {
const response = await fetch("https://api.myapp.com/books", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
return response.json();
};
Run Code Online (Sandbox Code Playgroud)
我尝试将 api 地址添加到现有策略中,并添加其他策略,但没有任何效果。
我正在寻找一种为ASP.NET WebForms应用程序实现相对强大的Content-Security-Policy标头的好方法.我将尽可能多的JavaScript存储在文件而不是内联中,但默认情况下,WebForms会为表单提交和基本AJAX调用等简单注入大量内联脚本.
MVC有一些简单的方法来实现nonce,特别是在第三方库(如NWebsec)的帮助下,但我似乎无法找到任何使用WebForms实现它们的方法.如果有一种方法可以预测和检索每个.NET注入脚本标记的哈希,我甚至不会使用哈希值.
我讨厌允许'不安全内联'的价值.需要关闭这样一个强大的安全功能是不对的.有没有合理的方法在WebForms中实现它?
我在浏览器的控制台中收到以下错误:
内容安全策略:页面的设置阻止了在
http://localhost:3000/favicon.ico
(“default-src”)处加载资源。
我在网上搜索,发现这应该用下面的代码片段来解决:
<meta http-equiv="Content-Security-Policy" content="default-src *;
img-src * 'self' data: https: http:;
script-src 'self' 'unsafe-inline' 'unsafe-eval' *;
style-src 'self' 'unsafe-inline' *">
Run Code Online (Sandbox Code Playgroud)
我将此添加到我的前端app.component.html
文件(我所有前端视图的父模板),但这并没有按预期工作。
我也因此尝试了多种排列无济于事。
我的前端在localhost:4200
,后端在localhost:3000
。
下面是来自我的后端服务器(中间件)的代码片段:
app.use(cors());
app.options('*',cors());
var allowCrossDomain = function(req,res,next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
app.use(allowCrossDomain);
Run Code Online (Sandbox Code Playgroud)
我现在还向我的后端 (Express) 服务器添加了以下中间件:
const csp = require('express-csp-header');
app.use(csp({
policies: {
'default-src': [csp.SELF, 'http://localhost:3000/', 'http://localhost:4200/' ],
'script-src': [csp.SELF, csp.INLINE],
'style-src': [csp.SELF],
'img-src': ['data:', 'favico.ico'],
'worker-src': [csp.NONE],
'block-all-mixed-content': true …
Run Code Online (Sandbox Code Playgroud) 我在使用以下Content-Security-Policy HTTP标头时尝试使用TinyMCE:
X-WebKit-CSP: default-src 'self'; script-src 'self' 'unsafe-eval'; img-src *; media-src *; frame-src *; font-src *; style-src 'self' 'unsafe-inline'; report-uri /:reportcspviolation
Run Code Online (Sandbox Code Playgroud)
我在工具 - JavaScript控制台中收到以下错误:
Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
about:blank:1
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
test.xhtml:1
Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
about:blank:1
Refused …
Run Code Online (Sandbox Code Playgroud) javascript security google-chrome tinymce content-security-policy
我目前正在为使用 Next.js 制作的生产应用程序制定内容安全策略 (CSP)。虽然我找到了使用该框架实施 CSP 的可靠文档,但我想确保正确解决一些问题。
问题#1:我了解到在 HTTP 标头中设置的安全策略更可取。但是,我找不到使用这种方法在生产中传递内联样式的“nonce”属性的方法。https://nextjs.org/docs/advanced-features/security-headers
问题#2:我见过其他示例,其中开发人员将其 CSP 注入自定义文档(“./pages/_document.js”)。我对使用这种方法犹豫不决,因为我听说元标签 CSP 很容易被绕过。https://github.com/vercel/next.js/tree/canary/examples/with-strict-csp
我的问题:
祝一切顺利,-萨姆
手机上没有正确接收某些页面(法国很多页面):内联JavaScript脚本元素.
而不是拥有
<script src="static/jquery-2.1.3.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
我有
<script> ... content of the whole jQuery script ... </script>
Run Code Online (Sandbox Code Playgroud)
由于我设置的内容安全策略标题禁止内联脚本,现代浏览器会阻止脚本的执行.
除了使用HTTPS之外,还有其他方法可以解决这个问题吗?也许某些指定页面的方法不应该由第三方重写?
备注:
Cache-Control:no-transform
首标被忽略,以及我有一个Cordova应用程序,升级后(5.0.0)我根本无法调用任何资源.我添加了白名单插件,并将以下标记添加到index.html
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.azure-mobile.net localhost:1337 *.ajax.aspnetcdn.com">
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
拒绝加载脚本' http://ajax.aspnetcdn.com/ajax/mobileservices/MobileServices.Web-1.2.5.min.js ',因为它违反了以下内容安全策略指令:"script-src'self'' unsafe-inline''unsafe-eval'*.azure-mobile.net localhost:1337*.ajax.aspnetcdn.com".
拒绝加载脚本' http:// localhost:1337/vorlon.js ',因为它违反了以下内容安全策略指令:"script-src'self''unsafe-inline''unsafe-eval'*.azure-mobile .net localhost:1337*.ajax.aspnetcdn.com".
我尝试过应该允许一切的默认策略,但仍然没有运气.
我还在config.xml文件中添加了以下内容
<access origin="*" />
<allow-navigation href="*" />
Run Code Online (Sandbox Code Playgroud)
并使用以下插件:
C:\Projects\TavlaApp>cordova plugin
com.microsoft.azure-mobile-services 1.2.7 "Windows Azure Mobile Services"
cordova-plugin-whitelist 1.0.1-dev "Whitelist"
nl.x-services.plugins.calendar 4.3.4 "Calendar"
nl.x-services.plugins.insomnia 4.0.1 "Insomnia (prevent screen sleep)"
org.apache.cordova.inappbrowser 0.6.0 "InAppBrowser"
Run Code Online (Sandbox Code Playgroud)
任何想法是什么尝试?
cordova azure-mobile-services content-security-policy ionic-framework visual-studio-cordova
我正在强制https
访问我的网站,但必须加载一些内容http
(例如视频内容不能通过https),但浏览器会因mixed-contents
策略阻止请求.
经过几个小时的搜索,我发现我可以使用Content-Security-Policy,但我不知道如何允许混合内容.
<meta http-equiv="Content-Security-Policy" content="????">
Run Code Online (Sandbox Code Playgroud) 我收到此错误:
Refused to load the image 'blob:file:///cf368042-bf23-42b6-b07c-54189d3b0e01' because it violates the following Content Security Policy directive: "default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content:". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.
Run Code Online (Sandbox Code Playgroud)
在尝试加载 mapboxGL 地图时。这是我的 CSP 标签:
<meta http-equiv="Content-Security-Policy"
content="
worker-src blob:;
child-src blob: gap:;
default-src * 'self' 'unsafe-inline' 'unsafe-eval' data: gap: content:">
Run Code Online (Sandbox Code Playgroud)