fix only allow redirects on whitelist
This commit is contained in:
@ -12,20 +12,28 @@ const pathsOfNoReturn = [
|
||||
'css'
|
||||
];
|
||||
|
||||
const pathsWhiteList = [
|
||||
'news',
|
||||
'challenges',
|
||||
'map',
|
||||
'news'
|
||||
];
|
||||
|
||||
const pathsOfNoReturnRegex = new RegExp(pathsOfNoReturn.join('|'), 'i');
|
||||
const whiteListRegex = new RegExp(pathsWhiteList.join('|'), 'i');
|
||||
|
||||
export default function addReturnToUrl() {
|
||||
return function(req, res, next) {
|
||||
// Remember original destination before login.
|
||||
var path = req.path.split('/')[1];
|
||||
var subPath = req.path.split('/')[2];
|
||||
|
||||
if (req.method !== 'GET') {
|
||||
return next();
|
||||
}
|
||||
if (pathsOfNoReturnRegex.test(path)) {
|
||||
return next();
|
||||
}
|
||||
if (/\/stories\/\w+/i.test(req.path)) {
|
||||
if (
|
||||
req.method !== 'GET' ||
|
||||
pathsOfNoReturnRegex.test(path) ||
|
||||
!whiteListRegex.test(path) ||
|
||||
(/news/i).test(path) && (/hot/i).test(subPath)
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
req.session.returnTo = req.path;
|
||||
|
Reference in New Issue
Block a user