Merge pull request #5008 from overleaf/jpa-drop-ie11-for-real

[web] redirect IE11 from all the pages to the unsupported browsers page

GitOrigin-RevId: 9124ca6feef4e82125d7948543a8bdb1d7702c3b
This commit is contained in:
Jakob Ackermann 2021-09-08 14:14:25 +02:00 committed by Copybot
parent 7919017118
commit 827768be92
3 changed files with 50 additions and 3 deletions

View file

@ -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 })

View file

@ -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

View file

@ -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(