Lab 14: Security & CSP
Overview
Step 1: Content-Security-Policy Fundamentals
CSP style-src directive controls which CSS can execute:
INSECURE (allows any inline styles):
Content-Security-Policy: style-src 'self' 'unsafe-inline'
SECURE (hash-based inline):
Content-Security-Policy: style-src 'self' 'sha256-<hash>'
SECURE (nonce-based inline):
Content-Security-Policy: style-src 'self' 'nonce-<random>'
SECURE (no inline at all):
Content-Security-Policy: style-src 'self'
Level of restriction (weakest → strongest):
unsafe-inline → nonce → hash → 'self' only → noneStep 2: Nonce-Based CSP
Step 3: Hash-Based CSP
Step 4: CSS Injection Attacks
Step 5: CSS Exfiltration Attacks
Step 6: Subresource Integrity (SRI)
Step 7: Complete CSP Header Strategy
Step 8: Capstone — CSP Hash Generator
Summary
Attack Vector
Risk
Mitigation
Last updated
