Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update nonce docs about unsafe-inline during development #240

Merged
merged 1 commit into from Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions docs/content/1.documentation/2.headers/1.csp.md
Expand Up @@ -160,10 +160,15 @@ export default defineNuxtConfig({
nonce: true,
headers: {
contentSecurityPolicy: {
'style-src': [
"'self'", // fallback value for older browsers, automatically removed if `strict-dynamic` is supported.
"'nonce-{{nonce}}'",
],
'style-src':
process.env.NODE_ENV === 'production'
? [
"'self'", // backwards compatibility for older browsers that don't support strict-dynamic
"'nonce-{{nonce}}'",
"'strict-dynamic'",
]
: // In dev mode, we allow unsafe-inline so that hot reloading keeps working
["'self'", "'unsafe-inline'"],
'script-src': [
"'self'", // fallback value for older browsers, automatically removed if `strict-dynamic` is supported.
"'nonce-{{nonce}}'",
Expand All @@ -181,6 +186,8 @@ export default defineNuxtConfig({
```

This will add a `nonce` attribute to all `<script>`, `<link>` and `<style>` tags in your application.
Note that to allow hot reloading during development, we conditionally add `'unsafe-inline'` to the `style-src` value.

The `nonce` value is generated per request and is added to the CSP header. This behaviour can be tweaked on a route level by using the `routeRules` option:

```ts
Expand Down