My challenge with using next js is the occurrence of Content-Security-Policy issues due to the inline styles it utilizes.
If 'unsafe-inline' is not added to the style-src, you will encounter the error message 'Refused to apply inline style because it violates the following Content Security Policy directive.'
However, allowing 'unsafe-inline' poses security risks that we want to avoid.
Some related problems and discussions on this matter include:
In my case of server-side rendering, the recommended solution involves implementing a CSP in the response header and adding a nonce to the document. For example:
Sample code snippet here...
The drawback of this approach is that having getInitialProps in my _app file means that the getInitialProps at the _document level won't be called.
I can generate the CSP and nonce in the _app's getInitialProps but accessing the nonce in the _document becomes problematic.
Different code snippet here...
As removing getInitialProps from _app would disrupt the application flow, I am exploring ways to share properties between _app and _document or seeking alternative solutions to resolve the CSP issues effectively.