Skip to content

SVG Symbols violate strict CSP style-src directives #16827

@mikelkew

Description

@mikelkew

Describe the bug
When using SVG symbols (using data-fa-symbol) with the NPM package, inline styling is added here to hide the SVG symbol. However, with a strict Content Security Policy that doesn't include unsafe-inline for the style-src directive, the inline styles are rejected. This results in a CSP violation being reposted, and the SVG symbols not being correctly hidden.

To Reproduce
Set a CSP header of Content-Security-Policy: default-src 'self'; style-src 'self' and then try to use the SVG symbol feature.

Expected behavior
I suppose the best approach would be to add a css class to the symbol instead of the inline style here and add that class in styles.css. For those that haven't disabled config.autoAddCss, this should still work fine, and for those that have, at least it will provide a class that can be styled manually in the page CSS.

Screenshots
Example of rejected inline style and CSP violation:
Screenshot 2020-06-24 21 54 24

Version and implementation
Version: @fortawesome/fontawesome-svg-core@^1.2.28

  • SVG with JS
  • Web Fonts with CSS
  • SVG Sprites
  • On the Desktop

Bug report checklist

  • I have filled out as much of the above information as I can
  • I have included a test case because my odds go way up that the team can fix this when I do
  • I have searched for existing issues and to the best of my knowledge this is not a duplicate

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions