Skip to content

Limit subresource integrity hash to SHA512 for JavaScript compilation#7732

Merged
aduth merged 1 commit intomainfrom
aduth-single-sri-hash
Jan 31, 2023
Merged

Limit subresource integrity hash to SHA512 for JavaScript compilation#7732
aduth merged 1 commit intomainfrom
aduth-single-sri-hash

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Jan 31, 2023

🛠 Summary of changes

Changes Webpack JavaScript compilation to generate only SHA512 hashes for resource, overriding default which would generate integrity for SHA256, SHA384, and SHA512.

The thinking here being that the SRI specification requires users agents to include support for all three algorithms, so there should be no risk that a browser would only implement one but not other hash algorithms.

Limiting the number of algorithms could potentially allow for some marginal savings in build time by avoiding unnecessary hashing of file contents†, as well as reducing the overall size of rendered pages.

Of the three, SHA512 was chosen as being the most collision-resistant hashing algorithm.

† anecdotally seeing around 3% reduction in build time over an average of 5 runs

📜 Testing Plan

  1. Run NODE_ENV=production yarn build
  2. Run rails s
  3. Visit http://localhost:3000
  4. Observe no issues with JavaScript load
  5. Observe SHA512 integrity hash for rendered scripts in page source

- Improve build performance
- Reduce rendered page size

changelog: Internal, Performance, Reduce size of rendered page
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aduth aduth merged commit c3db991 into main Jan 31, 2023
@aduth aduth deleted the aduth-single-sri-hash branch January 31, 2023 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants