CSP enabled DevTool show errors (insert inline style) #3495
Send to my agentDescribe the bug#
When CSP enabled, (Style-SRC='xxx')
the console error
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' 'nonce-0mihlgp7' 'report-sample'
Your minimal, reproducible example#
https://codesandbox.io/s/heuristic-cannon-it3v0r?file=/public/index.html
Steps to reproduce#
- start the app
- open the app in single window
- open the console and refresh
Expected behavior#
No errors or passing the nonce as params
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
Browsers
react-query version#
3.34.19
TypeScript version#
No response
Additional context#
No response
TkDodo added labelspackage: react-query-devtools
I found that
styletag was injected here. We can pass the nonce as a parameter or use the popular global var.- as parameter
<ReactQueryDevtools styleNonce={'string'} />- global var, such as
__webpack_nonce__
<style nonce={__webpack_nonce__}oh, I misunderstood the issue then. I wasn't aware that we are injecting a style tag 🤔 . I would like to get rid of this actually, but not sure how. We can't use inline styles if we want to target all containers inside
ReactQueryDevtoolsPanel, and if we extract it to a separate css file, users must import / bundle it.or, we create a separate css file and import it. but will that work for all consumers?
scoped styleis the most compatible solution for chromium browsers. CSS files are dependent on Webpack/Babel loaders.I preferred
scoped stylewith thenonceattribute,okay, would you like to contribute an optional
nonceprop for the devtools?TkDodo closed this
:tada: This issue has been resolved in version 3.36.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
tannerlinsley added labelsreleased
:tada: This issue has been resolved in version 4.0.0-beta.4 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
tannerlinsley added labelsreleased on @beta
Sign in to join this conversation.
not sure what to do here except to re-write the devtools to not use inline styles. any css-in-js lib would need some help for CSPs to be able to inject
styletags in the head, so would need to switch to something else. Since the devtools are meant for development mode and not production, my suggestion would be to relax the CSP on localhost. Do you have any other suggestions?