Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This is a proof-of-concept for adding optional Sub-Resource Integrity support via a new
--integrity
command line option, and a new:integrity
key inconfig/importmap.rb
:bin/importmap pin md5 --integrity
When this option is enabled, the SRI checksum is calculated and added to config/importmap.rb:
pin "md5", to: "https://cdn.jsdelivr.net/npm/md5@2.3.0/md5.js", integrity: "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
Which ultimately adds it to the HTML importmap, with two ESMS options enabled:
More discussion here: #122
Drawbacks
polyfillEnable: true
option to be turned on so that the shim is used for ALL clients. Otherwise, this integrity checking is bypassed when using native implementations, e.g. Chrome. So there is a performance/security trade-off here.script[type]
andlink[rel]
attributes. This breaks some other tooling that is looking forscript[type='importmap']
exactly, e.g.{ eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
.TODO:
script[type]
andlink[rel]
attributes? ESMS has progressed since I dove deep last year, maybe this has changed.Thoughts?