缺少子资源完整性保护
Posted
技术标签:
【中文标题】缺少子资源完整性保护【英文标题】:Missing Subresource Integrity Protection 【发布时间】:2016-02-22 13:29:19 【问题描述】:我在 Heroku 上搭建了一个 django 博客应用程序,目前一切正常,但我有一个关于 Missing Subresource Integrity Protection
的小问题。
我对使用 heroku 插件还很陌生,但我已经设置了 tinfoil 以确保安全,在初始扫描后我遇到了 3 个漏洞。扫描结果显示我是Missing Subresource Integrity Protection
,他们向我推荐了这个:
> All externally loaded resources must have their content pinned using
> the subresource integrity mechanisms provided by modern browsers. This
> involves computing a hash of the contents of the resource, and
> specifying this hash when loading that resource. In the case of a
> script, this might look like the following:
<script src="https://example.com/include.js"
integrity="sha256-Rj/9XDU7F6pNSX8yBddiCIIS+XKDTtdq0//No0MH0AE="
crossorigin="anonymous"></script>
SRI Hash is an option for computing the necessary hashes.
谁能解释一下这一切意味着什么,以便我可以从中学到一些东西,以及将来该怎么做才能避免这种情况?
【问题讨论】:
【参考方案1】:Subresource integrity 是一个规范,“定义了一种机制,用户代理可以通过该机制验证获取的资源是否已在没有意外操作的情况下交付。”它基本上是您资产的校验和,如果资源与指定的完整性值不匹配,兼容的浏览器将不会加载资源。
这很容易在 Rails 中添加,只要您的 sprockets 版本是 3.x 或更高版本。您可以按照sprockets documentation 中的示例添加检查:
javascript_include_tag :application, integrity: true
# => "<script src="/assets/application.js" integrity="sha256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>"
GitHub Engineering 有一个 interesting blog post,他们在那里详细讨论了该功能。
【讨论】:
我想我也可以将它添加到 django 中? There is not currently built in support for this feature, in django。您需要自己计算和添加。 你能告诉我如何为我的应用程序计算这个,或者提示一下,将不胜感激。 我对django了解不多,但你只需要计算校验和即可。这更多地谈论它 - tenzer.dk/generating-subresource-integrity-checksums。您可以查看 sprockets 源代码,了解它是如何在 Ruby 中完成的...以上是关于缺少子资源完整性保护的主要内容,如果未能解决你的问题,请参考以下文章