Files
freeCodeCamp/api-server/server/middlewares/csurf.js
Mrugesh Mohapatra ef39ab0e20 fix(donate): allow calls to the API without auth
This is also dependent on 170e3dbf4f
2020-03-21 01:58:07 +05:30

22 lines
476 B
JavaScript

import csurf from 'csurf';
export default function() {
const protection = csurf({
cookie: {
domain: process.env.COOKIE_DOMAIN || 'localhost'
}
});
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);
};
}