为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

won't display svg's using csp and default-src 'none'

  • 4 个回答
  • 1 人有此问题
  • 8 次查看
  • 最后回复者为 thujal

more options

SVG's will not display in Firefox/mac since we've implemented a CSP that starts with default-src 'none'

We have published a proof of concept of this problem:

https://go-web.goodyear.portal.mccannbristol.co.uk/

The same website works fine in Firefox/Windows, and all other browsers. No amount of tweaking of the CSP header seems to allow SVG's to show, except if we remove the default-src 'none' directive. Full header is:

Content-Security-Policy "default-src 'none'; script-src 'self' https://www.google-analytics.com; connect-src 'self'; frame-src 'self' https://*.youtube.com https://*.youtube-nocookie.com https://*.doubleclick.net; object-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self' https://www.google-analytics.com https://stats.g.doubleclick.net; frame-ancestors 'self'"

SVG's will not display in Firefox/mac since we've implemented a CSP that starts with default-src 'none' We have published a proof of concept of this problem: https://go-web.goodyear.portal.mccannbristol.co.uk/ The same website works fine in Firefox/Windows, and all other browsers. No amount of tweaking of the CSP header seems to allow SVG's to show, except if we remove the default-src 'none' directive. Full header is: Content-Security-Policy "default-src 'none'; script-src 'self' https://www.google-analytics.com; connect-src 'self'; frame-src 'self' https://*.youtube.com https://*.youtube-nocookie.com https://*.doubleclick.net; object-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self' https://www.google-analytics.com https://stats.g.doubleclick.net; frame-ancestors 'self'"

所有回复 (4)

more options

thujal said

The same website works fine in Firefox/Windows

Not for me, I get this in the Web Console on Firefox 48.0.2/Windows:

Content Security Policy: The page's settings blocked the loading of a resource at https://go-web.goodyear.portal.mccannbristol.co.uk/a/svg/global.svg ("default-src 'none'").

(I get a bouncing span with no image in it in the Inspector.)

This implies that a more specific policy applicable to the image in the SVG element was not found. But... extensive searching has not turned up an explanation of what <svg><img></svg> <svg><use href="uri"></svg> requires.

In your CSP, this is the only other 'none', did you try:

object-src 'self';

由jscher2000 - Support Volunteer于修改

more options

Yes, we have tried object-src. In fact, we've kept adding the different src elements in a bid to make this work, but it does not. For example:

Header always set Content-Security-Policy "default-src 'none'; script-src 'self' https://www.google-analytics.com; connect-src 'self'; frame-src 'self' https://*.youtube.com https://*.youtube-nocookie.com https://*.doubleclick.net; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://www.google-analytics.com https://stats.g.doubleclick.net; object-src 'self'; font-src 'self'; media-src 'self'; child-src 'self'; plugin-types 'image/svg+xml'; frame-ancestors 'self'"

Does not work.

However, setting a default-src of self does indeed work:

Header always set Content-Security-Policy "default-src 'self'; script-src 'self' https://www.google-analytics.com; connect-src 'self'; frame-src 'self' https://*.youtube.com https://*.youtube-nocookie.com https://*.doubleclick.net; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://www.google-analytics.com https://stats.g.doubleclick.net;"

Checking [https://content-security-policy.com|h.../content-security-policy.com] and other documentation, it doesn't look like there are any more headers for us to try to bring these SVG's in, so I simply see no way to have SVGs work in FF on a site with Content-Security-Policy "default-src 'none'... Which can't be the case, can it? I must be missing something really obvious!

Oh, and apologies, it also does not work in FF / win, this was an error our on testers part!

more options

I had trouble figuring out which part of the source code applies different content policies to different content types. If you or someone with you can search it out, that might shed light on how svg is evaluated.

https://dxr.mozilla.org/mozilla-release/source/

Alternately, you could submit a new bug:

https://bugzilla.mozilla.org/enter_bug.cgi

more options