ShipBastion / Security guides / Subresource Integrity (SRI): protect third-party scripts
Subresource Integrity (SRI): protect third-party scripts
When you load a script from a CDN, whoever controls that CDN controls your page. SRI pins the exact file: if a single byte changes, the browser refuses to run it.
Free scan. Sign in with Google to see the full report; paid plans start with a 7-day free trial.
Generate the hash
curl -s https://cdn.example.com/lib@1.2.3/lib.min.js \ | openssl dgst -sha384 -binary | openssl base64 -A
Add it to the tag
crossorigin="anonymous" is required for cross-origin files, otherwise the browser cannot check the hash and blocks the file.
<script src="https://cdn.example.com/lib@1.2.3/lib.min.js" integrity="sha384-<hash>" crossorigin="anonymous"></script>
When SRI does not fit
Files that change on every request (analytics loaders, chat widgets) cannot be pinned. Pin a versioned URL where the vendor offers one, or self-host the file.
Try it on your own domain
Free scan, no card. Pro is $19/mo after a 7-day free trial and covers all four scanners: VibeShield, CiteReady, InboxShield and BrandShield.
FAQ
Do I need SRI for my own scripts?
Not for same-origin files you deploy yourself. SRI matters for files served from someone else's origin.
Related
Next.js and Vercel security headers: copy-paste config
Add HSTS, CSP, X-Content-Type-Options, Referrer-Policy, Permissions-Policy and frame-ancestors to a Next.js app on Vercel with next.config.j...
ShipBastion vs Mozilla HTTP Observatory
ShipBastion runs all 12 Mozilla Observatory tests plus TLS 1.0/1.1 probing, 221 secret rules, Supabase RLS checks and daily monitoring. Obse...