Skip to content

Commit 64e9051

Browse files
authored
docs: Add section for CSP without nonces (#60067)
1 parent ff45e1f commit 64e9051

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/02-app/01-building-your-application/07-configuring/15-content-security-policy.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,42 @@ export default function Page() {
209209
}
210210
```
211211

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+
const cspHeader = `
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+
async headers() {
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+
212248
## Version History
213249

214250
We recommend using `v13.4.20+` of Next.js to properly handle and apply nonces.

0 commit comments

Comments
 (0)