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