Reputation: 348
I've written a simple middleware function to add the Content-Security-Policy header to my API routes, I've tried using multiple policies (default-src, img-src, frame-ancestors) pointing to either 'self' or explicitly to "http://localhost:port" but none of these seem to work.
This is my simple middleware:
(defn wrap-content-type-security
[handler]
(fn [req]
(let [resp (handler req)]
(header resp "Content-Security-Policy" "default-src 'self'"))))
I am able to see the correct header set in my routes:
However I'm still getting the usual favicon.ico route error, I do have a dummy route for /favicon.ico just returning some text and this also returns the CSP header.
There's obviously something I'm missing/doing wrong, any help is appreciated.
Thank you.
Edit: Looking more into this, seems like this is a Firefox related issue? I tried to replicate the issue in Chrome and everything seems to be working fine as the favicon does show in the browser tab.
However in Firefox, still showing the same issue:
Which makes me thing that it's got something to do with that "FaviconLoader.jsm" script? being loaded/shown on the console.
Upvotes: 1
Views: 637
Reputation: 4358
It seems that your middleware is working (adding the CSP header) but you don't have a proper csp header value.
Try adding img-src 'self'
and see if it helps.
Btw. you can try Content-Security-Policy-Report-Only
until you tune your CSP header.
Upvotes: 1