Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content Security Policy: Replace the inline background images #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zepich
Copy link

@zepich zepich commented May 14, 2023

To use the Spectrum Color Picker on a website with a Content Security Policy header, the use of data: URIs in the CSS code is only allowed if the header contains the param data:.

While it's not that problematic compared to the unsafe-inline from pull request #41, it's still an insecure param, and you do not want it in your CSP header.

The solution for this is to use no data: URIs. A possible solution is to use an SVG sprite to have the background images with the best performance. This combines all SVGs into one file, but it's still possible to use the background image like before.

I've extracted the SVGs from the data: URIs and added them as files in the src/icons directory. Additionally, I've added grunt-svg-sprite as a dev dependency and added a new task build-sprite to combine the single SVGs into the sprite.

After that, I replaced the data: URIs in the CSS file to use the new SVG sprite.

Personal Note:
I've split these two CSP fixes into two pull requests because Spectrum does not require this one directly. I can overwrite the CSS rules in my project directly and solve it that way. It is impossible to do that with the JavaScript code without copying the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant