2016-05-03 00:22:56 +00:00
|
|
|
import csurf from 'csurf';
|
|
|
|
|
|
|
|
export default function() {
|
2019-02-18 19:32:49 +00:00
|
|
|
const protection = csurf({
|
|
|
|
cookie: {
|
2020-06-16 15:18:48 +00:00
|
|
|
domain: process.env.COOKIE_DOMAIN || 'localhost',
|
|
|
|
sameSite: 'strict',
|
|
|
|
secure: true
|
2018-05-23 20:10:56 +00:00
|
|
|
}
|
2019-02-18 19:32:49 +00:00
|
|
|
});
|
2016-05-03 04:11:49 +00:00
|
|
|
return function csrf(req, res, next) {
|
2020-03-19 06:50:04 +00:00
|
|
|
const { path } = req;
|
2020-03-20 20:09:29 +00:00
|
|
|
if (
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
/^\/hooks\/update-paypal$|^\/hooks\/update-stripe$|^\/donate\/charge-stripe$/.test(
|
|
|
|
path
|
|
|
|
)
|
|
|
|
) {
|
2016-05-03 04:11:49 +00:00
|
|
|
return next();
|
|
|
|
}
|
|
|
|
return protection(req, res, next);
|
|
|
|
};
|
2016-05-03 00:22:56 +00:00
|
|
|
}
|