react-select: [V2] Request/Bug: Needs CSP Considerations
We use a pretty strict CSP which doesn’t allow unsafe-inline for style-src. Therefore, when we try to use react-select we get the following errors (and an un-styled react-select component):
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.
Unfortunately this is blocking us from using this wonderful component!
I noticed this old issue: https://github.com/JedWatson/react-select/issues/2030, but the props autosize and inputProps have been removed in v2.
EDIT: It looks maybe the best way to add support for this is by using create-emotion which includes the ability to use a single <style> tag with a nonce attribute?
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 20
- Comments: 18
Commits related to this issue
- Add CSP Nonce option to Select component Closes #2917 — committed to wearereasonablepeople/react-select by Avaq 6 years ago
- Add CSP Nonce option to Select component Closes #2917 — committed to wearereasonablepeople/react-select by Avaq 6 years ago
- Add CSP Nonce option to Select component Closes #2917 — committed to wearereasonablepeople/react-select by Avaq 6 years ago
- Add CSP Nonce option to Select component Closes #2917 — committed to wearereasonablepeople/react-select by Avaq 6 years ago
- fix: lax helmet csp config for styles. Required to support react-selct, see https://github.com/JedWatson/react-select/issues/2917 — committed to Unleash/unleash by ivarconr 4 years ago
Hi! My concerns were:
Hi, Im using Creatable in a project, and its not clear to me how to set/pass a nonce to react-select. Is there any documentation regarding this? Or maybe its possible to disable injecting CSS?
A solution on how to provide a nonce to
react-selecthas already been mentioned in a newer issue https://github.com/JedWatson/react-select/issues/4631#issuecomment-999483078.To provide a nonce you must use
CacheProviderandcreateCachefromemotion(the CSS-in-JS library used). It is recommended to place theCacheProviderat the root of your application, to cover every instance of theSelectcomponent available.Yep,
emotiondoes have support for CSP nonces, butreact-selectwill have to surface that option to be passed toemotion.I’m also looking for updates on this issue aged of 3 years and a half.
Took a little time yesterday to try and circumvent. Solved the
inputPropsissue (gettinginjectStyles={false}onto theAutosizeInputvia “replacing” the component, with no visual change.Verifying with a Jest Snapshot…(a lot of stuff deleted for simplicity)
However, that was not enough as you mentioned (my csp prevents
unsafe-inlineas well. There’s still a<style data-emotion></style>tag injected in the<head>).