I have a React App using Create-React-App (react-scripts) and Material-UI. I would like to apply a strong Content-Security-Policy for my app which does not allow unsafe inline styles.
I would like to set the CSP-Header server-side with a nonce present which can be done easily. However, Material-UI sets certain inline <style>
tags dynamically at runtime without a nonce value as attribute.
I´ve seen the documentation on the Material-UI website under guides and csp. They seem to provide a solution. However, that solution is for server-side-rendering of the HTML, which I am not using. I am using Create-React-App and deliver the HTML, CSS and JavaScript statically.
Does anyone know how that can be achieved?
<meta property="csp-nonce" content="123456" />
in the<head>
element as described on the Material-UI website under guides and csp, but the new<style>
element that are added at runtime in the browser do not include the nonce, but look like this:<style type="text/css" data-jss data-meta-"MuiInputLabel" nonce>
. The nonce attribute is there in the '<style>' tag but it has no value. Could anyone solve that? – Stefanindex.html
if you are only serving your site statically? – Saad