Skip to content

Commit

Permalink
Merge branch 'chore/1.0.0-rc.1' of github.com:Baroshem/nuxt-security …
Browse files Browse the repository at this point in the history
…into chore/1.0.0-rc.1
  • Loading branch information
Baroshem committed Oct 6, 2023
2 parents 819fedc + 6a7ff5b commit 4942b07
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: ci
on:
push:
branches:
- main
- 'main'
- '**-rc.**'
- 'renovate/**'
pull_request:
branches:
- main

jobs:
ci:
Expand Down
35 changes: 35 additions & 0 deletions docs/content/1.documentation/1.getting-started/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,38 @@ security: {
```

To read more about every security middleware, go to that middleware page in `security` section.

## Overriding a layer's configuration

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`:


```ts
export default defineNuxtConfig(
{
extends: 'some-layer-adding-nuxt-security',
modules: [
(_options, nuxt) => {
const nuxtConfigSecurity = nuxt.options.security
if (
typeof nuxtConfigSecurity.headers !== 'boolean' &&
nuxtConfigSecurity.headers.contentSecurityPolicy &&
typeof nuxtConfigSecurity.headers.contentSecurityPolicy !==
'boolean' &&
typeof nuxtConfigSecurity.headers.contentSecurityPolicy !==
'string' &&
nuxtConfigSecurity.headers.contentSecurityPolicy['object-src']
) {
nuxtConfigSecurity.headers.contentSecurityPolicy['object-src'] =
nuxtConfigSecurity.headers.contentSecurityPolicy[
'object-src'
].filter((x) => x !== "'none'")
}
console.log(nuxt.options.security)
},
],
}
)
```

Of course it's possible to define the module shown above using a file in the `modules` directory as well.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"test:watch": "vitest watch",
"stackblitz": "cd .stackblitz && yarn && yarn dev"
},
"packageManager": "[email protected]",
"dependencies": {
"@nuxt/kit": "^3.7.3",
"basic-auth": "^2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fileURLToPath } from 'node:url'
import { resolve, normalize } from 'pathe'
import { defineNuxtModule, addServerHandler, installModule, addVitePlugin } from '@nuxt/kit'
import defu from 'defu'
import { defu } from 'defu'
import { Nuxt, RuntimeConfig } from '@nuxt/schema'
import { builtinDrivers } from 'unstorage'
import { defuReplaceArray } from './utils'
Expand Down

0 comments on commit 4942b07

Please sign in to comment.