Intermediate LevelWeb Security & Cyber Defense
What is Subresource Integrity (SRI) and how do integrity attributes secure CDN scripts?
❓ Interview Prompt: Explain Subresource Integrity (SRI), base64-encoded cryptographic hashes (`sha384-...`), CDN compromise defense, and `crossorigin` attribute.
Subresource Integrity (SRI) is a browser security feature that verifies files fetched from third-party CDNs have not been tampered with or infected with malware:
How SRI Works:
1
Include the 'integrity' attribute on '<script>' or '<link>' tags containing the base64 cryptographic hash of the expected file.
2
Before executing the script, the browser computes the file's hash locally.
3
If the computed hash does not match the 'integrity' attribute, the browser blocks script execution immediately!
Code Implementation Example
html
<!-- Subresource Integrity (SRI) protected CDN script -->
<script
src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
crossorigin="anonymous"
></script>💡Embedding Subresource Integrity (SRI) hashes on external CDN script tags.
🎯 Interview Key Takeaway
Use Subresource Integrity (SRI) hashes on CDN scripts to ensure third-party CDN compromises cannot inject malicious scripts.
#SRI#Subresource Integrity#CDN Security#Intermediate
Back to all Web Security & Cyber Defense Questions→