Currently, the support for CSP in this module is to pass the provided CSP directly as a response header. However, in the case of using inline CSS (e.g. material-ui), we need to be able to set the inline nonce-${nonce} source for the style-src-elem. Is this functionality that you see this module taking on or should that be handled somewhere else?
Cheers!
Edit:
I felt I should add the workaround for any other folks that are encountering this - inside your specific gin handler, you can override the CSP header. So you'll need to:
- Generate a nonce, I use v4 UUIDs for this.
- Add the overriding header:
c.Header(
"Content-Security-Policy",
fmt.Sprintf(
"default-src 'self'; style-src-elem 'self' 'nonce-%s'",
nonce,
),
)
- Ensure to pass the
nonce to your HTML rendering function, as it must also be included as an meta attributed, i.e.:
<meta property="csp-nonce" content="{{ .nonce }}">
Currently, the support for CSP in this module is to pass the provided CSP directly as a response header. However, in the case of using inline CSS (e.g. material-ui), we need to be able to set the inline
nonce-${nonce}source for thestyle-src-elem. Is this functionality that you see this module taking on or should that be handled somewhere else?Cheers!
Edit:
I felt I should add the workaround for any other folks that are encountering this - inside your specific gin handler, you can override the CSP header. So you'll need to:
nonceto your HTML rendering function, as it must also be included as anmetaattributed, i.e.: