mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #3959 from overleaf/jpa-take-note-of-past-url
[UnsupportedBrowserMiddleware] take note of the past URL in redirect GitOrigin-RevId: d80ed876f87e54c181f00669a11795a2ce44e5a5
This commit is contained in:
parent
cf496e1fd2
commit
23c73b9bf1
4 changed files with 78 additions and 7 deletions
|
@ -1,5 +1,7 @@
|
|||
const Bowser = require('bowser')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const Url = require('url')
|
||||
const { getSafeRedirectPath } = require('../Features/Helpers/UrlHelper')
|
||||
|
||||
function unsupportedBrowserMiddleware(req, res, next) {
|
||||
if (!Settings.unsupportedBrowsers) return next()
|
||||
|
@ -16,10 +18,28 @@ function unsupportedBrowserMiddleware(req, res, next) {
|
|||
|
||||
const isUnsupported = parser.satisfies(Settings.unsupportedBrowsers)
|
||||
if (isUnsupported) {
|
||||
return res.redirect('/unsupported-browser')
|
||||
return res.redirect(
|
||||
Url.format({
|
||||
pathname: '/unsupported-browser',
|
||||
query: { fromURL: req.originalUrl },
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
module.exports = { unsupportedBrowserMiddleware }
|
||||
function renderUnsupportedBrowserPage(req, res) {
|
||||
let fromURL
|
||||
if (typeof req.query.fromURL === 'string') {
|
||||
try {
|
||||
fromURL = Settings.siteUrl + getSafeRedirectPath(req.query.fromURL)
|
||||
} catch (e) {}
|
||||
}
|
||||
res.render('general/unsupported-browser', { fromURL })
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
renderUnsupportedBrowserPage,
|
||||
unsupportedBrowserMiddleware,
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ const UserMembershipRouter = require('./Features/UserMembership/UserMembershipRo
|
|||
const SystemMessageController = require('./Features/SystemMessages/SystemMessageController')
|
||||
const { Joi, validate } = require('./infrastructure/Validation')
|
||||
const {
|
||||
renderUnsupportedBrowserPage,
|
||||
unsupportedBrowserMiddleware,
|
||||
} = require('./infrastructure/UnsupportedBrowserMiddleware')
|
||||
|
||||
|
@ -1143,9 +1144,7 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
|
|||
TokenAccessController.grantTokenAccessReadOnly
|
||||
)
|
||||
|
||||
webRouter.get('/unsupported-browser', (req, res) => {
|
||||
res.render('general/unsupported-browser')
|
||||
})
|
||||
webRouter.get('/unsupported-browser', renderUnsupportedBrowserPage)
|
||||
|
||||
webRouter.get('*', ErrorController.notFound)
|
||||
}
|
||||
|
|
|
@ -14,3 +14,9 @@ block body
|
|||
| Sorry, we don't support your browser anymore. Find out more about #[a(href="https://www.overleaf.com/learn/how-to/What_browsers_do_you_support") what browsers we support].
|
||||
br
|
||||
| If you think you're seeing this message in error, please #[a(href="/contact") let us know].
|
||||
|
||||
if fromURL
|
||||
p
|
||||
| URL:
|
||||
|
|
||||
a(href=fromURL) #{fromURL}
|
||||
|
|
|
@ -44,9 +44,10 @@ describe('UnsupportedBrowsers', function () {
|
|||
})
|
||||
|
||||
it('redirects unsupported browsers to unsupported page', function (done) {
|
||||
const url = '/project'
|
||||
this.user.request(
|
||||
{
|
||||
url: '/project',
|
||||
url,
|
||||
headers: {
|
||||
// IE11 user agent
|
||||
'user-agent':
|
||||
|
@ -56,7 +57,52 @@ describe('UnsupportedBrowsers', function () {
|
|||
(error, response) => {
|
||||
expect(error).to.not.exist
|
||||
expect(response.statusCode).to.equal(302)
|
||||
expect(response.headers.location).to.equal('/unsupported-browser')
|
||||
expect(response.headers.location).to.equal(
|
||||
'/unsupported-browser?fromURL=' + encodeURIComponent(url)
|
||||
)
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('shows the previous URL', function (done) {
|
||||
const url = '/project/60867f47174dfd13f1e00000'
|
||||
this.user.request(
|
||||
{
|
||||
url: '/unsupported-browser?fromURL=' + encodeURIComponent(url),
|
||||
headers: {
|
||||
// IE11 user agent
|
||||
'user-agent':
|
||||
'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko',
|
||||
},
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(error).to.not.exist
|
||||
expect(response.statusCode).to.equal(200)
|
||||
expect(body).to.include('URL:')
|
||||
expect(body).to.include(url)
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('shows a sanitized URL', function (done) {
|
||||
const url = 'https://evil.com/the/pathname'
|
||||
this.user.request(
|
||||
{
|
||||
url: '/unsupported-browser?fromURL=' + encodeURIComponent(url),
|
||||
headers: {
|
||||
// IE11 user agent
|
||||
'user-agent':
|
||||
'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko',
|
||||
},
|
||||
},
|
||||
(error, response, body) => {
|
||||
expect(error).to.not.exist
|
||||
expect(response.statusCode).to.equal(200)
|
||||
expect(body).to.include('URL:')
|
||||
expect(body).to.not.include('evil.com')
|
||||
expect(body).to.include('/the/pathname')
|
||||
done()
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue