Parse is storing user data in local storage, and I learned that local storage can be hacked with XSS attacks. I also learned that implementing CSP can prevent XSS attacks, but how to do it with parse.
Here is my custom header function that is supposed to add CSP along with other headers. But apparently it’s not working, because the content loads even if CSP blocks it.
How to set up CSP with parse?
const setHeaders = (req, res, next) => {
const origin = "http://localhost:3000"
res.setHeader("Access-Control-Allow-Origin", origin);
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With,content-type");
res.setHeader(
"Content-Security-Policy",
"default-src 'self'; img-src *; media-src *; script-src 'none'; frame-src youtube.com stripe.com"
);
res.setHeader("Access-Control-Allow-Credentials", true);
next();
};
module.exports = setHeaders;
And here is how I mount it along with the cors options
app.options("*", cors(corsOptions), setHeaders);
app.use(mountPath, server.app, cors(corsOptions), setHeaders);
app.use(cors(corsOptions), setHeaders);