diff --git a/services/web/app/src/infrastructure/UnsupportedBrowserMiddleware.js b/services/web/app/src/infrastructure/UnsupportedBrowserMiddleware.js index d7cf9db39e..690648f26d 100644 --- a/services/web/app/src/infrastructure/UnsupportedBrowserMiddleware.js +++ b/services/web/app/src/infrastructure/UnsupportedBrowserMiddleware.js @@ -6,6 +6,10 @@ const { getSafeRedirectPath } = require('../Features/Helpers/UrlHelper') function unsupportedBrowserMiddleware(req, res, next) { if (!Settings.unsupportedBrowsers) return next() + // Prevent redirect loop + const path = Url.parse(req.url).pathname + if (path === '/unsupported-browser') return next() + const userAgent = req.headers['user-agent'] if (!userAgent) return next() @@ -33,7 +37,8 @@ function renderUnsupportedBrowserPage(req, res) { let fromURL if (typeof req.query.fromURL === 'string') { try { - fromURL = Settings.siteUrl + getSafeRedirectPath(req.query.fromURL) + fromURL = + Settings.siteUrl + (getSafeRedirectPath(req.query.fromURL) || '/') } catch (e) {} } res.render('general/unsupported-browser', { fromURL }) diff --git a/services/web/app/src/router.js b/services/web/app/src/router.js index 88c4f423a9..925da72c0a 100644 --- a/services/web/app/src/router.js +++ b/services/web/app/src/router.js @@ -62,6 +62,8 @@ const _ = require('underscore') module.exports = { initialize } function initialize(webRouter, privateApiRouter, publicApiRouter) { + webRouter.use(unsupportedBrowserMiddleware) + if (!Settings.allowPublicAccess) { webRouter.all('*', AuthenticationController.requireGlobalLogin) } @@ -277,7 +279,6 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) { maxRequests: 30, timeInterval: 60, }), - unsupportedBrowserMiddleware, ProjectController.projectListPage ) webRouter.post( @@ -299,7 +300,6 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) { maxRequests: 15, timeInterval: 60, }), - unsupportedBrowserMiddleware, AuthenticationController.validateUserSession(), AuthorizationMiddleware.ensureUserCanReadProject, ProjectController.loadEditor diff --git a/services/web/test/acceptance/src/UnsupportedBrowserTests.js b/services/web/test/acceptance/src/UnsupportedBrowserTests.js index ce087219d4..23dc7ce752 100644 --- a/services/web/test/acceptance/src/UnsupportedBrowserTests.js +++ b/services/web/test/acceptance/src/UnsupportedBrowserTests.js @@ -65,6 +65,48 @@ describe('UnsupportedBrowsers', function () { ) }) + it('redirects unsupported browsers from any page', function (done) { + const url = '/foo/bar/baz' + this.user.request( + { + url, + headers: { + // IE11 user agent + 'user-agent': + 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko', + }, + }, + (error, response) => { + expect(error).to.not.exist + expect(response.statusCode).to.equal(302) + expect(response.headers.location).to.equal( + '/unsupported-browser?fromURL=' + encodeURIComponent(url) + ) + done() + } + ) + }) + + it('should render the unsupported browser page for unsupported browser', function (done) { + const url = + '/unsupported-browser?fromURL=' + encodeURIComponent('/foo/bar/baz') + this.user.request( + { + url, + headers: { + // IE11 user agent + 'user-agent': + 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko', + }, + }, + (error, response) => { + expect(error).to.not.exist + expect(response.statusCode).to.equal(200) + done() + } + ) + }) + it('shows the previous URL', function (done) { const url = '/project/60867f47174dfd13f1e00000' this.user.request(