Last active
November 26, 2019 16:05
-
-
Save Dornhoth/b3b49ac3ad8df4d23e0f7f8943061a3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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