From 4927d87295600d37e6872c19d22ed6a7344be136 Mon Sep 17 00:00:00 2001 From: alokhyland Date: Wed, 7 Aug 2024 21:08:19 +0530 Subject: [PATCH] Revert-3 : WEBUI-1511-BACKPORT: Own Code Static Scan : Open Redirect --- elements/routing.js | 38 +------------------ .../resources/OSGI-INF/web-ui-properties.xml | 2 - webpack.config.js | 2 +- 3 files changed, 2 insertions(+), 40 deletions(-) diff --git a/elements/routing.js b/elements/routing.js index 1c3037cce8..6585010dea 100644 --- a/elements/routing.js +++ b/elements/routing.js @@ -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'); @@ -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); } diff --git a/plugin/web-ui/addon/src/main/resources/OSGI-INF/web-ui-properties.xml b/plugin/web-ui/addon/src/main/resources/OSGI-INF/web-ui-properties.xml index b5ec6b3a81..c3f89772ea 100644 --- a/plugin/web-ui/addon/src/main/resources/OSGI-INF/web-ui-properties.xml +++ b/plugin/web-ui/addon/src/main/resources/OSGI-INF/web-ui-properties.xml @@ -53,8 +53,6 @@ ${org.nuxeo.pagination.nuxeoSelectOptions.maxAllowedItems:=1000} - - ${org.nuxeo.web.ui.trustedDomains:=''} \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 76180c1c5d..372f7ca404 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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({