Wordpress jquery 1.12.4的哈希不匹配
Posted
技术标签:
【中文标题】Wordpress jquery 1.12.4的哈希不匹配【英文标题】:Hash Mismatch for Wordpress jquery 1.12.4 【发布时间】:2019-04-02 17:58:40 【问题描述】:我正在使用最新的 (4.9.8) WordPress,目前正在为<script>
标签添加完整性属性。 /wp-includes/js/jquery/jquery.js
的版本是1.12.4
。用于此的 SRI(哈希)是
sha256-/EjR2A7OcaeaezmHf0EE1J09psNmXPbcIDAA+330RH4=
.
jquery site 和 Cloudflare CDN 上的版本 1.12.4
具有 SRI
sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU=
代码看起来已缩小,但 SRI 也与缩小版本不匹配。 Cloudflare 和 jquery 网站上的 SRI 属性也匹配缩小版本。
有人知道为什么会有差异吗? WordPress 开发人员自定义 jquery(标准)库是否常见?【问题讨论】:
【参考方案1】:Wordpress 使用的https://raw.githubusercontent.com/WordPress/WordPress/master/wp-includes/js/jquery/jquery.js 是https://code.jquery.com/jquery-1.12.4.min.js 的副本,已修改为添加jQuery.noConflict()
,使其处于“无冲突”模式https://api.jquery.com/jquery.noconflict/。
我想 Wordpress 这样做是为了防止在您的 Wordpress 网站中加载使用 $
作为函数或变量名的其他库的情况下发生冲突。
因此,如果您想使用具有子资源完整性的 /wp-includes/js/jquery/jquery.js
文件,则需要使用与上游版本不同的哈希值——因为内容不同。
更多详情
https://raw.githubusercontent.com/WordPress/WordPress/master/wp-includes/js/jquery/jquery.js1 与 https://code.jquery.com/jquery-1.12.4.min.js 的差异表明:
--- jquery-1.12.4.min.js 2018-10-30 08:44:12.545350081 +0900
+++ jquery.js 2018-10-30 08:38:48.978809390 +0900
@@ -3,3 +3,4 @@
return cfunction Q(a)var b;for(b in a)if(("data"!==b||!n.isEmptyObject...
marginLeft:0,function()return a.getBoundingClientRect().left):0))+"px"...
padding:"inner"+a,content:b,"":"outer"+a,function(c,d)n.fn[d]=function...
+jQuery.noConflict();
\ No newline at end of file
1https://raw.githubusercontent.com/WordPress/WordPress/922f83a69f47c68d9f7adac6520d1de04075d8be/wp-includes/js/jquery/jquery.js,确切地说。
因此,https://raw.githubusercontent.com/WordPress/WordPress/master/wp-includes/js/jquery/jquery.js 添加了 jQuery.noConflict();
行并从文件末尾删除换行符。
如果您删除该 jQuery.noConflict();
行并在该文件的末尾添加一个换行符,那么您最终将得到与上游 https://code.jquery.com/jquery-1.12.4.min.js 相同的内容。如果你为修改后的文件生成一个哈希,你会得到:
$ shasum -b -a 256 jquery-wordpress-modified.js \
| awk ' print $1 ' | xxd -r -p | base64
ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=
……或者……
$ cat jquery-wordpress-modified.js \
| openssl dgst -sha256 -binary | openssl base64 -A
ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=
...与 jQuery 站点上为 https://code.jquery.com/jquery-1.12.4.min.js 显示的哈希匹配:
<script
src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
crossorigin="anonymous"></script>
/wp-includes/js/jquery/jquery.js
的版本是1.12.4
。用于此的 SRI(哈希)是sha256-/EjR2A7OcaeaezmHf0EE1J09psNmXPbcIDAA+330RH4=
https://raw.githubusercontent.com/WordPress/WordPress/master/wp-includes/js/jquery/jquery.js(当前显示 v1.12.4),当我检查它时,上面没有那个哈希值;相反,它有这个:
$ curl -s -O https://raw.githubusercontent.com/WordPress/WordPress/922f83a69f47c68d9f7adac6520d1de04075d8be/wp-includes/js/jquery/jquery.js \
&& cat jquery.js | openssl dgst -sha256 -binary | openssl base64 -A
+gVfL3xbc127txlU9DSu15klvAD/L/vD7PxKeQaJpyM=
另请参阅the MDN article on Subresource Integrity 的Tools for generating SRI hashes 部分。
【讨论】:
以上是关于Wordpress jquery 1.12.4的哈希不匹配的主要内容,如果未能解决你的问题,请参考以下文章