fix: handle when request url has no valid referer

Signed-off-by: Max Wu <jackymaxj@gmail.com>
This commit is contained in:
Max Wu 2021-05-13 11:49:19 +08:00
parent 37b656df93
commit 5e709653ab
1 changed files with 9 additions and 2 deletions

View File

@ -8,8 +8,15 @@ exports.setReturnToFromReferer = function setReturnToFromReferer (req) {
if (!req.session) req.session = {}
var referer = req.get('referer')
var refererSearchParams = new URLSearchParams(new URL(referer).search)
var nextURL = refererSearchParams.get('next')
var nextURL
if (referer) {
try {
var refererSearchParams = new URLSearchParams(new URL(referer).search)
nextURL = refererSearchParams.get('next')
} catch (err) {
logger.warn(err)
}
}
if (nextURL) {
var isRelativeNextURL = nextURL.indexOf('://') === -1 && !nextURL.startsWith('//')