Part of my Express configuration looks like this and runs on different domain
app.use(function(req, res, next) {
res.setHeader("Access-Control-Allow-Origin", 'http://localhost:3000');
res.setHeader("Access-Control-Allow-Credentials","true");
res.setHeader("Access-Control-Expose-Headers", "Set-Cookie");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, x-xsrf-token, X-Requested-With, Accept, Expires, Last-Modified, Cache-Control");
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, DELETE");
next();
});
app.configure('development', 'production', function() {
app.use(express.csrf());
app.use(function(req, res, next) {
res.cookie('XSRF-TOKEN', req.csrfToken());
next();
});
});
When using CORS there is OPTIONS request before anything different than a GET. The server is manually configured to respond to it with 200 every time, so it proceed to the POST or whatever. The requests come from Angular. Some said I need to add some of these lines in order to configure Angular properly.
$httpProvider.defaults.xsrfCookieName = 'XSRF-TOKEN';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.withCredentials = true;
The error which I get is 403 Forbidden, the only solution so far is to comment out the whole app.configure(..) in the server. Obviously, I have some problem with CSRF and I cannot understand what should I do.
EDITED