diff --git a/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee b/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee index 765065823b..7a913604d9 100644 --- a/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee +++ b/services/web/app/coffee/Features/Authentication/AuthenticationController.coffee @@ -189,10 +189,11 @@ module.exports = AuthenticationController = Metrics.inc "user.login.failed" callback() - _setRedirectInSession: (req) -> - target = if Object.keys(req.query) then "#{req.path}?#{querystring.stringify(req.query)}" else req.path + _setRedirectInSession: (req, value) -> + if !value? + value = if Object.keys(req.query) > 0 then "#{req.path}?#{querystring.stringify(req.query)}" else req.path if req.session? - req.session.postLoginRedirect = target + req.session.postLoginRedirect = value _getRedirectFromSession: (req) -> return req?.session?.postLoginRedirect || null diff --git a/services/web/app/coffee/Features/Authorization/AuthorizationMiddlewear.coffee b/services/web/app/coffee/Features/Authorization/AuthorizationMiddlewear.coffee index cb0f583674..be0a85107c 100644 --- a/services/web/app/coffee/Features/Authorization/AuthorizationMiddlewear.coffee +++ b/services/web/app/coffee/Features/Authorization/AuthorizationMiddlewear.coffee @@ -108,5 +108,5 @@ module.exports = AuthorizationMiddlewear = logger.log {from: from}, "redirecting to login" redirect_to = "/login" if from? - redirect_to += "?redir=#{encodeURIComponent(from)}" + AuthenticationController._setRedirectInSession(req, from) res.redirect redirect_to diff --git a/services/web/test/UnitTests/coffee/Authentication/AuthenticationControllerTests.coffee b/services/web/test/UnitTests/coffee/Authentication/AuthenticationControllerTests.coffee index 7dd2617e66..378c3bafd2 100644 --- a/services/web/test/UnitTests/coffee/Authentication/AuthenticationControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Authentication/AuthenticationControllerTests.coffee @@ -541,6 +541,10 @@ describe "AuthenticationController", -> @AuthenticationController._setRedirectInSession(@req) expect(@req.session.postLoginRedirect).to.equal "/somewhere?one=1" + it 'should set the supplied value', -> + @AuthenticationController._setRedirectInSession(@req, '/somewhere/specific') + expect(@req.session.postLoginRedirect).to.equal "/somewhere/specific" + describe '_getRedirectFromSession', -> beforeEach -> @req = {session: {postLoginRedirect: "/a?b=c"}}