SRI should be checked before Unicode conversion
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
再現用ファイルの index.js と policy.json から始め、次にドキュメントに記載された node --experimental-policy=policy.json index.js コマンドを実行して、integrity failure を確認します。リンク先の PR をコンテキストとして使用し、Node の policy と SRI の処理を確認します。提供されたコメントのみの index.js が、出力を生成せずに宣言された integrity check を通過し、実際のコードは引き続き integrity validation の対象となっていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript
- 領域
- security
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100