Skip to content
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
2 changes: 1 addition & 1 deletion config/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
FEATURE_EXTENSIONS_ENABLED,
SHOW_VERSION,
SW_ENABLED,
HOST,
HOST = 'http://localhost',
PORT = '3100',
FEATURE_ENTERTHECLOUD,
FEATURE_JWT_EXTENDED_TIMEOUT_ENABLED,
Expand Down
13 changes: 9 additions & 4 deletions helpers/redirect.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const url = require('url');
const sanitizeHtml = require('sanitize-html');
const global = require('../config/global');

/**
* Collapse leading slashes to one slash to avoid redirects to other websides
* @param {string} redirectUrl URL to which the user should be redirected
* @returns {string} URL without multiple leading slashes
*/
const collapseLeadingSlashes = (redirectUrl) => redirectUrl.replace(/^\/*/, '/');
const collapseLeadingSlashes = (redirectUrl) => redirectUrl.replace(/^\/+/, '/');

/**
* Transform given URL to valid (sanitized and relative) redirect URL
Expand All @@ -16,8 +16,13 @@ const collapseLeadingSlashes = (redirectUrl) => redirectUrl.replace(/^\/*/, '/')
const getValidRedirect = (redirectUrl) => {
if (!redirectUrl) return '/';
const sanitizedUrl = sanitizeHtml(redirectUrl);
const relativeUrl = url.parse(sanitizedUrl).path || '/';
return collapseLeadingSlashes(relativeUrl);
let relativeUrl = '/';
const parsedUrl = URL.parse(collapseLeadingSlashes(sanitizedUrl), global.HOST);
if (parsedUrl) {
relativeUrl = parsedUrl.pathname + parsedUrl.search + parsedUrl.hash;
}

return relativeUrl;
};

const joinPathWithQuery = (path, paramsString) => (paramsString ? `${path}?${paramsString}` : path);
Expand Down