Overview
Subresource Integrity (SRI) enables browsers to verify that resources they fetch are delivered without unexpected manipulation. It works by allowing you to provide a cryptographic hash that the fetched resource must match. SRI matters because it offers protection against malicious tampering. If an attacker exploited a content delivery network (CDN) and modified the contents of JavaScript libraries hosted on that CDN, it would create vulnerabilities in all websites that use those libraries. SRI helps prevent attacks like cross-site scripting (XSS) by ensuring that the resources delivered to your site are exactly what they should be.How SRI Prevents MITM Attacks
SRI provides cryptographic protection against man-in-the-middle attacks:- Hash verification - The browser computes a SHA384 hash of the downloaded script
- Integrity check - If the hash doesn’t match the
integrityattribute, the browser refuses to execute the script - Tamper detection - Any modification in transit (MITM) or at rest (CDN compromise) is detected
How to Enable SRI
Formo supports SRI integration, providing an additional layer of security for your data and users. Enable SRI on the browser install snippet by updating thesrc and integrity fields:
Get the latest version number and integrity hash on GitHub.
This snippet has no inline code, so it also works under a strict Content Security Policy that allows
cdn.formo.so. With nonces or 'strict-dynamic', also add your nonce to the tag. If you start the SDK with an inline onload attribute instead, CSP blocks it unless you allow 'unsafe-inline'.Verifying the Integrity Hash
You can independently verify the SRI hash using the following methods: Using OpenSSL (macOS/Linux):Combined Protection with CSP
For maximum security, combine SRI with Content Security Policy. When both are enabled:- CSP restricts where scripts can load from and where data can be sent
- SRI ensures the loaded script hasn’t been tampered with
- TLS 1.2+ encrypts all traffic in transit