Files
freeCodeCamp/api-server/server/middlewares/csurf.js
Oliver Eyton-Williams b3d5cde75e fix(api): csurf to SameSite 'strict', https only (#39077)
Lax and http are probably sufficient, but if the stricter versions work
there's no harm using them.
2020-06-16 20:48:48 +05:30

24 lines
522 B
JavaScript

import csurf from 'csurf';
export default function() {
const protection = csurf({
cookie: {
domain: process.env.COOKIE_DOMAIN || 'localhost',
sameSite: 'strict',
secure: true
}
});
return function csrf(req, res, next) {
const { path } = req;
if (
// eslint-disable-next-line max-len
/^\/hooks\/update-paypal$|^\/hooks\/update-stripe$|^\/donate\/charge-stripe$/.test(
path
)
) {
return next();
}
return protection(req, res, next);
};
}