-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #659 from daniel-ac-martin/fix-zap-warnings
Fix DAST warnings
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Middleware } from './common'; | ||
|
||
const keywords = [ | ||
'self', | ||
'src' | ||
]; | ||
|
||
const ppObj = { | ||
'accelerometer': 'self', | ||
'ambient-light-sensor': 'self', | ||
'autoplay': 'self', | ||
'battery': 'self', | ||
'camera': 'self', | ||
'display-capture': 'self', | ||
'document-domain': 'self', | ||
'encrypted-media ': 'self', | ||
'execution-while-not-rendered': 'self', | ||
'execution-while-out-of-viewport': 'self', | ||
'fullscreen': 'self', | ||
'gamepad': 'self', | ||
'geolocation': 'self', | ||
'gyroscope': 'self', | ||
'hid': 'self', | ||
'idle-detection': 'self', | ||
'local-fonts': 'self', | ||
'magnetometer': 'self', | ||
'microphone': 'self', | ||
'midi': 'self', | ||
'payment': 'self', | ||
'picture-in-picture': 'self', | ||
'publickey-credentials-get': 'self', | ||
'screen-wake-lock': 'self', | ||
'serial': 'self', | ||
'speaker-selection': 'self', | ||
'usb': 'self', | ||
'web-share': 'self', | ||
'xr-spatial-tracking': 'self' | ||
}; | ||
|
||
const isDefined = (v: any): boolean => ( | ||
v !== undefined | ||
); | ||
|
||
const policy = Object.keys(ppObj) | ||
.map(directive => { | ||
const _valueArr = ppObj[directive]; | ||
const valueArr = ( | ||
Array.isArray(_valueArr) | ||
? _valueArr | ||
: [ _valueArr ] | ||
); | ||
const values = ( | ||
valueArr | ||
.filter(isDefined) | ||
.map(v => ( | ||
keywords.includes(v) | ||
? v | ||
: `"${v}"` | ||
) ) | ||
.join(' ') | ||
); | ||
|
||
return ( | ||
values === '' | ||
? undefined | ||
: `${directive}=(${values})` | ||
); | ||
} ) | ||
.filter(isDefined) | ||
.join(', '); | ||
|
||
export const permissionsPolicy: Middleware = (_req, res, next) => { | ||
res.header('Permissions-Policy', policy); | ||
|
||
next(); | ||
}; | ||
|
||
export default permissionsPolicy; |
b6e0568
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://not-gov.uk as production
🚀 Deployed on https://63cec388f0771a6ff507a2cc--notgovuk.netlify.app