Unverified Commit ec11c862 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

docs: fix CSP example to only include unsafe-eval in development (#88407)

## What

Fixes the CSP documentation "Without Nonces" example to only include
`'unsafe-eval'` in development mode.

## Why

The example was showing `'unsafe-eval'` without a development check,
which would cause it to be shipped to production. This is inconsistent
with the guidance in the "Development vs Production Considerations"
section which correctly shows how to conditionally add `'unsafe-eval'`
only in development.

## How

Added a `isDev` check using `process.env.NODE_ENV === 'development'` and
conditionally includes `'unsafe-eval'` in the `script-src` directive
only when in development mode.
parent 38ac0353
...@@ -415,9 +415,11 @@ Consider nonces when: ...@@ -415,9 +415,11 @@ Consider nonces when:
For applications that do not require nonces, you can set the CSP header directly in your [`next.config.js`](/docs/app/api-reference/config/next-config-js) file: For applications that do not require nonces, you can set the CSP header directly in your [`next.config.js`](/docs/app/api-reference/config/next-config-js) file:
```js filename="next.config.js" ```js filename="next.config.js"
const isDev = process.env.NODE_ENV === 'development'
const cspHeader = ` const cspHeader = `
default-src 'self'; default-src 'self';
script-src 'self' 'unsafe-eval' 'unsafe-inline'; script-src 'self' 'unsafe-inline'${isDev ? " 'unsafe-eval'" : ''};
style-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';
img-src 'self' blob: data:; img-src 'self' blob: data:;
font-src 'self'; font-src 'self';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment