Content Security Policy (CSP)
How to do that?
Well,
- Implement CSP to declare valid sources of content, reducing the risk of script injection.
- Use CSP to enforce policies like
script-src
orstyle-src
to only allow trusted sources. - Regularly update your CSP based on new threats and application changes.
Example:
app.use((req, res, next) => {
res.setHeader("Content-Security-Policy", "default-src 'self'; script-src 'self' 'unsafe-inline';");
next();
});
Want to learn more? Check out the MDN Web Docs on CSP