Skip to content

JADSN1894/sri

Repository files navigation

Subresource Integrity (SRI)

Version badge Score badge

Adds subresource integrity hashes to script and stylesheet imports from at index.html file at build time.

Before

Before execution

After

After execution

Usage

  1. Install wasmtime: curl https://wasmtime.dev/install.sh -sSf | bash
  2. Download the sri.wasm compiled executing the code below at the project root: wget -c https://github.com/JADSN1894/sri/releases/download/<TAG_VERSION>/sri.wasm
  3. In your vite.config.js file:

Jsr sri package import

Ohh!! Is not a Vite(or another bundler) then...

  • Execute: wasmtime --dir=/ --dir=. <filename>.wasm <hash_algorithm> <airtifact_folder>
  • Example: wasmtime --dir=/ --dir=. ./sri.wasm Sha512 ./dist

Disclaimer

Given the instability of the WASI API, utilizing Wasmtime ensures reliable execution of the compiled sri.wasm file.

Look for the issues: WASI support #441 and node:wasi fails during module resolution #23531

Links

  1. WebAssembly System Interface (WASI)#
  2. WASI tutorial
  3. How to convert hexadecimal values to Base64 in Rust
  4. Deno wasi
  5. Synchronizy your type definitions between Rust and other languages for seamless FFI
  6. How works sha256
  7. Leveraging Rust to Bundle Node Native Modules and Wasm into an Isomorphic NPM Package
  8. WebAssembly System Interface (WASI)
  9. Getting started with NodeJS and the WebAssembly System Interface

About

Adds subresource integrity hashes to script and stylesheet imports from at index.html file at build time.

Resources

Stars

Watchers

Forks

Packages

No packages published