mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 08:17:57 +02:00
feat: require csrf token if not using bearer token
This commit is contained in:
@@ -48,6 +48,7 @@ middleware.applyCSRF = function (req, res, next) {
|
||||
next();
|
||||
}
|
||||
};
|
||||
middleware.applyCSRFasync = util.promisify(middleware.applyCSRF);
|
||||
|
||||
middleware.ensureLoggedIn = ensureLoggedIn.ensureLoggedIn(nconf.get('relative_path') + '/login');
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ module.exports = function (middleware) {
|
||||
const loginAsync = util.promisify(req.login).bind(req);
|
||||
|
||||
if (req.loggedIn) {
|
||||
if (res.locals.isAPI) {
|
||||
await middleware.applyCSRFasync(req, res);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (req.headers.hasOwnProperty('authorization')) {
|
||||
const user = await passportAuthenticateAsync(req, res);
|
||||
|
||||
Reference in New Issue
Block a user