go-safeweb icon indicating copy to clipboard operation
go-safeweb copied to clipboard

Make XSRF token and CSP nonce injection generic

Open maramihali opened this issue 4 years ago • 0 comments

Currently, in order to avoid cloning a template every time we inject a XSRF token or a CSP nonce, we extended the safehttp.TemplateResponse with a FuncMap field. This contains the name to function mappings of the template i.e. for a {{XSRFToken}} template function, the FuncMap will contain an element similar to:

"XSRFToken": func() string { return "XSRFTokenValue" }

In the safehtml/template package, when the template is parsed the value "XSRFTokenValue" will be then applied to the template function. This design is, however, very specific to the safehtml/template API and we should find a more general solution.

maramihali avatar Sep 25 '20 09:09 maramihali