SRI should be checked before Unicode conversion
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
Version
v16.6.1
Platform
Any
Subsystem
policy
What steps will reproduce the bug?
-
Create a file
index.jssuch that its contents change after Unicode processing. For example, use$ xxd -groupsize 1 index.js 00000000: 2f 2f 20 c0 af 0a 0a // .... -
Compute the SRI value, e.g., using OpenSSL:
$ echo "sha384-$(cat index.js | openssl dgst -sha384 -binary | openssl base64 -A)" sha384-Z8NoAR4bc95cOnD/QrsnPsgs5pmETQ3ke3NpAVI0Ve08aqCW6aaHFRNVrhcsBCua -
Test the SRI value in a browser:
<script src="index.js" integrity="sha384-Z8NoAR4bc95cOnD/QrsnPsgs5pmETQ3ke3NpAVI0Ve08aqCW6aaHFRNVrhcsBCua"></script> -
Create
policy.json:{ "resources": { "./index.js": { "integrity": "sha384-Z8NoAR4bc95cOnD/QrsnPsgs5pmETQ3ke3NpAVI0Ve08aqCW6aaHFRNVrhcsBCua" } } } -
Run the script with the policy file:
node --experimental-policy=policy.json index.js
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
No output, unless index.js contains code. In the example above, index.js contains a comment only.
This behavior can be observed in Chrome and Firefox.
What do you see instead?
Error [ERR_MANIFEST_ASSERT_INTEGRITY]: The content of "file:///home/tniessen/dev/policy-test/index.js" does not match the expected integrity. Integrities found are: sha384-s+/FLC70SKA4cOtWba1RQAhBoGcQoMRXt/kU5mp0oDnO+hQVqm5/zQkIaG26qVa0
Additional information
It seems unlikely that this could cause any real security issues, but it does allow hash collisions. Different byte sequences can result in the same Unicode character sequences, which, when hashed, result in the same digests.
The issue arises from the fact that Node.js loads a byte sequence from the resource, converts the byte sequence to a Unicode string, and then converts the string back to a byte sequence for the SRI check.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从复现文件 index.js 和 policy.json 开始,然后运行文档中记录的 node --experimental-policy=policy.json index.js 命令,以观察完整性失败。参考链接的 PR,检查 Node 对 policy 和 SRI 的处理。完成标准是:提供的仅包含注释的 index.js 能通过其声明的完整性检查且不产生输出,同时实际代码仍受完整性验证覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- security
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100