Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parentheses for permissions policy parser according issue #195

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ 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) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: please change defaultConfig.ts value for permissionsPolicy from the existing one to:

    permissionsPolicy: {
      camera: [],
      'display-capture': [],
      fullscreen: [],
      geolocation: [],
      microphone: []
    }

This with the addition of the next comment would allow to have both () and your functionality :)

Object.entries(value)
.map(
([directive, sources]) =>
(sources as string[])?.length &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: here you can safely delete the checking for length as we will allow for empty arrays that will be translated to ()

`${directive}=(${(sources as string[]).join(' ')})`
)
.filter(Boolean)
.join(', ')
}

export const getHeaderValueFromOptions = <T>(headerType: keyof SecurityHeaders, headerOptions: MiddlewareConfiguration<T>) => {
Expand Down