Generate Intergrity hash for the use of CDN, which can be used via CLI or Node packages. (Haven't tested on web)
- firstname.lastname@example.org [Added typings]
- email@example.com [Added inquirer]
- firstname.lastname@example.org [Code refactor]
- email@example.com [Shows file sizes in bytes]
Why use SRI?
unpkg website was compromised, so you don't want to risk your website to be phished or whatsoever, a simple intergrity hash check will solve this issue.
Initially, I wanted to use unpkg for cdn alongside alongside with checksum for intergrity, but I found out that I need to run follwing bash command in order to generate hash. Therefore, I decided to write a CLI tools to "automate" that.
curl https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css | openssl dgst -sha384 -binary | openssl base64 -A
With intergrity checksum, eventhough the CDN is compromised, but your website are still safe from it.
console on webpage when the checksum is not the same
Inspired from srihash.org
Install with npm or yarn
npm install -g ihashgen # yarn global add ihashgen
ihashgen is a function in typescript
> ihashgen --version1.1.3> ihashgen --helpUsage: ihashgen [options] [command]Options:-V, --version output the version number-h, --help output usage informationCommands:generate|g [options] <cdn_url> generate links based on url given
ihashgen g <cdn_url> or
ihashgen generate <cdn_url>
> ihashgen g --helpUsage: generate|g [options] <cdn_url>generate links based on url givenOptions:-t, --type [css/js] specify file type-a, --algo [sha384] specify hashing algorithm-h, --help output usage information
ihashgen generate <cdn_url>,
--type(file type) is set to default to check the url string ends with js or css
--algo(hashing algorithm used) is set to sha384
> ihashgen g https://firstname.lastname@example.org/umd/react.production.min.js -t js -a sha384Generatring hashes
yarn testto run unit test.
yarn prodto generate for NPM. (This command works on Linux/Unix based machine)
yarn sampleto run a sample cli command to ihashgen
- Support other hashing algorithm
- Better CLI with inquirer
- Create webpack configuration for dynamic-cdn-webpack-plugin