Don't always redirect to the current window's URL if the redirect URL is __SELF__

Please see code comments for an explanation.

refs #8626
This commit is contained in:
Eric Lippmann 2015-03-11 21:24:56 +01:00
parent 846a22e7a1
commit 031f9ddc84
1 changed files with 22 additions and 4 deletions

View File

@ -246,13 +246,31 @@
},
processRedirectHeader: function(req) {
var icinga = this.icinga;
var redirect = req.getResponseHeader('X-Icinga-Redirect');
if (! redirect) return false;
var icinga = this.icinga,
redirect = req.getResponseHeader('X-Icinga-Redirect');
if (! redirect) {
return false;
}
redirect = decodeURIComponent(redirect);
if (redirect.match(/__SELF__/)) {
redirect = redirect.replace(/__SELF__/, encodeURIComponent(document.location.pathname + document.location.search + document.location.hash));
if (req.autorefresh) {
// Redirect to the current window's URL in case it's an auto-refresh request. If authenticated
// externally this ensures seamless re-login if the session's expired
redirect = redirect.replace(
/__SELF__/,
encodeURIComponent(
document.location.pathname + document.location.search + document.location.hash
)
);
} else {
// Redirect to the URL which required authentication. When clicking a link this ensures that we
// redirect to the link's URL instead of the current window's URL (see above)
redirect = redirect.replace(/__SELF__/, req.url);
}
}
icinga.logger.debug(
'Got redirect for ', req.$target, ', URL was ' + redirect
);