nodejs / nodejs/node

SRI should be checked before Unicode conversion

Open
#39,707 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

never-stale policy security
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction files index.js and policy.json, then run the documented node --experimental-policy=policy.json index.js command to observe the integrity failure. Review Node's policy and SRI handling, using the linked PR as context. Done means the provided comment-only index.js passes its declared integrity check without producing output, while actual code remains covered by integrity validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.