Dear Everyone,
I am working on a module for Content-Security-Policy generation for Cloudflare. I’ve come across the following case:
Create a dictionary with the report-to directive values,
Use the jsonify function to return a string as JSON,
Use this value in a string that is used in resources.FromString method.
The partial does work and creates “_headers” file at the root of the “publish” folder. The problem is the following:
JSON keys are not wrapped in either single or double quotes but escaped by HTML entities.
Dear Joe and Bjorn,
I’ve studied template functions looking for those related to escaping/sanitizing input.
Using: htmlUnescape helped to get correct output. Besides the JSON value I gave as an example in my original post the hash strings for style-src and script-src were escaped in the same way.
I am wondering now if I should use functions like safeURL or safeHTMLAttr to further sanitize and normalize the header value. Hugo started returning regular strings from the .Data.Integrity for resources and the delimit function, which I am using in partials.
The module is getting in a rather usable shape. Since it touches the security aspect of a site, I want to use it on my own website first for a while to watch for possible errors.
It has one feature that is very specific to how I inline CSS in my main theme, which I need to make generic. All in all, it looks like it can be released into the wild with some documentations on how to generate the configuration files. The first use case is my own, which is Cloudflare pages, but it is very easy to be adapted to any other configuration format.