The font-src Directive
You'll learn how to control which fonts your website loads to prevent unauthorized tracking and ensure only trusted typography resources are used.
What It Is
The font-src directive in your Content Security Policy tells the browser which servers are allowed to deliver web fonts to your page. Just like script-src controls JavaScript sources and style-src controls stylesheets, font-src guards the fonts that can be loaded.
Why It Matters
Web fonts aren't just about design—they can be exploited for fingerprinting (tracking users by their unique font rendering) and as a potential data exfiltration vector. By restricting font sources, you ensure only legitimate font providers can load resources into your page.
Think of it like a doorman at a typography shop: only approved font vendors get through.
How to Use It
Add font-src to your CSP header with allowed sources:
Content-Security-Policy: font-src 'self' https://fonts.gstatic.com
This allows fonts from your own domain ('self') and Google Fonts' CDN.
Common Patterns
Only local fonts:
font-src 'self'
Google Fonts:
font-src 'self' https://fonts.gstatic.com
Multiple CDNs:
font-src 'self' https://fonts.gstatic.com https://use.typekit.net
The Fingerprinting Risk
Attackers can detect which fonts a user has installed by attempting to load system fonts and measuring rendering differences. A strict font-src policy prevents unauthorized font-probing scripts from loading external fonts for this purpose.
Key Takeaway: Use font-src to whitelist only trusted font providers, protecting users from font-based tracking while ensuring your typography loads correctly from approved sources.