SRI 介绍
来源:互联网 发布:艺术学博士知乎 编辑:程序博客网 时间:2024/05/17 05:07
What
Subresource Integrity (SRI) is a security feature that enables browsers to verify that files they fetch (for example, from a CDN) are delivered without unexpected manipulation.
在 <script> 和 link 标签中通过 integrity 属性,浏览器核实所获取的 js 文件(或 css 文件)确实是如 integrity 值规定的,然后再加载 js 文件(或应用css 文件)。
例子
如下是个 script 标签
<script src="https://example.com/example-framework.js" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="anonymous"></script>
注意 integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
,integrity 的值以 sha384-
开头,表示算法为 sha384, dash (-) 之后跟随的是 base64-encoded hash。
当前所允许的 hash 算法有 sha256, sha384, and sha512
生成 SRI hashes 值
命令行有两种方法。
方法一:
cat FILENAME.js | openssl dgst -sha384 -binary | openssl enc -base64 -A
方法二:
shasum -b -a 384 FILENAME.js | xxd -r -p | base64
注意,这里 shah 算法是 sha384,如果生成其他的 hash 值,是否也像这样,只需稍作修改即可(可能吧,但是未验证)。
还有在线工具 https://srihash.org/
浏览器如何处理 SRI (Subresource Integrity)
When a browser encounters a <script> or <link> element with an integrity attribute, before executing the script or before applying any stylesheet specified by the <link> element, the browser must first compare the script or stylesheet to the expected hash given in the integrity value.
If the script or stylesheet doesn’t match its associated integrity value, then the browser must refuse to execute the script or apply the stylesheet, and must instead return a network error indicating that fetching of that script or stylesheet failed.
参考
- Subresource Integrity
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
- SRI 介绍
- Subresource Integrity 介绍--SRI (Subresource Integrity) 的检查
- 漏洞修复之 SRI
- Siri之父SRI又一力作:银行智能助手Lola
- RFC32 关于SRI所提议的实时时钟的一些想法
- #银行智能助手Lola#银行工作人员可以下岗了,Siri之父SRI新作,银行智能助手Lola
- 看看SRI的“可穿戴机器人”:能让人跑得更快、负重更多的可穿戴技术(视频)
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 获取Linux内核未导出符号的几种方式
- helloworld详解
- C语言-计算某段代码的运行时间
- Laravel框架路由配置、设置
- 父元素overflow: hidden;子元素position: fixed;子元素溢出部分居然不显示。
- SRI 介绍
- 验证码短信收不到的原因及解决办法
- 杭电acm1597 find the nth digit
- Magento重置索引时Catalog URL Rewrites生成错误的解决办法
- 周日历
- json-lib 相关jar包
- Unity获取串口数据
- STM32之内存五 (attribute at属性)
- qpnp_rtc_read_time