Open JoeChapman opened 7 years ago
So we can implement a Content Security Policy that does not allow unsafe-inline scripts to be loaded we should sign our script tags with a nonce.
unsafe-inline
nonce
A nonce can be generated in server middleware on each request using npm uuid, assigned to the locals object and the CSP script-src directive.
npm uuid
script-src
When the template is rendered the placeholder is substituted with the value of locals.nonce
locals.nonce
If the value of the placeholder attribute (the nonce value we just set) and the value of the nonce on the server match then the request can proceed
Associated issues https://github.com/UKHomeOfficeForms/hof-bootstrap/issues/105 https://github.com/alphagov/govuk_template/issues/258
PR for script tag placeholder: https://github.com/alphagov/govuk_template/pull/268
So we can implement a Content Security Policy that does not allow
unsafe-inline
scripts to be loaded we should sign our script tags with anonce
.A
nonce
can be generated in server middleware on each request usingnpm uuid
, assigned to the locals object and the CSPscript-src
directive.When the template is rendered the placeholder is substituted with the value of
locals.nonce
If the value of the placeholder attribute (the
nonce
value we just set) and the value of thenonce
on the server match then the request can proceedAssociated issues https://github.com/UKHomeOfficeForms/hof-bootstrap/issues/105 https://github.com/alphagov/govuk_template/issues/258