You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The addon uses express middleware to generate a unique nonce for each request, but the nonce must be added to the Redux store *after* the store is created in the route handler. This ensures the nonce is available to the `Html` component during server-side rendering.
45
+
23
46
## Basic Usage
24
47
25
48
This addon is enabled by setting one or more of the `RAZZLE_CSP_...` headers.
@@ -52,6 +75,31 @@ Volto includes a number of inline scripts. Good practice is to not use the `unsa
52
75
53
76
If `RAZZLE_CSP_DEFAULT_SRC` is set and no value for `RAZZLE_CSP_SCRIPT_SRC` is set. Then the addon will add the `script-src` directive as a duplicate of the `default-src` with the hashed inline scripts added.
54
77
78
+
## Nonce Support
79
+
80
+
This addon automatically generates a unique cryptographic nonce for each request and includes it in the CSP header. The nonce is available through:
81
+
82
+
### Redux Store
83
+
84
+
The nonce is added to the Redux store via the `SET_CSP_NONCE` action and can be accessed at `state.csp.nonce`. This allows components to access the nonce during server-side rendering.
85
+
86
+
### Environment Variable
87
+
88
+
To enable nonce attributes on script and style tags, set:
89
+
90
+
```
91
+
RAZZLE_CSP_SET_NONCE=true
92
+
```
93
+
94
+
When enabled, the nonce will be:
95
+
- Automatically added to the CSP header as `'nonce-<value>'`
96
+
- Available via `window.__webpack_nonce__` for webpack's style-loader
97
+
- Included in script and style tags during server-side rendering
98
+
99
+
### Development Mode Support
100
+
101
+
In development mode, this addon includes a patched version of webpack's style-loader runtime that properly reads the nonce from `window.__webpack_nonce__`, ensuring dynamically injected `<style>` tags include the nonce attribute.
102
+
55
103
## Critical CSS
56
104
57
105
Volto allows you to automatically include [critical css](https://2022.training.plone.org/effective-volto/development/criticalCSS.html) as inline styles.
0 commit comments