Skip to main content

Overview

Subresource Integrity (SRI) lets the browser check that a script it loads from a CDN has not changed. You add an integrity attribute with a hash of the file. If the file on the CDN is different, the browser does not run it. This protects your site if the CDN or the path to it is compromised: a changed SDK file cannot run on your pages.

The pinned snippet

The setup page gives a script tag for one exact SDK version on jsDelivr, with its SRI hash:
  • src names an exact version, never @latest.
  • integrity is the hash of that exact file.
  • crossorigin="anonymous" is required for the browser to check the hash of a cross-origin script.
The hosted dashboard offers only a pinned snippet with a hash. If no pinned release is available, the setup page offers no script tag: use the npm install for Next.js or React instead. It never offers an unpinned script.

How the browser checks the hash

  1. The browser downloads the file in src.
  2. It computes the SHA-384 hash of the file and compares it with integrity.
  3. If the hashes are different, the browser does not run the script and reports an integrity error in the console.
A file that is changed in transit or on the CDN fails the check. A published version on jsDelivr does not change, so a correct hash keeps working until you update the version.

Domains

Allow these exact hosts, not a wildcard such as https://*.jsdelivr.net. With a reverse proxy on your own domain, 'self' covers both. See CSP for a full policy.

Verify the hash

You can compute the hash of the pinned file yourself and compare it with the integrity value. Replace VERSION with the version in your src. With OpenSSL (macOS and Linux):
With Node.js:
The OpenSSL output has no prefix: add sha384- before you compare it. The result must match the integrity value on the setup page exactly.

Update the SDK

  1. Copy the new script tag from the setup page or the SDK release notes.
  2. Change the version and the hash together.
  3. Deploy, and check that page views still arrive in Activity.
Do not change the version without the hash, and do not point a pinned snippet at an unpinned build. The hash then fails and the script does not run, so no events are sent.

npm installs

When you install @untitled-analytics/web from npm, your bundler includes the SDK in your own scripts. SRI on the CDN tag does not apply. Pin the version in your lockfile and review updates as you do for other dependencies.

With a reverse proxy

A reverse proxy that forwards the same file unchanged keeps the same hash. If your proxy changes the file (for example, it minifies or rewrites it), the hash fails.

Combine with CSP

For the strongest protection, use SRI with a Content Security Policy that allows only the SDK’s script host and the collector endpoint.