Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEBUI-1511: Own Code Static Scan : Open Redirect #2247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions elements/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ 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 +54,6 @@ function _routeAdmin(selectedAdminTab, errorPath, routeData) {
app.showError(404, '', errorPath);
}
}

// Routes
page('*', scrollToTop, (ctx, next) => {
next();
Expand Down Expand Up @@ -197,7 +213,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 @@ -36,7 +36,6 @@
<!-- S3 Direct upload -->
<property name="org.nuxeo.web.ui.s3.useDirectUpload">${nuxeo.s3storage.useDirectUpload:=false}</property>


<!-- Redirect to final download url -->
<property name="org.nuxeo.web.ui.url.followRedirect">${org.nuxeo.download.url.follow.redirect:=false}</property>

Expand All @@ -51,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>
</component>
Loading