Skip to content

Commit

Permalink
WEBUI-1511: Own Code Static Scan : Open Redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
alokhyland committed May 28, 2024
1 parent cc8d335 commit 17f7189
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 24 additions & 2 deletions elements/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ function scrollToTop(ctx, next) {
next();
}

function getTrustedDomains(path) {
const trustedDomains = Nuxeo && Nuxeo.UI && Nuxeo.UI.config && Nuxeo.UI.config.trustedDomains;
const pathUrl = new URL(path);
const { hostname } = pathUrl;
const queryParams = pathUrl.search.split('?')[1];
const encodepath = queryParams ? `${pathUrl.origin}?${encodeURIComponent(queryParams)}` : path;
if (!trustedDomains) return { encodepath, isvalidUrl: true };
const trustedDomainList = trustedDomains.split(',');
const isvalidUrl = trustedDomainList.some((url) => {
const isFullpath = /^http(s)?:\/\//.test(url);
const parsedURL = isFullpath ? url : `https://${url}`;
const { hostname: currentUrlhost } = new URL(parsedURL);
return currentUrlhost.toLowerCase() === hostname.toLowerCase();
});

return { encodepath, isvalidUrl };
}

function _routeAdmin(selectedAdminTab, errorPath, routeData) {
const hasPermission =
app.currentUser.isAdministrator || app.currentUser.extendedGroups.find((grp) => grp.name === 'powerusers');
Expand All @@ -37,7 +55,6 @@ function _routeAdmin(selectedAdminTab, errorPath, routeData) {
app.showError(404, '', errorPath);
}
}

// Routes
page('*', scrollToTop, (ctx, next) => {
next();
Expand Down Expand Up @@ -197,7 +214,12 @@ app.router = {
}
const isFullpath = /^http(s)?:\/\//.test(path);
if (isFullpath) {
window.location = path;
const { encodepath, isvalidUrl } = getTrustedDomains(path);
if (isvalidUrl) {
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 @@ -50,5 +50,9 @@

<!-- 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">${nuxeo.trustedDomains}</property>

</extension>
</component>

0 comments on commit 17f7189

Please sign in to comment.