question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Make vanilla-picker work with strict CSP header

See original GitHub issue

Hi! We are trying to migrate to a stricter Content-Security-Policy header. However, this currently does not work with vanilla-picker. The header we want to enforce is as follows:

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

This header causes dynamically injected <style> elements to no longer work. They will be ignored and produce an error. Example in Chrome:

Refused to apply inline style because it violates the following Content Security Policy directive: "default-src 'self'". [...]
./node_modules/vanilla-picker/dist/vanilla-picker.mjs @ vanilla-picker.mjs:504

The way to fix this could be to add a new option externalCss: true somewhere, which would prevent the dynamic <style> injection. Additionally the user would have to manually import the CSS file using a <link> element, or bundling it in webpack.

Note that directly applying styles to an element is not affected by this, e.g. uiSL.style.color = ... still works fine.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jlherrencommented, Oct 29, 2021

Works perfectly now! Many thanks! ❤️

0reactions
Sphinxxxxcommented, Oct 28, 2021

Ok, we’re getting closer 😃 Try v2.12.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strict CSP - Content Security Policy
Strict CSP. Content Security Policy can help protect your application from XSS, but in order for it to be effective you need to...
Read more >
Inline styles in Next 10 don't work with strict Content-Security ...
Create a Content-Security-Policy header in next.config.js with style-src: 'self'; (i.e. without unsafe-inline explicitly enabled) ...
Read more >
Content Security Policy - OWASP Cheat Sheet Series
Using a header is the preferred way and supports the full CSP feature set. Send it in all HTTP responses, not just the...
Read more >
How to protect PHP application from XSS attacks: CSP 3 nonce
Set the same string as a value to the Content-Security-Policy HTTP header. 1. Generate a random nonce string on each request. Let's create...
Read more >
CSP: script-src - HTTP - MDN Web Docs - Mozilla
Alternatively, you can create hashes from your inline scripts. CSP supports sha256, sha384 and sha512. Content-Security-Policy: script-src ' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found