Skip to content

Add documentation to cover Firefox CSP SVG sprite blocking issue#34592

Merged
chrisdavidmills merged 2 commits intomdn:mainfrom
chrisdavidmills:svg-csp-default-src
Jul 3, 2024
Merged

Add documentation to cover Firefox CSP SVG sprite blocking issue#34592
chrisdavidmills merged 2 commits intomdn:mainfrom
chrisdavidmills:svg-csp-default-src

Conversation

@chrisdavidmills
Copy link
Contributor

Description

This PR adds documentation covering the Firefox CSP default-src 'none' SVG sprite blocking issue, documented by @pepelsbey at mdn/mdn-http-observatory#6.

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills chrisdavidmills requested review from a team as code owners July 3, 2024 10:23
@chrisdavidmills chrisdavidmills requested review from a team and teoli2003 and removed request for a team and teoli2003 July 3, 2024 10:23
@github-actions github-actions bot added Content:HTTP HTTP docs Content:Security Security docs labels Jul 3, 2024
@chrisdavidmills chrisdavidmills requested review from pepelsbey and removed request for teoli2003 July 3, 2024 10:23
@github-actions github-actions bot added the size/s [PR only] 6-50 LoC changed label Jul 3, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2024

Preview URLs

External URLs (4)

URL: /en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src
Title: CSP: default-src


URL: /en-US/docs/Web/Security/Practical_implementation_guides/CSP
Title: Content Security Policy (CSP) implementation

(comment last updated: 2024-07-03 11:30:33)

Copy link
Member

@pepelsbey pepelsbey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I also double-checked how Firefox treats inlined sprites: it works! It might be an alternative solution if default-src 'none' is essential to keep. What do you think?

</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. See [bug 1773976](https://bugzilla.mozilla.org/show_bug.cgi?id=1773976) and [this CSP spec issue](https://github.com/w3c/webappsec-csp/issues/199) for more information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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. See [bug 1773976](https://bugzilla.mozilla.org/show_bug.cgi?id=1773976) and [this CSP spec issue](https://github.com/w3c/webappsec-csp/issues/199) for more information.
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, you can inline the external sprite in the HTML page. See [bug 1773976](https://bugzilla.mozilla.org/show_bug.cgi?id=1773976) and [this CSP spec issue](https://github.com/w3c/webappsec-csp/issues/199) for more information.

</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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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, you can inline the external sprite in the HTML page:
```html
<body>
<svg style="display: none">
<symbol id="icon" viewBox="0 0 24 24">
<path d="…"/>
</symbol>
</svg>
<svg>
<use href="#icon"/>
</svg>
</body>
```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pepelsbey, this is great information. I have added it, but with slightly different wording/structure. My reasons:

  1. If we refer to external sprites being inlined, then I reckon people will nitpick that they are no longer external.
  2. I wanted to keep the bug/spec issue links attached to the bit about default-src 'none' not working with external SVG sprites specifically.

Let me know if you think my additions read ok.

@github-actions github-actions bot added size/m [PR only] 51-500 LoC changed and removed size/s [PR only] 6-50 LoC changed labels Jul 3, 2024
@chrisdavidmills chrisdavidmills requested a review from pepelsbey July 3, 2024 11:33
Copy link
Member

@pepelsbey pepelsbey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

@chrisdavidmills chrisdavidmills merged commit c6b08a2 into mdn:main Jul 3, 2024
@chrisdavidmills chrisdavidmills deleted the svg-csp-default-src branch July 3, 2024 12:04
@chrisdavidmills
Copy link
Contributor Author

Awesome, I've put it live, as I don't think there is any point waiting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:HTTP HTTP docs Content:Security Security docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants