fix: only allow redirects to /admin sub-routes
This commit is contained in:
@@ -315,7 +315,7 @@ const Routes: React.FC = () => {
|
||||
<Unauthorized />
|
||||
)}
|
||||
</Fragment>
|
||||
) : <Redirect to={`${match.url}/login?redirect=${encodeURIComponent(window.location.pathname)}`} />}
|
||||
) : <Redirect to={`${match.url}/login${window.location.pathname.startsWith(routes.admin) ? `?redirect=${encodeURIComponent(window.location.pathname.replace(routes.admin, ''))}` : ''}`} />}
|
||||
</Route>
|
||||
<Route path={`${match.url}*`}>
|
||||
<NotFound />
|
||||
|
||||
@@ -64,7 +64,12 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
setUser(json.user);
|
||||
} else {
|
||||
setUser(null);
|
||||
push(`${admin}${logoutInactivityRoute}?redirect=${encodeURIComponent(window.location.pathname)}`);
|
||||
if (window.location.pathname.startsWith(admin)) {
|
||||
const redirectParam = `?redirect=${encodeURIComponent(window.location.pathname.replace(admin, ''))}`;
|
||||
push(`${admin}${logoutInactivityRoute}${redirectParam}`);
|
||||
} else {
|
||||
push(`${admin}${logoutInactivityRoute}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
toast.error(e.message);
|
||||
@@ -220,7 +225,12 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||
if (remainingTime > 0) {
|
||||
forceLogOut = setTimeout(() => {
|
||||
setUser(null);
|
||||
push(`${admin}${logoutInactivityRoute}?redirect=${encodeURIComponent(window.location.pathname)}`);
|
||||
if (window.location.pathname.startsWith(admin)) {
|
||||
const redirectParam = `?redirect=${encodeURIComponent(window.location.pathname.replace(admin, ''))}`;
|
||||
push(`${admin}${logoutInactivityRoute}${redirectParam}`);
|
||||
} else {
|
||||
push(`${admin}${logoutInactivityRoute}`);
|
||||
}
|
||||
closeAllModals();
|
||||
}, Math.min(remainingTime * 1000, maxTimeoutTime));
|
||||
}
|
||||
|
||||
@@ -51,7 +51,8 @@ const Login: React.FC = () => {
|
||||
if (data.token) {
|
||||
setToken(data.token);
|
||||
|
||||
history.push(redirect || admin);
|
||||
// Ensure the redirect always starts with the admin route, and concatenate the redirect path
|
||||
history.push(admin + (redirect || ''));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user