You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/content/1.documentation/5.advanced/3.strict-csp.md
+2-66
Original file line number
Diff line number
Diff line change
@@ -732,70 +732,6 @@ From an application design perspective, it is simpler to use a single Strict CSP
732
732
733
733
In order to obtain a Strict CSP on Nuxt apps, we need to use `strict-dynamic`. This mode disallows the ability for scripts to insert inline styles, and cancels the ability to whitelist external resources by name. In conjunction with the fact that nonces and hashes disable the `'unsafe-inline'` mode, this leaves us with very few options to customize our CSP policies.
734
734
735
-
On the other hand, it obliges the developers community to adopt a standardized mindset when thinking about CSP. Less configuration options means less potential loopholes that malicious actors can seek to exploit.
735
+
On the other hand, it obliges application developers to adopt a standardized mindset when thinking about CSP. Less configuration options means less potential loopholes that malicious actors can seek to exploit.
736
736
737
-
With this in mind, we recommend that you implement your Strict CSP policy by checking your configuration against the following template:
738
-
739
-
```ts
740
-
exportdefaultdefineNuxtConfig({
741
-
security: {
742
-
nonce:true, // Enables HTML nonce support in SSR mode
743
-
ssg: {
744
-
meta:true, // Enables CSP as a meta tag in SSG mode
745
-
hashScripts:true, // Enables CSP hash support for scripts in SSG mode
746
-
hashStyles:false// Disables CSP hash support for styles in SSG mode (recommended)
747
-
nitroHeaders:true// Allow Nitro to serve security headers for pre-rendered routes
748
-
exportToPresets:true// Export pre-rendered security headers to Nitro presets
749
-
},
750
-
// You can use nonce and ssg simultaneously
751
-
// Nuxt Security will take care of choosing the adequate parameters when you build for either SSR or SSG
752
-
headers: {
753
-
contentSecurityPolicy: {
754
-
'script-src': [
755
-
"'self'", // Fallback value, will be ignored by browsers level 3
756
-
"https://domain.com/external-script.js", // Fallback value, will be ignored by browsers level 3
757
-
"'unsafe-inline'", // Fallback value, will be ignored by browsers level 2 & 3
758
-
"'strict-dynamic'", // Strict CSP via 'strict-dynamic', supported by browsers level 3
759
-
"'nonce-{{nonce}}'"// Enables CSP nonce support for scripts in SSR mode, supported browsers level 2 & 3
760
-
],
761
-
'style-src': [
762
-
"'self'", // Enables loading of stylesheets hosted on self origin
763
-
"https://domain.com/file.css", // Use fully-qualified filenames rather than the https: generic
764
-
"https://trusted-domain.com", // Avoid using domain stubs unless you can fully trust them
765
-
"'unsafe-inline'"// Recommended default for most Nuxt apps, but make sure 'img-src' is properly set up
766
-
//"'nonce-{{nonce}}'" // Disables CSP nonce support, otherwise would cancel 'unsafe-inline'
767
-
// You can re-enable if your application does not modify inline styles dynamically
768
-
],
769
-
"img-src": [
770
-
"'self'", // Enables loading of images hosted on self origin
771
-
"https://domain.com/img.png", // Use fully-qualified filenames rather than the https: generic
772
-
"https://trusted-domain.com", // Avoid using domain stubs unless you can fully trust them
773
-
"blob:"// If you use Blob to construct images dynamically from javascript
774
-
// Qualifying img-src properly mitigates strongly against 'unsafe-inline' in style-src
775
-
],
776
-
'font-src': [
777
-
"'self'", // Enables loading of fonts hosted on self origin
778
-
"https://domain.com/font.woff", // Use fully-qualified filenames rather than the https: generic
779
-
"https://trusted-domain.com"// Avoid using domain stubs unless you can fully trust them
780
-
],
781
-
"worker-src": [
782
-
"'self'", // Enables loading service worker from self origin,
783
-
"blob:"// If you use PWA, it is likely that the worker will be instantiated from Blob
784
-
],
785
-
"connect-src": [
786
-
"'self'", // Enables fetching from self origin
787
-
"https://api.domain.com/service", // Use largest prefix possible on API routes
788
-
"wss://api.domain.com/messages"// Add Websocket qualifiers if used
789
-
],
790
-
"object-src": [
791
-
"'none'"
792
-
],
793
-
"base-uri": [
794
-
"'none'"
795
-
]
796
-
// Do not use default-src
797
-
}
798
-
}
799
-
}
800
-
})
801
-
```
737
+
With this in mind, we recommend that you implement your Strict CSP policy by starting from our [default configuration values](/documentation/getting-started/configuration#default), and modifying only the required values.
0 commit comments