Content-Security-Policy
HTTP response header using Express.By using the Express API, we can use the set
method of the Express Response
object.
res.set("Content-Security-Policy", "default-src 'self'");
Your policy will go inside the second argument of the set
method of the Express Response object.
Instead of writing the header directly from your node js code, you can instead use your web server to write the header. For example CSP with nginx or CSP with Apache via htaccess.
As we saw above it is quite simple to set the header yourself, but if you are looking for some additional features there are some express middleware modules that support CSP:
If you're not sure what default-src 'self';
means, then check out the Content Security Policy reference for details.
Want to learn the ins and outs CSP? Grab a copy of the CSP Developer Field Guide. It's a short and sweet guide to help developers get up to speed quickly.
Grab a CopyAdvisory Week is a weekly roundup of all the security advisories published by the major software vendors.