The frame-src and child-src Directives
You'll learn how to control which websites can be embedded in your pages using frame-src and child-src CSP directives.
Why These Directives Matter
Think of your website as a gallery wall where you can hang frames (iframes) showing content from other sites. Without rules, anyone could slip a malicious frame onto your wall—perhaps one that tricks users into clicking (clickjacking) or displays harmful content. The frame-src and child-src directives are your bouncers, deciding which frames are allowed in.
The Core Difference
frame-src specifically controls <iframe> and <frame> elements—where your page loads external content.
child-src is broader, covering iframes plus web workers. However, many modern browsers now treat frame-src as the preferred directive for frames, with child-src mainly applying to workers.
How They Work
Set these in your CSP header to whitelist trusted sources:
Content-Security-Policy: frame-src 'self' https://trusted-embed.com
This allows iframes from your own domain and trusted-embed.com only. Any other iframe source will be blocked.
Common patterns:
frame-src 'none'— Block all iframes (strictest)frame-src 'self'— Only same-origin iframesframe-src https://youtube.com https://vimeo.com— Whitelist specific embeds
Preventing Attacks
By restricting iframe sources, you prevent attackers from injecting malicious frames that could:
- Overlay invisible clickable elements (clickjacking)
- Load phishing pages disguised as legitimate content
- Embed ads or trackers you didn't authorize
Key Takeaway: Use frame-src to whitelist only the iframe sources you trust, preventing clickjacking and malicious embedded content while maintaining control over what appears within your pages.