test: add failing guest csrf test (#10169)

* test: add failing guest csrf test

* test: use correct var

* fix: use applyCsrf for guests as well
This commit is contained in:
Barış Soner Uşaklı
2022-01-20 18:22:10 -05:00
committed by GitHub
parent f090de3688
commit 10949184ca
2 changed files with 42 additions and 10 deletions

View File

@@ -42,12 +42,12 @@ module.exports = function (middleware) {
return true;
}
if (req.loggedIn) {
if (res.locals.isAPI && (req.loggedIn || !req.headers.hasOwnProperty('authorization'))) {
// If authenticated via cookie (express-session), protect routes with CSRF checking
if (res.locals.isAPI) {
await middleware.applyCSRFasync(req, res);
}
await middleware.applyCSRFasync(req, res);
}
if (req.loggedIn) {
return true;
} else if (req.headers.hasOwnProperty('authorization')) {
const user = await passportAuthenticateAsync(req, res);