Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

The browser refuses to load a font because of your Content Security Policy

ErrorRefused to load the font 'data:font/woff;base64,...' because it violates the following Content Security Policy directive: "default-src 'self'".

Short answer

A font is blocked when the font-src directive, or default-src when font-src is missing, does not allow where the font comes from. For a data: font add data: to font-src. For a CDN font, add that host or self-host the font with next/font. Test the new policy in report-only mode first.

  • Applies to Next.js 15, Next.js 16, Chrome, Firefox
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the policy your server really sends, then find the font directive. If there is no font-src, default-src decides.

    curl -sI https://example.com/ | grep -i content-security-policy
  2. 2Match what you see, then jump to its fix

    1. 1Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.No font-src, so default-src 'self' decidesFix
    2. 2The blocked URL in the message starts with data:font/.The font is inlined as a data: URI and data: is not allowedFix
    3. 3The blocked URL is an https:// font file on another host, for example a CDN.The font comes from an external hostFix

What does the error look like?

  • Refused to load the font 'data:font/woff;base64,...' because it violates the following Content Security Policy directive: "default-src 'self'".
  • Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.

Cause 1 of 3

No font-src, so default-src 'self' decides

1Check

MDN states that font-src falls back to default-src when it is absent. A policy of default-src 'self' therefore allows only fonts from your own origin.

curl -sI https://example.com/ | grep -i content-security-policy | tr ';' '\n' | grep -i -E "default-src|font-src"

2Fix

Add an explicit font-src directive that lists the sources you really use. The Next.js CSP guide uses font-src 'self' in its starting policy.

// next.config.js
const csp = `
  default-src 'self';
  font-src 'self';
`
module.exports = {
  async headers() {
    return [{ source: '/(.*)', headers: [
      { key: 'Content-Security-Policy', value: csp.replace(/\n/g, '') },
    ] }]
  },
}

3Verify

Reload and check the response header lists font-src.

curl -sI http://localhost:3000/ | grep -i content-security-policy

Confirmed by developer.mozilla.org

Did this fix it?

Cause 2 of 3

The font is inlined as a data: URI and data: is not allowed

1Check

A data: URI is its own scheme, so 'self' does not cover it. font-src accepts scheme sources, so data: can be listed.

curl -s https://example.com/ | grep -o "data:font[^;]*;" | head -3

2Fix

Add data: to font-src, or build the font as a normal file so it is served from your own origin.

font-src 'self' data:;

3Verify

Hard-reload with the console open: the Refused to load the font line should be gone.

curl -sI http://localhost:3000/ | grep -i "font-src"

Confirmed by developer.mozilla.org

Did this fix it?

Cause 3 of 3

The font comes from an external host

1Check

A host-source in font-src must match the host of the font file. A font from a host not listed is blocked, as the MDN example shows.

grep -rn "fonts.googleapis\|fonts.gstatic\|@font-face" app src styles 2>/dev/null | head

2Fix

Preferably self-host: next/font downloads Google Fonts at build time and serves them from your own domain, so 'self' is enough. Otherwise add the font host to font-src.

// app/layout.tsx
import { Geist } from 'next/font/google'
const geist = Geist({ subsets: ['latin'] })
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return <html lang="en" className={geist.className}><body>{children}</body></html>
}

3Verify

Open the network tab: the font file should load from your own origin.

npm run build && npm run start

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Ship a new policy as Content-Security-Policy-Report-Only first, then enforce it when the reports are clean.
  • Write font-src explicitly instead of leaning on default-src.
  • Use next/font so fonts stay on your own origin.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Security

The browser blocks a script because of your Content Security Policy

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

The page's Content-Security-Policy does not allow what it tried to run or load.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.