Skip to content

Commit

Permalink
Revert-3 : WEBUI-1511-BACKPORT: Own Code Static Scan : Open Redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
alokhyland committed Aug 7, 2024
1 parent 54f09e3 commit 4927d87
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 40 deletions.
38 changes: 1 addition & 37 deletions elements/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,6 @@ 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 @@ -226,13 +196,7 @@ app.router = {
}
const isFullpath = /^http(s)?:\/\//.test(path);
if (isFullpath) {
const isValidUrl = isTrustedDomain(path);
if (isValidUrl) {
const encodepath = encodeQueryParams(path);
const link = document.createElement('a');
link.setAttribute('href', encodepath);
link.click();
}
window.location = path;
} else {
page(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@

<!-- Max results for nuxeo select options. default is 1000.-->
<property name="org.nuxeo.web.ui.pagination.nuxeoSelectOptions.listingMaxItems">${org.nuxeo.pagination.nuxeoSelectOptions.maxAllowedItems:=1000}</property>
<!-- allowed url to redirect -->
<property name="org.nuxeo.web.ui.trustedDomains">${org.nuxeo.web.ui.trustedDomains:=''}</property>

</extension>
</component>
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const assets = ['images', 'fonts', 'themes'].map((p) => {

const production = merge([
{
devtool: 'source-map' /* // enable this if you need sourcemaps on the production version */,
/* devtool: 'source-map', // enable this if you need sourcemaps on the production version */
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
Expand Down

0 comments on commit 4927d87

Please sign in to comment.