Using React on Rails with CSP and nonce #1751
Replies: 4 comments 3 replies
-
|
The ReactOnRails script itself doesn't need a nonce if you're able to use If you really need a nonce, then I believe the html_options parameter should satisfy your needs. Side Note: You can also give the nonce to the component as a prop, which may be necessary for resolving CSP violations by certain CSS-in-JS & animation libraries. (I remember forking |
Beta Was this translation helpful? Give feedback.
-
|
Hi @joshuacronemeyer, I saw you're using React on Rails at https://app.trucentive.com/users/sign_up. Cool! Feel free to book a time with me if you think my team and I can help further: https://meetings.hubspot.com/justingordon/30-minute-consultation. |
Beta Was this translation helpful? Give feedback.
-
|
Is there a way to add a nonce attribute to the script tag which react on rails generates? In my project I'm seeing script tags like this: Which are causing CSP console errors like this: I do have the recommended policy |
Beta Was this translation helpful? Give feedback.
-
|
Hey Tony, I never figured this out and we stopped using react on rails for the part of the application that needed to have CSP enabled. Also it's worth noting that for our requirements just allowing ANY https: script src was not secure enough. We needed to only allow specific domains in order to satisfy our security audits. If you do come up with a solution to get react on rails to include the nonce please update here. I'd really appreciate it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I've been unable to find any docs about how to use react on rails when our server has a CSP setup. I believe that the initial script tag that react on rails renders needs to include the nonce. Can you help me figure out how to add the nonce attribute to the react on rails script tag?
Here is the rails guide for CSP/nonce configuration. https://guides.rubyonrails.org/security.html#adding-a-nonce
Thanks in advance,
Josh Cronemeyer
Beta Was this translation helpful? Give feedback.
All reactions