Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了node.js – 尝试渲染i-frame:ancestor违反了以下内容安全策略指令:“frame-ancestors’none’”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想渲染一个iframe,源代码Github,如下所示:

<iframe src="https://gist.github.com/user45445/9bf8d568e3350146ba302d7d67ad576f"> </iframe>

这是我在控制台中遇到的错误:@H_673_10@拒绝在框架中显示https://gist.github.com/fresh5447/9bf8d568e3350146ba302d7d67ad576f”,因为祖先违反了以下内容安全策略指令:“frame-ancestors’none’”.

我正在研究如何在我的节点服务器中指定我的内容安全策略,以指定它应该接受来自github的任何iframe

所以我安装了csp-helmet并将其添加到我的服务器代码中:

var csp = require('HelR_237_11845@et-csp')

app.use(csp({
  // Specify directives as normal.
  directives: {
    frameAncestors: ['*.github.com'],//I thought these two did the same,so I tried them both.
    childSrc: ['*.github.com']
  },// Set to true if you only want browsers to report errors,not block them.
  // You may also set this to a function(req,res) in order to decide dynamically
  // whether to use reportOnly mode,e.g.,to allow for a dynamic kill switch.
  reportOnly: false,// Set to true if you want to blindly set all headers: Content-Security-Policy,// X-WebKit-CSP,and X-Content-Security-Policy.
  setAllHeaders: false,// Set to true if you want to disable CSP on Android where it can be buggy.
  disableAndroid: false,// Set to false if you want to completely disable any user-agent sniffing.
  // This may make the headers less compatible but it will be much faster.
  // This defaults to `true`.
  browserSniff: true
}))

但仍然是同样的错误..

我一直试图看看official docsHTML5 rocks guide

不确定我是否超级接近或采取完全错误方法.

更新

我还尝试通过元标记设置CSP.

<Meta http-equiv="Content-Security-Policy" content="child-src https://gist.github.com; frame-ancestors https://gist.github.com;">

比我收到这个错误

Content Security Policies delivered via a <Meta> element may not contain the frame-ancestors directive.

提前致谢.

解决方法

正如oreoshake所指出的,这里的问题不是你的CSP,而是GitHub上的CSP. GitHub阻止你对它们进行框架处理,因此你无法用CSP解决这个问题.

大佬总结

以上是大佬教程为你收集整理的node.js – 尝试渲染i-frame:ancestor违反了以下内容安全策略指令:“frame-ancestors’none’”全部内容,希望文章能够帮你解决node.js – 尝试渲染i-frame:ancestor违反了以下内容安全策略指令:“frame-ancestors’none’”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。