Content-Security-Policy: default-src directive - HTTP | MDN (original) (raw)

**Note:**This issue was fixed in Firefox 132; see bug 1773976.

When creating a CSP, you can start with default-src 'none' to lock down all resource loading and then add further directives to open up the policy, allowing you to load just the resources you need. For example, to allow same-origin loading of images only:

Content-Security-Policy: default-src 'none'; img-src 'self'

However, there is a problem here. If you are embedding SVG sprites defined in external files via the element, for example:

<svg>
  <use href="/images/icons.svg#icon"/>
</svg>

your SVG images will be blocked in Firefox if you have a default-src 'none' policy set. Firefox does not treat the SVG as an embedded image like other browsers do, therefore img-src 'self' will not allow them to be loaded. You need to use default-src 'self' if you want your external sprites to load in Firefox.

Alternatively, if the default-src 'none' policy is a hard requirement, you can include the SVG sprites inline in the HTML page:

<body>
  <svg style="display: none">
    <symbol id="icon" viewBox="0 0 24 24">
      <path d="…" />
    </symbol>
  </svg>
  …
  <svg>
    <use href="#icon" />
  </svg>
</body>