Skip to content

Commit 2229c51

Browse files
authored
Merge pull request #226 from dargmuesli/layer-overrides
docs(configuration): add layer overriding instructions
2 parents c50d055 + dabab16 commit 2229c51

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

+35
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,38 @@ security: {
113113
```
114114

115115
To read more about every security middleware, go to that middleware page in `security` section.
116+
117+
## Overriding a layer's configuration
118+
119+
If you extend a [Nuxt Layer](https://nuxt.com/docs/getting-started/layers) which adds `nuxt-security`, you can override that layer's `nuxt-security` configuration or parts of it by defining a module in your project's `nuxt.config.ts`. Here is an example that illustrates how to remove the `'none'` value set by default for `object-src`:
120+
121+
122+
```ts
123+
export default defineNuxtConfig(
124+
{
125+
extends: 'some-layer-adding-nuxt-security',
126+
modules: [
127+
(_options, nuxt) => {
128+
const nuxtConfigSecurity = nuxt.options.security
129+
if (
130+
typeof nuxtConfigSecurity.headers !== 'boolean' &&
131+
nuxtConfigSecurity.headers.contentSecurityPolicy &&
132+
typeof nuxtConfigSecurity.headers.contentSecurityPolicy !==
133+
'boolean' &&
134+
typeof nuxtConfigSecurity.headers.contentSecurityPolicy !==
135+
'string' &&
136+
nuxtConfigSecurity.headers.contentSecurityPolicy['object-src']
137+
) {
138+
nuxtConfigSecurity.headers.contentSecurityPolicy['object-src'] =
139+
nuxtConfigSecurity.headers.contentSecurityPolicy[
140+
'object-src'
141+
].filter((x) => x !== "'none'")
142+
}
143+
console.log(nuxt.options.security)
144+
},
145+
],
146+
}
147+
)
148+
```
149+
150+
Of course it's possible to define the module shown above using a file in the `modules` directory as well.

0 commit comments

Comments
 (0)