Skip to content

Commit

Permalink
Merge branch 'maintenance-3.1.x' into 2023-snapshot-gnerate
Browse files Browse the repository at this point in the history
  • Loading branch information
alokhyland authored Jun 14, 2024
2 parents 38b0fc8 + b3b9b22 commit d224f13
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 37 additions & 1 deletion elements/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ function scrollToTop(ctx, next) {
next();
}

function createUrlFromString(str) {
const httpRegex = /^https?:\/\//;
const wwwRegex = /www\./;
str = httpRegex.test(str) ? str : `http://${str}`;
str = wwwRegex.test(str) ? str : str.replace(/^(https?:\/\/)?/, '$1www.');
return str;
}

function isTrustedDomain(path) {
const trustedDomains = Nuxeo && Nuxeo.UI && Nuxeo.UI.config && Nuxeo.UI.config.trustedDomains;
if (!trustedDomains) return true;
const modifiedPathUrl = createUrlFromString(path);
const pathUrl = new URL(modifiedPathUrl);
const { hostname: userHostName } = pathUrl;
const trustedDomainList = trustedDomains.split(',');
const isValidUrl = trustedDomainList.some((url) => {
const updatedUrl = createUrlFromString(url);
const { hostname: currentUrlHostName } = new URL(updatedUrl);
return currentUrlHostName?.toLowerCase() === userHostName?.toLowerCase();
});
return isValidUrl;
}

function encodeQueryParams(path) {
const pathUrl = new URL(path);
const queryParams = pathUrl.search.split('?')[1];
const encodepath = queryParams ? `${pathUrl.origin}?${encodeURIComponent(queryParams)}` : path;
return encodepath;
}

function _routeAdmin(selectedAdminTab, errorPath, routeData) {
const hasPermission =
app.currentUser.isAdministrator || app.currentUser.extendedGroups.find((grp) => grp.name === 'powerusers');
Expand Down Expand Up @@ -196,7 +226,13 @@ app.router = {
}
const isFullpath = /^http(s)?:\/\//.test(path);
if (isFullpath) {
window.location = path;
const isValidUrl = isTrustedDomain(path);
if (isValidUrl) {
const encodepath = encodeQueryParams(path);
const link = document.createElement('a');
link.setAttribute('href', encodepath);
link.click();
}
} else {
page(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
<!-- Properties to be fetched when loading the user object in user management, default is empty -->
<property name="org.nuxeo.web.ui.user.management.fetch.document" list="true"></property>

<!-- allowed url to redirect -->
<property name="org.nuxeo.web.ui.trustedDomains">${org.nuxeo.web.ui.trustedDomains:=''}</property>

</extension>
</component>

0 comments on commit d224f13

Please sign in to comment.