Skip to content

Commit

Permalink
Don't always redirect to the current window's URL if the redirect URL…
Browse files Browse the repository at this point in the history
… is __SELF__

Please see code comments for an explanation.

refs #8626
  • Loading branch information
lippserd committed Mar 11, 2015
1 parent 846a22e commit 031f9dd
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions public/js/icinga/loader.js
Expand Up @@ -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
);
Expand Down

0 comments on commit 031f9dd

Please sign in to comment.