--- slug: relaxed-csp-for-go-coverage title: "Relaxed Content-Security-Policy for Go Code Coverage Reports" date: "2022-02-25T01:36:14-04:00" --- There is a conflict between [my strict `Content-Security-Policy`][my-csp] and the [CSS][] and [JavaScript][js] embedded in the [HTML][] [code coverage][] reports generated by [`go cover`][go-cover]. I tested a couple of methods of overriding the base [`Content-Security-Policy`][csp], without success: 1. Add a relaxed [``][meta-http-equiv] element. 2. Embed the script and style as [`data:` URLs][data-url]. (Aside: I'm glad browsers don't allow these workarounds, because they would be potential security holes). In any case, the my solution was to relax the policy for a specific location via the [Apache][] config: ```apache # # Relax style-src and script-src content security policies for content # in the "/coverage-reports" directory so that the HTML coverage reports # generated by `go cover` work as expected. # # Specifically the relaxed constraints allow: # # 1. The inline `