Write or check
--write adds integrity (and crossorigin) attributes; --check fails on missing, wrong or stale values.
npm package · MIT · Node ≥ 18
Subresource Integrity for your built site: generate, write and check it in CI.
Scans the HTML in your build for scripts, stylesheets, modulepreload / preload links and import map entries, hashes the local files (and CDN files with --remote), then either writes integrity and crossorigin attributes or checks the existing ones are correct. Vite, webpack, Rollup, esbuild and Astro integrations. Zero runtime dependencies.
npm i -D sri-sentinel
$ npx sri-sentinel dist --checkdist/index.html 4: high <link> "/assets/app.css?v=42" has no integrity attribute [missing-integrity] ↳ Add integrity="sha384-IBXuE+SKr6nOANxq1LIznMbjQUHDJ3PY6mUpF3ZQCTz1+rK8Fip9GAGqRq59yH3C" 5: high <script> "https://cdn.jsdelivr.net/npm/htmx.org@2.0.3/dist/htmx.min.js" has no integrity attribute [missing-integrity] ↳ Run with --remote to fetch and hash it, then --write 6: critical Integrity for "./assets/app.js" does not match its content (wrong or stale) [integrity-mismatch] 7: medium Could not resolve "/assets/vendor.js" (file not found: dist/assets/vendor.js) [unresolved-resource] ↳ Check the path and --base, or allowlist it 1 HTML file(s), 4 resource(s): 1 critical, 2 high, 1 medium
If a CDN or asset host is compromised, anything you load from it runs with full access to your page. Subresource Integrity stops that, but hand-maintained hashes go stale on every rebuild and a single missing crossorigin attribute makes the browser block the file.
sri-sentinel writes the hashes for you after each build and fails CI when one is missing, wrong or stale.
--write adds integrity (and crossorigin) attributes; --check fails on missing, wrong or stale values.
--remote fetches and hashes cross-origin files too.
Fills the integrity object inside <script type="importmap">.
The webpack plugin patches the webpack 5 runtime so import() chunks get integrity too.
Only the strongest algorithm counts, any hash of it may match; base64url and ?options accepted.
Vite, webpack, Rollup, esbuild and Astro.
Per-rule or per-URL exemptions with a reason and an expiry date.
JSON manifest of resource → integrity; text, JSON, SARIF and Markdown reports.
# Add integrity attributes
npx sri-sentinel dist --write# Fail CI on bad integrity
npx sri-sentinel dist --check# Include CDN resources
npx sri-sentinel dist --write --remote# Write a manifest
npx sri-sentinel dist --manifest sri.jsonname: SRI
on: [push, pull_request]
jobs:
sri:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm ci && npm run build
- uses: MrLouisWright/sri-sentinel@v1
with:
paths: dist
mode: check # or write
remote: 'true'
fail-on: high
sarif: sri.sarif
| Flag | Description |
|---|---|
--check | Report missing, wrong or stale integrity (default) |
--write | Write integrity (and crossorigin) attributes into the HTML |
-a, --algorithm <alg> | sha256 | sha384 | sha512 (default: sha384) |
--remote | Fetch and hash remote (CDN) resources |
--base <path> | Public base path, e.g. /app/ (default: /) |
--origin <url> | Site origin; absolute URLs on it are treated as local files |
--crossorigin <v> | anonymous | use-credentials (default: anonymous) |
--manifest <file> | Write a JSON manifest of resource -> integrity |
--config <file> | Config file (default: .sri-sentinel.json or package.json "sri-sentinel") |
--fail-on <sev> | critical | high | medium | low | info | none (default: high) |
--format <fmt> | text | json | sarif | markdown (default: text) |
--json/--sarif/--markdown <file> | Also write that report to a file |
--timeout <ms> | Remote fetch timeout (default: 10000) |
-q, --quiet | Only print the summary |
Full reference, config file format and API in the README.
Support this project
I build free, open-source tools that help developers ship safer websites. Every coffee helps keep them maintained, documented and free for everyone.
Buy me a coffee (opens Stripe in a new tab)Secure checkout by Stripe