nodejs / nodejs/node

SRI should be checked before Unicode conversion

オープン
#39,707 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

never-stale policy security
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Version

v16.6.1

Platform

Any

Subsystem

policy

What steps will reproduce the bug?
  1. Create a file index.js such that its contents change after Unicode processing. For example, use

    $ xxd -groupsize 1 index.js 
    00000000: 2f 2f 20 c0 af 0a 0a                             // ....
    
  2. Compute the SRI value, e.g., using OpenSSL:

    $ echo "sha384-$(cat index.js | openssl dgst -sha384 -binary | openssl base64 -A)"
    sha384-Z8NoAR4bc95cOnD/QrsnPsgs5pmETQ3ke3NpAVI0Ve08aqCW6aaHFRNVrhcsBCua
    
  3. Test the SRI value in a browser:

    <script src="index.js" integrity="sha384-Z8NoAR4bc95cOnD/QrsnPsgs5pmETQ3ke3NpAVI0Ve08aqCW6aaHFRNVrhcsBCua"></script>
    
  4. Create policy.json:

    {
      "resources": {
        "./index.js": {
          "integrity": "sha384-Z8NoAR4bc95cOnD/QrsnPsgs5pmETQ3ke3NpAVI0Ve08aqCW6aaHFRNVrhcsBCua"
        }
      }
    }
    
  5. 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.

Refs: https://github.com/nodejs/node/pull/37248

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。