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

N21-2389 fix redirect uri #3576

Merged
merged 10 commits into from
Feb 3, 2025
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
Loading