2015-11-20 92 views
3

我已经上演在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的,只要你的链轮版本3.x或更高。您可以通过以下从sprockets documentation的例子中添加了检查:

javascript_include_tag :application, integrity: true 
# => "<script src="/assets/application.js" integrity="sha256-TvVUHzSfftWg1rcfL6TIJ0XKEGrgLyEq6lEpcmrG9qs="></script>" 

GitHub的工程有一个interesting blog post,在那里他们详细讨论该功能。

+0

我想,我可以把它添加到Django的呢? – PetarP

+1

[目前还没有内置该功能的支持,在Django(https://github.com/cyberdelia/django-pipeline/issues/501)。您需要自行计算并添加它。 –

+0

你能否告诉我如何为我的应用程序计算这个值,或者只是一个提示,将不胜感激。 – PetarP