From a967253afa0e2bfedf9981428b62f9657a221f97 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Sun, 10 Mar 2019 03:19:42 +0000 Subject: [PATCH 1/5] chore(deps): update dependency jsdom to v14 --- install/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/package.json b/install/package.json index 61f154e98f..9cc3685ed1 100644 --- a/install/package.json +++ b/install/package.json @@ -141,7 +141,7 @@ "grunt": "1.0.3", "grunt-contrib-watch": "1.1.0", "husky": "1.3.1", - "jsdom": "13.2.0", + "jsdom": "14.0.0", "lint-staged": "8.1.4", "mocha": "6.0.1", "mocha-lcov-reporter": "1.3.0", From 2cb0bdea9a47f77b09f82005404762d8ae45b484 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 12 Mar 2019 16:34:23 +0000 Subject: [PATCH 2/5] chore(deps): update node:8.15.1 docker digest to c151597 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a973757a4d..8bc6f85444 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # The base image is the latest 8.x node (LTS) -FROM node:8.15.1@sha256:287b8a533675e0c72cb374b5e5ab580961b2a203600e1758b95c475390bd9f9a +FROM node:8.15.1@sha256:c151597d05a3c8c4e7b2e988f71c8cd645235d96f39a47b16b1930ef9e7a5aab RUN mkdir -p /usr/src/app WORKDIR /usr/src/app From 02804fe9c47c5f37f27d1879b7a77a8154dbd987 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 13 Mar 2019 15:46:35 +0000 Subject: [PATCH 3/5] fix(deps): update dependency connect-redis to v3.4.1 --- install/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/package.json b/install/package.json index a06cdc0878..4cbfded919 100644 --- a/install/package.json +++ b/install/package.json @@ -49,7 +49,7 @@ "connect-mongo": "2.0.3", "connect-multiparty": "^2.1.0", "connect-pg-simple": "^5.0.0", - "connect-redis": "3.4.0", + "connect-redis": "3.4.1", "continuation-local-storage": "^3.2.1", "cookie-parser": "^1.4.3", "cron": "^1.3.0", From d8486e887a8191bb845e722e4206797569865bed Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 5 Mar 2019 02:53:05 +0000 Subject: [PATCH 4/5] chore(deps): update dependency eslint to v5.15.1 --- install/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/package.json b/install/package.json index 9f65c25efa..98ce967f5d 100644 --- a/install/package.json +++ b/install/package.json @@ -135,7 +135,7 @@ "@commitlint/cli": "7.5.2", "@commitlint/config-angular": "7.5.0", "coveralls": "3.0.3", - "eslint": "5.14.1", + "eslint": "5.15.1", "eslint-config-airbnb-base": "13.1.0", "eslint-plugin-import": "2.16.0", "grunt": "1.0.3", From d2cfe6b946001828e21e6f2aa1e52b0678f31408 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 13 Mar 2019 12:38:30 -0400 Subject: [PATCH 5/5] Moved onSuccessfulLogin call from plugins to core, + auth verification hook (#7416) * fix: #7412, calling controllers.onSuccessfulLogin in core * feat: added plugin hook for auth validation --- src/controllers/authentication.js | 11 ++++++++++- src/middleware/index.js | 17 +++++++++++++++++ src/routes/authentication.js | 23 ++++++++++++++++------- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js index 5901cf5ead..56f7f12287 100644 --- a/src/controllers/authentication.js +++ b/src/controllers/authentication.js @@ -331,6 +331,15 @@ authenticationController.doLogin = function (req, uid, callback) { }; authenticationController.onSuccessfulLogin = function (req, uid, callback) { + // If already called once, return prematurely + if (req.res.locals.user) { + if (typeof callback === 'function') { + return setImmediate(callback); + } + + return true; + } + var uuid = utils.generateUUID(); req.uid = uid; @@ -392,7 +401,7 @@ authenticationController.onSuccessfulLogin = function (req, uid, callback) { if (typeof callback === 'function') { callback(err); } else { - return false; + return !!err; } }); }; diff --git a/src/middleware/index.js b/src/middleware/index.js index d2dd50b663..316d5a2ea6 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -217,3 +217,20 @@ middleware.trimUploadTimestamps = function trimUploadTimestamps(req, res, next) next(); }; + +middleware.validateAuth = function validateAuth(req, res, next) { + plugins.fireHook('static:auth.validate', { + user: res.locals.user, + strategy: res.locals.strategy, + }, function (err) { + if (err) { + return req.session.regenerate(function () { + req.uid = 0; + req.loggedIn = false; + next(err); + }); + } + + next(); + }); +}; diff --git a/src/routes/authentication.js b/src/routes/authentication.js index a4341ddf36..11e8c03432 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -100,14 +100,23 @@ Auth.reloadRoutes = function (router, callback) { return helpers.redirect(res, strategy.failureUrl !== undefined ? strategy.failureUrl : '/login'); } - req.login(user, function (err) { - if (err) { - return next(err); - } - - helpers.redirect(res, strategy.successUrl !== undefined ? strategy.successUrl : '/'); - }); + res.locals.user = user; + res.locals.strategy = strategy; + next(); })(req, res, next); + }, + Auth.middleware.validateAuth, + (req, res, next) => { + async.waterfall([ + async.apply(req.login.bind(req), res.locals.user), + async.apply(controllers.authentication.onSuccessfulLogin, req, req.uid), + ], function (err) { + if (err) { + return next(err); + } + + helpers.redirect(res, strategy.successUrl !== undefined ? strategy.successUrl : '/'); + }); }); });