title: 403 error in Node Express
body: <p>I have a node App where there is a page which posts their email address to login to the app (I'm not doing anything but storing the email address for now). When I push the app to production it works fine for a little while and then I start getting a 403 error like this:</p>
  
  <pre><code>Express
  403 Error: Forbidden
  at Object.exports.error (/opt/run/snapshot/package/node_modules/express/node_modules/connect/lib/utils.js:63:13)
  at createToken (/opt/run/snapshot/package/node_modules/express/node_modules/connect/lib/middleware/csrf.js:82:55)
  at /opt/run/snapshot/package/node_modules/express/node_modules/connect/lib/middleware/csrf.js:54:7
  at Object.ondone (/opt/run/snapshot/package/node_modules/express/node_modules/connect/node_modules/uid2/index.js:46:8)
  </code></pre>
  
  <p>This is what I'm seeing in the log:</p>
  
  <pre><code>err Sun, 09 Mar 2014 11:52:01 GMT Error: Forbidden
  at Object.exports.error (/opt/run/snapshot/package/node_modules/express/node_modules/connect/lib/utils.js:63:13)
  at createToken (/opt/run/snapshot/package/node_modules/express/node_modules/connect/lib/middleware/csrf.js:82:55)
  at /opt/run/snapshot/package/node_modules/express/node_modules/connect/lib/middleware/csrf.js:54:7
  at Object.ondone (/opt/run/snapshot/package/node_modules/express/node_modules/connect/node_modules/uid2/index.js:46:8)
  </code></pre>
  
  <p>If I restart the app without any code changes, login starts working again. I'm guessing something to do with csrf is going stale. I definitely am passing a csrf token on the login page. I can see it when I do a view source.</p>
  
  <p>I'm on node 0.10, I'm wondering if I should go back to 0.8.</p>
  
  <p>here's my config:</p>
  
  <pre><code>app.configure(function(){
      app.set('views', __dirname + '/views');
      app.set('view engine','ejs');
      app.use(express.logger('dev'));
      app.use(express.bodyParser());
      app.use(helmet.xframe());
      app.use(helmet.iexss());
      app.use(helmet.contentTypeOptions());
      app.use(helmet.cacheControl());
      app.use(express.cookieParser());
      app.use(express.session({
          secret: "**********************",
          cookie: {
              maxAge  : 3600000, //1 hours
              expires : new Date(Date.now() + 3600000), //2 Hours
          },
  
          store: new MongoStore({
              mongoose_connection: mongoose.connection
           })
          })
      );
  
      //app.use(express.cookieSession({secret:"fooseball123!"}));
      app.use(express.csrf());
      //middleware to make csrf token available 
      app.use(function (req, res, next) {
          //res.locals.token = req.session._csrf;
          res.locals.token = req.csrfToken();
          next();
        });
      app.use(express.compress());
      app.use(app.router);
      app.use(express.static(__dirname + '/public', {maxAge: 86400000}));
      app.use(express.errorHandler());
  });
  </code></pre>