QA
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→

More Web Security & Cyber Defense Interview Questions

Beginner LevelSecurity & Web Security

Explain OWASP Top 10 vulnerabilities (XSS, CSRF, SQL Injection) and their defenses.

Beginner LevelSecurity & Web Security

What are the 3 types of XSS (Stored, Reflected, DOM-based) and how do they differ?

Beginner LevelSecurity & Web Security

How do Parameterized Queries (Prepared Statements) prevent SQL Injection attacks?