UI: fix blank screen when redirect to unknown app route
@@ -97,6 +97,8 @@ import {
} from '../requests';
import { baseApi } from './axios-config';
import Utils, { getDisplaySegmentStatus } from './Utils';
+import { matchPath } from 'react-router';
+import RouterData from '../router';
const JSONbig = require('json-bigint')({'storeAsString': true})
// This method is used to display tenants listing on cluster manager home page
@@ -1006,6 +1008,37 @@ const getAccessTokenFromHashParams = () => {
return accessToken;
};
+
+// validates app redirect path with known routes
+const validateRedirectPath = (path: string): boolean => {
+ if(!path) {
+ return false;
+ }
+
+ if(!path.startsWith("/")) {
+ path = "/" + path;
+ }
+
+ let pathName = "";
+
+ try {
+ const appUrl = new URL(location.origin + path);
+ pathName = appUrl.pathname;
+ } catch(err) {
+ console.error(err);
+ return false;
+ }
+
+ const knownAppRoutes = RouterData.map((data) => data.path);
+ const routeMatches = matchPath(pathName, {path: knownAppRoutes, exact: true});
+
+ if(!routeMatches) {
+ return false;
+ }
+
+ return true;
+};
+
const getURLWithoutAccessToken = (fallbackUrl = '/'): string => {
let prefix = '';
let url = location.hash.substring(1);
@@ -1037,6 +1070,12 @@ const getURLWithoutAccessToken = (fallbackUrl = '/'): string => {
}
url = urlParams.join('&');
+
+ if(!validateRedirectPath(url)) {
+ // constructed redirect url is not a valid app route
+ // redirect to fallBackUrl
+ url = fallbackUrl;
+ }
} else {
url = fallbackUrl;
}
