I have a React SPA with only one request to my Node.js + express server with header "Content-Security-Policy" set to default-src ‘none’. Although it still loads everything. What am I doing wrong? P.S: incognito mode does not help, I use latest version of Chrome.
I’ve checked syntax adding it to tag and it worked but I want to be able to make my web app more secure via HTTP.
2
Answers
The CSP header must be on the client. If you want to protect the server, use CORS headers.
Example:
Access-Control-Allow-Origin: http://localhost:5139
The
Content-Security-Policy
header must be sent with the HTMLDoc
response.In your screenshot, it looks like the HTML
Doc
response doesn’t have aContent-Security-Policy
because your browser loaded the React app, which then fetched/ping
.Diagnosing your problem
Doc
type.Doc
circled in red.Doc
response.Doc
response have aContent-Security-Policy
?