-
Notifications
You must be signed in to change notification settings - Fork 145
Dynamic CSP Nonce Support #25
Copy link
Copy link
Closed
Description
Hi
Great work. Thanks for this awesome middleware.
Can I send a PR for adding dynamic CSP nonce?
Proposed Implementation would extend the current solution without breaking anything
Now
ContentSecurityPolicy: "script-src 'self'"
Proposed Solution
ContentSecurityPolicy: "script-src 'self' {{ . }}"
Will use Go's template/text package to change this to to a fmt string i.e. script-src 'self' 'nonce-%s' then use this to send headers on every request with a unique nonce for each request.
Add a new Nonce(r *http.Request) function globally to get the nonce for the present request which can be later used to add nonce to scripts like,
<script nonce="2726c7f26c"> var inline = 1; </script>
There can also a nonce length property.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels