Skip to content

Commit 90ad2d5

Browse files
authored
Merge pull request #483 from Baroshem/vejja/issue470
feat(core): introduce `strict` mode
2 parents 1c33843 + b9e7913 commit 90ad2d5

38 files changed

+753
-243
lines changed

docs/content/1.documentation/1.getting-started/2.configuration.md

+19-43
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All module configuration is the following type:
1414

1515
```ts
1616
interface ModuleOptions {
17+
strict: boolean;
1718
headers: SecurityHeaders | false;
1819
requestSizeLimiter: RequestSizeLimiter | false;
1920
rateLimiter: RateLimiter | false;
@@ -33,76 +34,49 @@ interface ModuleOptions {
3334

3435
All above `ModuleOptions` are explained in more details in the next sections.
3536

36-
## Default
37+
## Defaults
3738

38-
This module will by default set the following configuration options to enable middlewares and route roules:
39+
This module will automatically set default values for each option.
40+
41+
By default, this module chooses reasonable defaults that ensure that your application will not break. The following configuration options are set:
3942

4043
```ts
4144
security: {
45+
strict: false,
4246
headers: {
4347
crossOriginResourcePolicy: 'same-origin',
4448
crossOriginOpenerPolicy: 'same-origin',
45-
crossOriginEmbedderPolicy: 'require-corp',
49+
crossOriginEmbedderPolicy: 'credentialless',
4650
contentSecurityPolicy: {
4751
'base-uri': ["'none'"],
48-
'default-src' : ["'none'"],
49-
'connect-src': ["'self'", 'https:'],
5052
'font-src': ["'self'", 'https:', 'data:'],
5153
'form-action': ["'self'"],
5254
'frame-ancestors': ["'self'"],
53-
'frame-src': ["'self'"],
5455
'img-src': ["'self'", 'data:'],
55-
'manifest-src': ["'self'"],
56-
'media-src': ["'self'"],
5756
'object-src': ["'none'"],
5857
'script-src-attr': ["'none'"],
5958
'style-src': ["'self'", 'https:', "'unsafe-inline'"],
6059
'script-src': ["'self'", 'https:', "'unsafe-inline'", "'strict-dynamic'", "'nonce-{{nonce}}'"],
61-
'upgrade-insecure-requests': true,
62-
'worker-src': ["'self'"],
60+
'upgrade-insecure-requests': true
6361
},
6462
originAgentCluster: '?1',
6563
referrerPolicy: 'no-referrer',
6664
strictTransportSecurity: {
67-
maxAge: 31536000,
68-
includeSubdomains: true
65+
maxAge: 15552000,
66+
includeSubdomains: true,
6967
},
7068
xContentTypeOptions: 'nosniff',
7169
xDNSPrefetchControl: 'off',
7270
xDownloadOptions: 'noopen',
73-
xFrameOptions: 'DENY',
71+
xFrameOptions: 'SAMEORIGIN',
7472
xPermittedCrossDomainPolicies: 'none',
7573
xXSSProtection: '0',
7674
permissionsPolicy: {
77-
accelerometer: [],
78-
'ambient-light-sensor':[],
79-
autoplay:[],
80-
battery:[],
81-
camera:[],
82-
'display-capture':[],
83-
'document-domain':[],
84-
'encrypted-media':[],
85-
fullscreen:[],
86-
gamepad:[],
87-
geolocation:[],
88-
gyroscope:[],
89-
'layout-animations':['self'],
90-
'legacy-image-formats':['self'],
91-
magnetometer:[],
92-
microphone:[],
93-
midi:[],
94-
'oversized-images':['self'],
95-
payment:[],
96-
'picture-in-picture':[],
97-
'publickey-credentials-get':[],
98-
'speaker-selection':[],
99-
'sync-xhr':['self'],
100-
'unoptimized-images':['self'],
101-
'unsized-media':['self'],
102-
usb:[],
103-
'screen-wake-lock':[],
104-
'web-share':[],
105-
'xr-spatial-tracking':[]
75+
camera: [],
76+
'display-capture': [],
77+
fullscreen: [],
78+
geolocation: [],
79+
microphone: []
10680
}
10781
},
10882
requestSizeLimiter: {
@@ -155,7 +129,9 @@ security: {
155129
}
156130
```
157131

158-
To read more about every security middleware, go to that middleware page in `security` section.
132+
::alert{type="warning"}
133+
To modify these default settings and further increase the security of your application, read about our `strict` mode and our user-friendly approach on how to [Improve Security](/documentation/advanced/improve-security)
134+
::
159135

160136
## Overriding a layer's configuration
161137

docs/content/1.documentation/2.headers/1.csp.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ You can also disable this header by `contentSecurityPolicy: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header:
45+
By default, Nuxt Security will set the following value for this header:
4646

4747
```http
48-
Content-Security-Policy: base-uri 'none'; default-src 'none'; connect-src 'self' https:; font-src 'self' https: data:; form-action 'self'; frame-ancestors 'self'; frame-src 'self'; img-src 'self' data:; manifest-src 'self'; media-src 'self'; object-src 'none'; script-src-attr 'none'; style-src 'self' https: 'unsafe-inline'; script-src 'self' https: 'unsafe-inline' 'strict-dynamic' 'nonce-{{nonce}}'; upgrade-insecure-requests; worker-src 'self';
48+
Content-Security-Policy: base-uri 'none'; font-src 'self' https: data:; form-action 'self'; img-src 'self' data:; object-src 'none'; script-src-attr 'none'; style-src 'self' https: 'unsafe-inline'; script-src 'self' https: 'unsafe-inline' 'strict-dynamic' 'nonce-{{nonce}}'; upgrade-insecure-requests;
4949
```
5050

5151
## Available values
@@ -161,8 +161,6 @@ export default defineNuxtConfig({
161161
"'unsafe-inline'" // Recommended default for most Nuxt apps
162162
],
163163
'base-uri': ["'none'"],
164-
'default-src': ["'self'"],
165-
'connect-src': ["'self'", 'https:'],
166164
'img-src': ["'self'", "data:"], // Add relevant https://... sources if you load images from external sources
167165
'font-src': ["'self'", "https:", "data:"], // For increased security, replace by the specific sources for fonts
168166
'object-src': ["'none'"],

docs/content/1.documentation/2.headers/10.xDNSPrefetchControl.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `xDNSPrefetchControl: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
X-DNS-Prefetch-Control: off

docs/content/1.documentation/2.headers/11.xDownloadOptions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `xDownloadOptions: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
X-Download-Options: noopen

docs/content/1.documentation/2.headers/12.xFrameOptions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `xFrameOptions: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
X-Frame-Options: SAMEORIGIN

docs/content/1.documentation/2.headers/13.xPermittedCrossDomainPolicies.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `xPermittedCrossDomainPolicies: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
X-Permitted-Cross-Domain-Policies: none

docs/content/1.documentation/2.headers/14.xXSSProtection.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `xXSSProtection: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
X-XSS-Protection: 0

docs/content/1.documentation/2.headers/2.permissions-policy.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export default defineNuxtConfig({
5454

5555
## Default value
5656

57-
By default, Nuxt Security will set following value for this header.
57+
By default, Nuxt Security will set the following value for this header:
5858

5959
```http
60-
Permissions-Policy: accelerometer=(), autoplay=(), camera=(), display-capture=(), encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(self), usb=(), web-share=(), xr-spatial-tracking=()
60+
Permissions-Policy: camera=(), display-capture=(), fullscreen=(), geolocation=(), microphone=()
6161
```
6262

6363
## Available values

docs/content/1.documentation/2.headers/3.crossOriginEmbedderPolicy.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ You can also disable this header by `crossOriginEmbedderPolicy: false`.
4444

4545
## Default value
4646

47-
By default, Nuxt Security will set following value for this header.
47+
By default, Nuxt Security will set the following value for this header.
4848

4949
```http
50-
Cross-Origin-Embedder-Policy: require-corp
50+
Cross-Origin-Embedder-Policy: credentialless
5151
```
5252

5353
## Available values
@@ -73,3 +73,27 @@ no-cors cross-origin requests are sent without credentials. In particular, it me
7373
::alert{type="warning"}
7474
⚠️ Read more about `Avoiding blockage with CORS` [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy#avoiding_coep_blockage_with_cors).
7575
::
76+
77+
## Cross-Origin Isolation issues
78+
79+
Setting cross-origin isolation by using the COEP header can sometimes have tricky consequences. This is because the COEP/COOP specification requires **both** your application **and** the embedded resource to set corresponding headers properly. If only one of the two parties does not set the headers properly, the frame can be blocked.
80+
81+
As a consequence, in order to avoid being blocked in websites that do not have COEP/COOP headers, some major third-party providers have chosen to _not_ deliver COEP/COOP headers. This in turn prevents you from using COEP in your application! If you want some background, please read the [excellent blog note from Stackblitz that explains their decision](https://blog.stackblitz.com/posts/cross-browser-with-coop-coep/).
82+
83+
If you encounter this situation, you will be left with a tough dilemna:
84+
- If you choose to apply the `require-corp` option, the embedded resource will be blocked _if it does not deliver the proper headers_.
85+
- If you choose to apply the `unsafe-none` option, the embedded resource will not be cross-origin isolated and therefore _might not work properly_.
86+
87+
This is the reason why we use the `credentialless` option by default, which is a reasonable fallback.
88+
However even with this setting, you might encounter difficulties.
89+
90+
1. Inspect COEP/COOP issues in your browser's Developer Tools:
91+
92+
- If your console logs tell you that the Embedded Resource is blocked because it does not deliver proper COEP/COOP headers, this means that the third-party resource prevents you from using `credentialless`. In that case you might have to fallback to `unsafe-none`.
93+
- If your console logs tell you that some features (e.g. SharedArrayBuffers) are blocked because your application is not cross-origin isolated, your application might still be able to run properly. If it's not the case, you might have to upgrade to `require-corp`.
94+
95+
2. Have a look at our documentation example code
96+
97+
Our own documentation website includes iframes from Youtube and Stackblitz.
98+
Please have a look at our [Github source code](https://github.com/Baroshem/nuxt-security/blob/main/docs/nuxt.config.ts) to see how we set the Nuxt Security options to allow these iframes.
99+

docs/content/1.documentation/2.headers/4.crossOriginOpenerPolicy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ You can also disable this header by `crossOriginOpenerPolicy: false`.
4444

4545
## Default value
4646

47-
By default, Nuxt Security will set following value for this header.
47+
By default, Nuxt Security will set the following value for this header.
4848

4949
```http
5050
Cross-Origin-Opener-Policy: same-origin

docs/content/1.documentation/2.headers/5.crossOriginResourcePolicy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `crossOriginResourcePolicy: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
Cross-Origin-Resource-Policy: same-origin

docs/content/1.documentation/2.headers/6.originAgentCluster.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `originAgentCluster: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
Origin-Agent-Cluster: ?1

docs/content/1.documentation/2.headers/7.referrerPolicy.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `referrerPolicy: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
Referrer-Policy: no-referrer

docs/content/1.documentation/2.headers/8.strictTransportSecurity.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `strictTransportSecurity: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
Strict-Transport-Security: max-age=15552000; includeSubDomains;

docs/content/1.documentation/2.headers/9.xContentTypeOptions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ You can also disable this header by `xContentTypeOptions: false`.
4242

4343
## Default value
4444

45-
By default, Nuxt Security will set following value for this header.
45+
By default, Nuxt Security will set the following value for this header.
4646

4747
```http
4848
X-Content-Type-Options: nosniff

0 commit comments

Comments
 (0)