Skip to content

Commit

Permalink
docs: Add section for CSP without nonces (#60067)
Browse files Browse the repository at this point in the history
  • Loading branch information
leerob authored Dec 31, 2023
1 parent ff45e1f commit 64e9051
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,42 @@ export default function Page() {
}
```

## Without Nonces

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:

```js filename="next.config.js"
const cspHeader = `
default-src 'self';
script-src 'self' 'unsafe-eval' 'unsafe-inline';
style-src 'self' 'unsafe-inline';
img-src 'self' blob: data:;
font-src 'self';
object-src 'none';
base-uri 'self';
form-action 'self';
frame-ancestors 'none';
block-all-mixed-content;
upgrade-insecure-requests;
`

module.exports = {
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: cspHeader.replace(/\n/g, ''),
},
],
},
]
},
}
```

## Version History

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

0 comments on commit 64e9051

Please sign in to comment.