diff --git a/backend/docs/SSO.md b/backend/docs/SSO.md
index 86388c95ab..fc1c28dfe7 100644
--- a/backend/docs/SSO.md
+++ b/backend/docs/SSO.md
@@ -300,6 +300,8 @@ The frontend handles the post-SSO flow at `/auth/callback`:
3. On success: redirects to the workspace (or the original `next` path)
4. On failure: redirects to `/login?error=sso_failed`
+The login page shows the localized message for a known `error` code. Any other value, including an inherited object key such as `__proto__` or `constructor`, shows the generic "Authentication failed." message.
+
## Security Notes
- **State cookies** are HttpOnly, SameSite=Lax, Max-Age=300 seconds, and signed with the JWT secret
diff --git a/frontend/src/app/(auth)/login/page.tsx b/frontend/src/app/(auth)/login/page.tsx
index 1d02135f68..e1d0ba244a 100644
--- a/frontend/src/app/(auth)/login/page.tsx
+++ b/frontend/src/app/(auth)/login/page.tsx
@@ -23,6 +23,18 @@ import {
} from "@/core/auth/setup";
import { parseAuthError } from "@/core/auth/types";
import { useI18n } from "@/core/i18n/hooks";
+import type { Translations } from "@/core/i18n/locales/types";
+
+/** The message for a `?error=` code, or the generic failure. */
+function loginErrorMessage(t: Translations, code: string) {
+ // The code comes from the URL, so only the table's own keys name a message.
+ // An inherited key such as `__proto__` or `constructor` resolves to an
+ // object or a function instead. The page renders the object, and
+ // `useState` calls the function as an initializer; both can crash the page.
+ return Object.hasOwn(t.login.errors, code)
+ ? t.login.errors[code as keyof typeof t.login.errors]
+ : t.login.authFailed;
+}
export default function LoginPage() {
const router = useRouter();
@@ -54,8 +66,7 @@ export default function LoginPage() {
const ssrDisabled = useContext(AuthDisabledContext);
const [error, setError] = useState(
errorParam
- ? (t.login.errors[errorParam as keyof typeof t.login.errors] ??
- t.login.authFailed)
+ ? loginErrorMessage(t, errorParam)
: ssrDisabled
? t.login.errors.account_disabled
: "",
diff --git a/frontend/tests/unit/app/login-account-disabled.dom.test.tsx b/frontend/tests/unit/app/login-account-disabled.dom.test.tsx
index 417f9cffde..f09b5c6deb 100644
--- a/frontend/tests/unit/app/login-account-disabled.dom.test.tsx
+++ b/frontend/tests/unit/app/login-account-disabled.dom.test.tsx
@@ -22,9 +22,11 @@ rs.mock("@/core/auth/AuthProvider", () => ({
useAuth: rs.fn(),
}));
rs.mock("@/core/i18n/hooks", () => ({ useI18n: () => ({ t: enUS }) }));
+const navigationState = rs.hoisted(() => ({ search: "" }));
+
rs.mock("next/navigation", () => ({
useRouter: () => ({ push: rs.fn() }),
- useSearchParams: () => new URLSearchParams(),
+ useSearchParams: () => new URLSearchParams(navigationState.search),
}));
rs.mock("next-themes", () => ({
useTheme: () => ({ theme: "light", resolvedTheme: "light" }),
@@ -57,6 +59,7 @@ beforeEach(() => {
afterEach(() => {
cleanup();
rs.clearAllMocks();
+ navigationState.search = "";
});
function fillAndSubmit() {
@@ -156,3 +159,26 @@ test("sign-up keeps the backend message so a disabled account cannot be probed",
expect(await screen.findByText("Account disabled")).toBeTruthy();
expect(screen.queryByText(enUS.login.errors.account_disabled)).toBeNull();
});
+
+test("a known ?error= code shows its localized message", () => {
+ navigationState.search = "?error=sso_failed";
+ render();
+
+ expect(screen.getByText(enUS.login.errors.sso_failed)).toBeTruthy();
+});
+
+// The code comes from the URL. An inherited key names no message: `__proto__`
+// resolves to an object and the others to functions that `useState` would
+// call, so each one crashed the page or showed a junk string.
+test.each([
+ "__proto__",
+ "constructor",
+ "valueOf",
+ "hasOwnProperty",
+ "toString",
+])("an inherited ?error=%s shows the generic failure", (code) => {
+ navigationState.search = `?error=${code}`;
+ render();
+
+ expect(screen.getByText(enUS.login.authFailed)).toBeTruthy();
+});