Create the integrity attribute and a ready-to-paste script or link element for a CDN file, or check an existing attribute against the file.
Initializing in your browser…
Build a Content Security Policy from presets, see what browsers will really enforce, and copy it for nginx, Apache, Express or a meta tag.
Make random passwords in one click, with the strength in bits calculated from the settings and the time each would take to guess.
Design a CSS button with hover, pressed, focus and disabled states, each checked against WCAG contrast, and copy the CSS and HTML.
You host a small helper script on a CDN at a versioned address and want the page to refuse it if the file ever changes.
The file (104 bytes) and its address
// A tiny script to try the generator with.
export function greet(name) {
return `Hello, ${name}!`;
}
https://cdn.example.com/greeting@1.0.0/greeting.jsWhat the tool gives you
sha384-mw0H14J/8jPisTggh6syyaICXWC/P5nhYpb5uKtif/i4ixCVKjEAYer6udJf9qA9 <script src="https://cdn.example.com/greeting@1.0.0/greeting.js" integrity="sha384-mw0H14J/8jPisTggh6syyaICXWC/P5nhYpb5uKtif/i4ixCVKjEAYer6udJf9qA9" crossorigin="anonymous"></script> With all three algorithms on: sha256-I57EkQNbQzXGYc0O7rX1Biiw6LCnUNAxxX1MhJtlfyc= sha384-mw0H14J/8jPisTggh6syyaICXWC/P5nhYpb5uKtif/i4ixCVKjEAYer6udJf9qA9 sha512-oLBDskXGffgHRDL+JqkuxB0N3SwWNX/9l6GvDdeUui7tkki4A3Jdnkf3Ek3wTO50NBpGd+moYqrDCllGl+0eqQ==
The sha384 digest of these 104 bytes is 48 bytes long. In hex that is 96 characters starting 9b0d07d7; SRI writes the same bytes as 64 characters of standard base64 starting mw0H14J, which is exactly what openssl dgst -sha384 -binary greeting.js | openssl base64 -A prints. The element keeps crossorigin="anonymous" because the CDN is another origin, and the address names version 1.0.0 so the hash stays valid until you choose to upgrade. If you paste all three values into one attribute, a browser checks only the sha512 one, the strongest present.
Create the integrity attribute that stops a browser from running a script or stylesheet that has been changed. Drop in the file, fetch it by address or paste its contents, and copy a ready-made script or link element with the hash, your real address and the crossorigin attribute already in place. You can also paste an existing attribute to check it against a file.
What the attribute does. Subresource Integrity (SRI) lets a page say exactly which bytes it expects from a script or stylesheet hosted elsewhere, usually on a CDN. The browser downloads the file, hashes it, and refuses to use it if the hash is different. If the CDN is compromised, or the file is quietly replaced, the page breaks safely instead of running someone else's code. The value has a simple shape: the algorithm, a hyphen, and the raw digest in standard base64, as in sha384-mw0H14J/8jPisTggh6syya.... That is why it looks nothing like the hex string sha384sum prints, even though the digest is the same.
Getting the file in. Drop a file, choose one, or press Try a sample script. You can also paste the contents, which are hashed as UTF-8 as you type, or type the file's address and press Fetch. Fetching only works when the server lets other sites read the file (it sends an Access-Control-Allow-Origin header); many CDNs do, some do not. When the browser blocks the request, download the file and drop it in: the hash is identical. Whatever you do, the address you type goes into the generated element, so the result can be pasted straight into your page.
One hash or several. sha384 is the usual choice and the default. You can switch on sha256 and sha512 as well, and all chosen hashes go into one attribute. A browser only checks the strongest algorithm present, so adding a weaker hash beside a stronger one neither helps nor hurts. Several hashes of the same algorithm are useful in one situation: during a rolling deployment, one attribute can accept either the old or the new version of a file.
The element and its pitfalls. Choose a classic script, a module script, a stylesheet, or a preload link for a script or style. The crossorigin attribute is always included because integrity on a file from another origin needs a CORS request; without it the load fails with an error about CORS that never mentions integrity. The tool warns when the address is plain http (blocked as mixed content on an https page) and when you pick use-credentials, and reminds you that a preload must carry the same hash as the element that uses the file, and that the address must name a fixed version, never a moving tag such as @latest.
Checking an existing attribute. Switch to Check an attribute, add the file, and paste the attribute from your page. Each hash is listed with the one a browser actually checks marked, and the tool explains what is wrong with any that cannot work: base64url characters where standard base64 is required, a digest of the wrong length, or an algorithm such as sha1 or md5 that the specification does not allow. An attribute made only of those is ignored, and the browser then loads the file without checking it at all. Everything is computed in your browser and nothing is uploaded.
Download lib.min.js from the exact versioned address, drop it in, type the address and copy the script element. If the CDN ever serves different bytes, the browser refuses to run them.
Pick Preload (style) and then Stylesheet for the same file. Both elements carry the same hash, which is what the browser needs to reuse the preloaded file.
A legacy page carries integrity="sha1-...". The checker reports that sha1 is not an allowed algorithm, so the browser ignores the attribute and loads the script unchecked. Generate a sha384 value to replace it.
sha384 is the common choice and the one the specification's own examples use. sha256 and sha512 are equally valid. Listing several only matters for the strongest one, because that is the only one a browser checks.
A browser only checks integrity on a file from another origin when it fetched the file with CORS. The crossorigin attribute asks for that, and the server has to answer with Access-Control-Allow-Origin. Keep crossorigin="anonymous" in the element and make sure the CDN sends the header.
The page can only read a file from another site if that site allows it with an Access-Control-Allow-Origin header, and an http address cannot be read from an https page at all. Download the file and drop it in instead; the hash is the same.
It is the same digest written differently. sha384sum prints hexadecimal; SRI needs the raw bytes in standard base64. You can reproduce the value with openssl dgst -sha384 -binary FILE | openssl base64 -A.
Browsers ignore algorithms the specification does not list. If every hash in the attribute is unusable, the attribute counts as empty and the file loads without any check, which is worse than it looks. The checker flags this in red.
Yes. The hash pins exact bytes, so any change to the file, even a single space, needs a new value. That is also why the address should name a fixed version rather than a tag like @latest.
No. Hashing uses the browser's built-in cryptography and the file never leaves your device. Fetching an address downloads it straight into your browser.
File and pasted-code hashing happen entirely in your browser. URL mode fetches the file directly from the host you enter, so that host sees the request; the downloaded bytes are hashed locally.