Skip to content

Commit

Permalink
fix: permissions policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Baroshem committed Oct 15, 2023
1 parent 5d9740a commit 9861e61
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ security: {
xPermittedCrossDomainPolicies: 'none',
xXSSProtection: '0',
permissionsPolicy: {
camera: ['()'],
'display-capture': ['()'],
fullscreen: ['()'],
geolocation: ['()'],
microphone: ['()']
camera: [],
'display-capture': [],
fullscreen: [],
geolocation: [],
microphone: []
}
},
requestSizeLimiter: {
Expand Down
3 changes: 0 additions & 3 deletions docs/content/1.documentation/1.getting-started/3.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ experimental: {

::




## Disabling functionality

To disable certain middleware or headers, follow this pattern:
Expand Down
14 changes: 13 additions & 1 deletion docs/content/1.documentation/2.headers/2.permissions-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ export default defineNuxtConfig({
})
```

You can also disable this header by `permissionsPolicy: false`.
You can also disable this header by setting `permissionsPolicy: false`. To disable certain API completely, set its value to empty array like:

```ts
export default defineNuxtConfig({
security: {
headers: {
permissionsPolicy: {
'camera': [] // This will block usage of camera by this website
},
},
},
})
```

## Default value

Expand Down
10 changes: 5 additions & 5 deletions src/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export const defaultSecurityConfig = (serverlUrl: string): ModuleOptions => ({
xPermittedCrossDomainPolicies: 'none',
xXSSProtection: '0',
permissionsPolicy: {
camera: ['()'],
'display-capture': ['()'],
fullscreen: ['()'],
geolocation: ['()'],
microphone: ['()']
camera: [],
'display-capture': [],
fullscreen: [],
geolocation: [],
microphone: []
}
},
requestSizeLimiter: {
Expand Down
2 changes: 1 addition & 1 deletion src/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const headerValueMappers = {
})
.filter(Boolean).join('; ')
},
permissionsPolicy: (value: PermissionsPolicyValue) => Object.entries(value).map(([directive, sources]) => (sources as string[])?.length && `${directive}=${(sources as string[]).join(' ')}`).filter(Boolean).join(', ')
permissionsPolicy: (value: PermissionsPolicyValue) => Object.entries(value).map(([directive, sources]) => `${directive}=(${(sources as string[]).join(' ')})`).filter(Boolean).join(', ')
}

export const getHeaderValueFromOptions = <T>(headerType: HeaderMapper, headerOptions: any) => {
Expand Down

0 comments on commit 9861e61

Please sign in to comment.