Skip to content

Instantly share code, notes, and snippets.

@Dornhoth
Last active November 26, 2019 16:05
Show Gist options
  • Save Dornhoth/b3b49ac3ad8df4d23e0f7f8943061a3c to your computer and use it in GitHub Desktop.
Save Dornhoth/b3b49ac3ad8df4d23e0f7f8943061a3c to your computer and use it in GitHub Desktop.
import express from 'express';
import cookieParser from 'cookie-parser';
import csurf from 'csurf';
const app = express();
const csrfProtection = csurf({
cookie: true,
ignoreMethods: ['GET', 'HEAD', 'OPTIONS'],
});
app.use(cookieParser());
app.use(csrfProtection, (req, res, next): void => {
res.cookie('XSRF_TOKEN', req.csrfToken(), { httpOnly: false });
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment