- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否有使用 CSP(内容安全策略)将 WebForms 项目中动态创建的脚本列入白名单的安全方法?
使用 unsafe-inline
像下面它的工作原理,但不推荐。
context.Response.Headers.Append("Content-Security-Policy", string.Format("default-src 'none'; connect-src 'self'; font-src 'self'; img-src 'self' data: https:; style-src 'self'; script-src 'self' 'unsafe-inline'"));
nonce-(random)
,我们看到此 CSP 错误消息:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash, or a nonce is required to enable inline execution.
最佳答案
动态脚本没有“安全内联”这样的东西,请尝试使用动态导入? (您可以在代码中重新加载此类脚本)。
您通常不必使用“不安全内联”,经常会出现问题的两件事是开发中的实时重新加载和代码中的 setTimeout/setInterval,它们可以轻松触发 CSP。所以最好在开发中禁用 CSP 以提高交付速度。 'unsafe-inline' 用于启用动态创建的脚本的执行。
更新
要解决此问题,您需要使用标准(可能使用 async/defer)加载自定义脚本 <script src="/myscript.js"></script>
并且“不安全内联”要求消失了。但是,您的技术选择(“网络表单”)可能会限制您这样做的选择。无论如何要进行测试,请使用 cdn url 或单独的服务器(内部或外部)来交付您的脚本。我已经用 nodejs 在本地测试了这个,它按预期工作。您遇到的“问题”很可能是因为您编写了这样的代码(或代码放在那里):<script>function unsafeInline() { ... }</script>
Modernizr 现在是 v3.6.0,您使用 v2.8.3 并消除错误,您可以将其添加到标题中:
<header>
<title>CSP Test</title>
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' https://cdnjs.cloudflare.com/;">
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
</header>
If modernizr is injecting all that inline stuff than it seems like your choices are to either (a) add all those hashes, (b) use 'unsafe-inline' (but which basically defeats the whole purpose of CSP…), or (c) don’t use modernizr.
document.body.style = "background: #000000;";
从外部库设置样式(或其他)属性。我在导入的外部脚本中尝试了所有“正常”代码事件,但它不会触发 CSP。通常我也指将对象(函数)分配给 window 对象并执行它们。
关于webforms - 如何使用 CSP(内容安全策略)将 WebForms 项目中动态创建的脚本列入白名单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54095422/
当我读这本书 -- 人工智能(一种现代方法)时,我遇到了以下描述将 n 元约束搜索问题转换为二进制问题的方法的句子: Another way to convert an n-ary CSP to a
我的Web应用程序(JS部分)需要在加载之前由服务器配置。现在它是通过以下方式完成的: var configObj = { setting1: "blah", setting2: {val1: 1,
作为开发人员,我应该为windows提供什么智能卡登录功能?只有微型驱动程序 + 现有的基础智能卡 csp 工作吗或者,如果我开发了一个完整的 CSP,我可以让智能卡登录正常工作吗? 最佳答案 你应该
在一些 css 文件中嵌入一些 base64 字体,但 CSP 阻止了这些:类似于 url("data:font/woff;base64,d09GRk9UVE...); 当前 CSP =“base-u
CSP的理念:以通信的方式来共享内存 不要通过共享内存来通信,而要通过通信来实现内存共享。这就是 Go 的并发哲学,它依赖 CSP 模型,基于 channel 实现。Go 一开始就把 CSP 的思想融
在上一篇博客我们主要总结了XSS攻击,本篇博客主要总结内容安全策略CSP的相关内容。 一、定义 内容安全策略(CSP),是一种安全策略,其原理是当浏览器请求某一个网站时,告诉该浏览器申明文件可以执行,
我正在开发一个 Flask 应用程序,它使用 Flask-Talisman 来合并一个 CSP。我想在我的模板之一中创建一个内联脚本,而不是将“unsafe-inline”添加到 CSP 的“scri
我注意到 GitHub 和 Facebook 现在都在实现这项政策,这限制了第三方脚本在他们的体验/站点中运行。 有没有办法使用 检测文档是否针对 CSP 运行? JavaScript ? 我正在编写
我一直在努力寻找最好的管理访问权限的方法,并允许我们的技术人员访问我们的客户订阅和 Azure 资源,而不给予他们作为每个订阅的贡献者或类似权利的明确权利。 现在我遇到了权限身份管理功能( https
我正在学习内容安全策略。 假设我的网站 abc.com 有以下 csp: default-src 'self' 'unsafe-inline' 'unsafe-eval' xyz.com 这是否意味着
我一直在努力寻找最好的管理访问权限的方法,并允许我们的技术人员访问我们的客户订阅和 Azure 资源,而不给予他们作为每个订阅的贡献者或类似权利的明确权利。 现在我遇到了权限身份管理功能( https
我了解使用 CSP 的好处,但是发送这些 header 用于 HTML 文件以外的任何内容是否浪费?例如,我是否需要在图像上发送 CSP header ?对于 .js 文件? 最佳答案 Content
Closed. This question needs to be more focused。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题
有许多用于 JavaScript 的图表绘制库,例如 Chart.js 或 Chartist.js。但是,我们无法找到任何适用于严格 CSP-Mode 的库。 .我们测试的所有库都使用 eval 或默
如何获取已连接智能卡的 CSP 提供商名称? 我无法访问注册表窗口,因此我找到了通过 win API 获取该信息的方法。 我已经看过有关 SCardGetCardTypeProviderName 的内
我正在编写一个使用智能卡进行 xml 签名的简单程序。 示例代码: var cspParams = new CspParameters(1, "Microsoft Base Smart Card Cr
我正在尝试编写自己的 CSP。我正在尝试通过实现一个 dll 文件来做到这一点,但我不确定我的方法是否正确。 我发现了这样的东西:加密服务提供商开发人员工具包 (CSPDK) 有 CSP API 的示
下册开学期末+CSP-J游记 Day -14 期末 Day -7 今天家长会,老师公布成绩 /fn/fn/fn。政治和历史考废了,然后其他都挺好。 语文 \(101\
当我从 TFS 服务器运行构建时,出现以下错误:无法导入以下 key 文件:C:\TfsData\Build_work\fa450055\EXChecker 2015\signingKey.pfx。
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
我是一名优秀的程序员,十分优秀!