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
Copy file name to clipboardExpand all lines: docs/02-app/01-building-your-application/07-configuring/15-content-security-policy.mdx
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,6 +209,42 @@ export default function Page() {
209
209
}
210
210
```
211
211
212
+
## Without Nonces
213
+
214
+
For applications that do not require nonces, you can set the CSP header directly in your [`next.config.js`](/docs/app/api-reference/next-config-js) file:
215
+
216
+
```js filename="next.config.js"
217
+
constcspHeader=`
218
+
default-src 'self';
219
+
script-src 'self' 'unsafe-eval' 'unsafe-inline';
220
+
style-src 'self' 'unsafe-inline';
221
+
img-src 'self' blob: data:;
222
+
font-src 'self';
223
+
object-src 'none';
224
+
base-uri 'self';
225
+
form-action 'self';
226
+
frame-ancestors 'none';
227
+
block-all-mixed-content;
228
+
upgrade-insecure-requests;
229
+
`
230
+
231
+
module.exports= {
232
+
asyncheaders() {
233
+
return [
234
+
{
235
+
source:'/(.*)',
236
+
headers: [
237
+
{
238
+
key:'Content-Security-Policy',
239
+
value:cspHeader.replace(/\n/g, ''),
240
+
},
241
+
],
242
+
},
243
+
]
244
+
},
245
+
}
246
+
```
247
+
212
248
## Version History
213
249
214
250
We recommend using `v13.4.20+` of Next.js to properly handle and apply nonces.
0 commit comments