# Example app with strict CSP generating script hash
This example features how you can set up a strict CSP for your pages whitelisting next's inline bootstrap script by hash.
In contrast to the example `with-strict-csp` based on nonces, this way doesn't require running a server to generate fresh nonce values on every document request.
It defines the CSP by document `meta` tag.
Note: There are still valid cases for using a nonce in case you need to inline scripts or styles for which calculating a hash is not feasible.
## Deploy your own
Deploy the example using [Vercel](https://vercel.com):
[](https://vercel.com/import/project?template=https://github.com/zeit/next.js/tree/canary/examples/with-strict-csp-hash)
## How to use
### Using `create-next-app`
Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example)([Documentation](https://nextjs.org/docs/deployment)).
This example was moved to [with-strict-csp](https://github.com/zeit/next.js/tree/canary/examples/with-strict-csp)
# Example app with strict CSP generating script hash
If you want to implement a CSP, the most effective way is to follow the [strict CSP](https://csp.withgoogle.com/docs/strict-csp.html) approach. For it to work, we need to generate a nonce on every request.
This example features how you can set up a strict CSP for your pages including Next.js' inline bootstrap script by hash.
It defines the CSP by document `meta` tag.
This example uses [Helmet](https://github.com/helmetjs/helmet) to configure the CSP and add the appropriate headers to all server responses. The nonce is generated with [uuid](https://github.com/kelektiv/node-uuid). Then we can pass the nonce to `<Head>` and `<NextScript>` in the custom `<Document>`.
Note: There are still valid cases for using a nonce in case you need to inline scripts or styles for which calculating a hash is not feasible.
## Deploy your own
Deploy the example using [Vercel](https://vercel.com):
[](https://vercel.com/import/project?template=https://github.com/zeit/next.js/tree/canary/examples/with-strict-csp-hash)
## How to use
...
...
@@ -11,9 +18,9 @@ This example uses [Helmet](https://github.com/helmetjs/helmet) to configure the
Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: