Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): revalidate layout after email/password login (#12285)

Ottob342bfa3baaa
diff --git a/autogpt_platform/frontend/src/app/(platform)/login/useLoginPage.ts b/autogpt_platform/frontend/src/app/(platform)/login/useLoginPage.ts
index 9b81965c31..38fc9896d1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/login/useLoginPage.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/login/useLoginPage.ts
@@ -21,8 +21,14 @@ export function useLoginPage() {
const [showNotAllowedModal, setShowNotAllowedModal] = useState(false);
const isCloudEnv = environment.isCloud();
- // Get redirect destination from 'next' query parameter
- const nextUrl = searchParams.get("next");
+ // Get redirect destination from 'next' query parameter.
+ // Only allow relative paths to prevent open redirect attacks
+ // (e.g., /login?next=https://phishing.site).
+ const rawNext = searchParams.get("next");
+ const nextUrl =
+ rawNext && rawNext.startsWith("/") && !rawNext.startsWith("//")
+ ? rawNext
+ : null;
useEffect(() => {
if (isLoggedIn && !isLoggingIn) {
@@ -93,8 +99,11 @@ export function useLoginPage() {
throw new Error(result.error || "Login failed");
}
- // Prefer URL's next parameter, then use backend-determined route
- router.replace(nextUrl || result.next || "/");
+ // Use full page navigation to ensure middleware processes the new auth cookies.
+ // router.replace() does a soft navigation where the cookie store may not
+ // immediately reflect cookies set by the server action, causing a blank page.
+ // This matches the OAuth flow which also uses window.location.href.
+ window.location.href = nextUrl || result.next || "/";
} catch (error) {
toast({
title: