Skip to content

Commit

Permalink
Ensure the redirect URL starts with a slash (#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmajchrak authored Dec 2, 2024
1 parent 374c062 commit 60e2983
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/aai/aai.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@

if (redirectUrlFromLogin != null && redirectUrlFromLogin !== '') {
// Redirect from the login page with retrieved redirect URL
redirectUrl = window.location.origin + (namespace === '' ? namespace : '/' + namespace) + redirectUrlFromLogin;
var baseUrl = window.location.origin + formatNamespace(namespace);
var redirectPath = ensureLeadingSlash(redirectUrlFromLogin);

redirectUrl = baseUrl + redirectPath;
}

// Encode the redirect URL
Expand Down Expand Up @@ -129,6 +132,20 @@
var cookieString = name + '=' + value + ';expires=' + expirationDate.toUTCString() + ';path=/';
document.cookie = cookieString;
}

/**
* Return empty string if namespace is empty, otherwise return namespace with leading slash.
*/
function formatNamespace(namespace) {
return namespace === '' ? '' : ensureLeadingSlash(namespace);
}

/**
* Ensure that the path starts with a leading slash.
*/
function ensureLeadingSlash(path) {
return path.startsWith('/') ? path : '/' + path;
}
}

if (!window.aai) {
Expand Down

0 comments on commit 60e2983

Please sign in to comment.