Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(auth): breadcrumb SSO check JSON.parse transport failures (#16550)

cursor[bot]81f22e596a8c
diff --git a/web/src/__tests__/auth-sign-in-page.clienttest.tsx b/web/src/__tests__/auth-sign-in-page.clienttest.tsx
index 59d80bac4a..bd654c28c5 100644
--- a/web/src/__tests__/auth-sign-in-page.clienttest.tsx
+++ b/web/src/__tests__/auth-sign-in-page.clienttest.tsx
@@ -268,3 +268,104 @@ describe("sign-in page JumpCloud provider button", () => {
expect(screen.queryByLabelText("Email")).not.toBeInTheDocument();
});
});
+
+describe("sign-in page SSO check transport errors", () => {
+ let warnSpy: ReturnType<typeof vi.spyOn>;
+
+ beforeEach(() => {
+ captureExceptionMock.mockClear();
+ addBreadcrumbMock.mockClear();
+ signInMock.mockReset();
+ routerState.query = {};
+ window.localStorage.clear();
+ warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
+ });
+
+ afterEach(() => {
+ warnSpy.mockRestore();
+ vi.unstubAllGlobals();
+ });
+
+ it("breadcrumbs a JSON.parse failure on check-sso instead of capturing", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn().mockResolvedValue(
+ new Response("<html>gateway</html>", {
+ status: 200,
+ headers: { "Content-Type": "text/html" },
+ }),
+ ),
+ );
+
+ renderSignIn({
+ authProviders: { ...authProviders, sso: true },
+ });
+
+ fireEvent.change(screen.getByLabelText("Email"), {
+ target: { value: "[email protected]" },
+ });
+ fireEvent.click(screen.getByTestId("submit-email-password-sign-in-form"));
+
+ await waitFor(() => {
+ expect(
+ screen.getByText(/Unable to check SSO configuration/),
+ ).toBeInTheDocument();
+ });
+ expect(addBreadcrumbMock).toHaveBeenCalledTimes(1);
+ expect(addBreadcrumbMock.mock.calls[0]![0].category).toBe(
+ "auth.signIn.checkSso",
+ );
+ expect(captureExceptionMock).not.toHaveBeenCalled();
+ });
+
+ // Negative fixture: unexpected check-sso failures must still capture.
+ it("still captures an unexpected check-sso failure", async () => {
+ vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("boom")));
+
+ renderSignIn({
+ authProviders: { ...authProviders, sso: true },
+ });
+
+ fireEvent.change(screen.getByLabelText("Email"), {
+ target: { value: "[email protected]" },
+ });
+ fireEvent.click(screen.getByTestId("submit-email-password-sign-in-form"));
+
+ await waitFor(() => {
+ expect(captureExceptionMock).toHaveBeenCalledTimes(1);
+ });
+ const [err, options] = captureExceptionMock.mock.calls[0]!;
+ expect(err.message).toBe("boom");
+ expect(options.tags.area).toBe("auth.signIn.checkSso");
+ expect(addBreadcrumbMock).not.toHaveBeenCalled();
+ expect(
+ screen.getByText(/Unable to check SSO configuration/),
+ ).toBeInTheDocument();
+ });
+
+ // Non-JSON SyntaxErrors must still capture (classifier allowlist only).
+ it("still captures a non-JSON SyntaxError from check-sso", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn().mockRejectedValue(new SyntaxError("Invalid regular expression")),
+ );
+
+ renderSignIn({
+ authProviders: { ...authProviders, sso: true },
+ });
+
+ fireEvent.change(screen.getByLabelText("Email"), {
+ target: { value: "[email protected]" },
+ });
+ fireEvent.click(screen.getByTestId("submit-email-password-sign-in-form"));
+
+ await waitFor(() => {
+ expect(captureExceptionMock).toHaveBeenCalledTimes(1);
+ });
+ const [err, options] = captureExceptionMock.mock.calls[0]!;
+ expect(err).toBeInstanceOf(SyntaxError);
+ expect(err.message).toBe("Invalid regular expression");
+ expect(options.tags.area).toBe("auth.signIn.checkSso");
+ expect(addBreadcrumbMock).not.toHaveBeenCalled();
+ });
+});
diff --git a/web/src/features/auth/lib/expectedAuthErrors.clienttest.ts b/web/src/features/auth/lib/expectedAuthErrors.clienttest.ts
index 436a372884..03539bc983 100644
--- a/web/src/features/auth/lib/expectedAuthErrors.clienttest.ts
+++ b/web/src/features/auth/lib/expectedAuthErrors.clienttest.ts
@@ -4,6 +4,7 @@ import {
isExpectedSignInError,
isExpectedAuthErrorPageMessage,
isNextAuthMissingSignInUrlError,
+ isJsonParseSyntaxError,
} from "@/src/features/auth/lib/expectedAuthErrors";
import { MULTI_TENANT_SSO_DOMAIN_MISMATCH_MESSAGE } from "@/src/features/auth/constants";
@@ -94,4 +95,40 @@ describe("expectedAuthErrors", () => {
expect(isNextAuthMissingSignInUrlError(error)).toBe(false);
});
});
+
+ describe("isJsonParseSyntaxError", () => {
+ it.each([
+ "JSON.parse: unexpected character at line 1 column 1 of the JSON data", // Firefox
+ "JSON.parse: unexpected end of data at line 1 column 1 of the JSON data", // Firefox truncated
+ "Unexpected token '<', \"<html>\" is not valid JSON", // Chromium
+ "Unexpected token < in JSON at position 0", // Chromium (older)
+ "Unexpected end of JSON input", // Chromium truncated
+ "JSON Parse error: Unexpected identifier", // Safari
+ "JSON Parse error: Unexpected EOF", // Safari truncated
+ ])("classifies %j as a JSON.parse transport failure", (message) => {
+ expect(isJsonParseSyntaxError(new SyntaxError(message))).toBe(true);
+ });
+
+ // Negative fixtures: real errors MUST still flow to Sentry.
+ it("does not match a non-JSON SyntaxError", () => {
+ expect(
+ isJsonParseSyntaxError(new SyntaxError("Invalid regular expression")),
+ ).toBe(false);
+ });
+
+ it("does not match a TypeError (Failed to fetch stays classified elsewhere)", () => {
+ expect(isJsonParseSyntaxError(new TypeError("Failed to fetch"))).toBe(
+ false,
+ );
+ });
+
+ it("does not match a generic Error", () => {
+ expect(isJsonParseSyntaxError(new Error("boom"))).toBe(false);
+ });
+
+ it("does not match null/undefined", () => {
+ expect(isJsonParseSyntaxError(null)).toBe(false);
+ expect(isJsonParseSyntaxError(undefined)).toBe(false);
+ });
+ });
});
diff --git a/web/src/features/auth/lib/expectedAuthErrors.ts b/web/src/features/auth/lib/expectedAuthErrors.ts
index 7c6d7e12d6..469e963b42 100644
--- a/web/src/features/auth/lib/expectedAuthErrors.ts
+++ b/web/src/features/auth/lib/expectedAuthErrors.ts
@@ -73,3 +73,25 @@ export const isNextAuthMissingSignInUrlError = (error: unknown): boolean => {
message.includes("undefined is not a valid URL")
);
};
+
+/**
+ * True when `error` is a `SyntaxError` from `Response.json()` / `JSON.parse`
+ * on a non-JSON body (HTML error page, truncated payload, WAF challenge).
+ *
+ * `/api/auth/check-sso` always returns JSON, so a parse failure means
+ * something between server and client replaced the body — transport state
+ * the server owns, not an app bug. Chrome/Firefox/Safari word this
+ * differently; match all three. A SyntaxError that is not a JSON parse
+ * (eval, invalid regexp) still captures.
+ */
+export const isJsonParseSyntaxError = (error: unknown): boolean => {
+ if (!(error instanceof SyntaxError)) return false;
+ const message = error.message;
+ return (
+ message.includes("JSON.parse") ||
+ message.includes("JSON Parse error") ||
+ message.includes("is not valid JSON") ||
+ /in JSON at position/i.test(message) ||
+ message.includes("Unexpected end of JSON input")
+ );
+};
diff --git a/web/src/pages/auth/enterprise-sso-required.tsx b/web/src/pages/auth/enterprise-sso-required.tsx
index e286b5493f..c36a686325 100644
--- a/web/src/pages/auth/enterprise-sso-required.tsx
+++ b/web/src/pages/auth/enterprise-sso-required.tsx
@@ -18,7 +18,8 @@ import {
} from "@/src/components/ui/form";
import { Input } from "@/src/components/ui/input";
import { env } from "@/src/env.mjs";
-import { captureUnknownError } from "@/src/utils/captureUnknownError";
+import { reportError } from "@/src/utils/reportError";
+import { isJsonParseSyntaxError } from "@/src/features/auth/lib/expectedAuthErrors";
const enterpriseSsoFormSchema = z.object({
email: z.email(),
@@ -124,7 +125,11 @@ export default function EnterpriseSsoRequiredPage() {
"Unable to start the Enterprise SSO sign-in flow. Please try again.",
);
} catch (err) {
- captureUnknownError("auth.enterpriseSso", err);
+ reportError(err, {
+ area: "auth.enterpriseSso",
+ expected: isJsonParseSyntaxError(err),
+ extra: { context: "auth.enterpriseSso" },
+ });
setError(
"Something went wrong while checking your Enterprise SSO configuration. Please try again.",
);
diff --git a/web/src/pages/auth/sign-in.tsx b/web/src/pages/auth/sign-in.tsx
index dae611d8d5..c44e3400b5 100644
--- a/web/src/pages/auth/sign-in.tsx
+++ b/web/src/pages/auth/sign-in.tsx
@@ -42,6 +42,7 @@ import { reportError } from "@/src/utils/reportError";
import {
isExpectedSignInError,
isNextAuthMissingSignInUrlError,
+ isJsonParseSyntaxError,
} from "@/src/features/auth/lib/expectedAuthErrors";
import { captureUnknownError } from "@/src/utils/captureUnknownError";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
@@ -848,7 +849,13 @@ export default function SignIn({
}
}, 100);
} catch (error) {
- captureUnknownError("auth.signIn.checkSso", error);
+ // JSON.parse of a non-JSON 200 (proxy/WAF HTML) is transport, not an
+ // app bug — breadcrumb it. Unknown failures still capture.
+ reportError(error, {
+ area: "auth.signIn.checkSso",
+ expected: isJsonParseSyntaxError(error),
+ extra: { context: "auth.signIn.checkSso" },
+ });
setCredentialsFormError(
"Unable to check SSO configuration. Please try again.",
);
diff --git a/web/src/pages/auth/sign-up.tsx b/web/src/pages/auth/sign-up.tsx
index bf3b4aa563..f66c34aa61 100644
--- a/web/src/pages/auth/sign-up.tsx
+++ b/web/src/pages/auth/sign-up.tsx
@@ -30,7 +30,8 @@ import { PasswordInput } from "@/src/components/design-system/PasswordInput/Pass
import { useLangfuseCloudRegion } from "@/src/features/organizations/hooks";
import { useRouter } from "next/router";
import { getSafeRedirectPath } from "@/src/utils/redirect";
-import { captureUnknownError } from "@/src/utils/captureUnknownError";
+import { reportError } from "@/src/utils/reportError";
+import { isJsonParseSyntaxError } from "@/src/features/auth/lib/expectedAuthErrors";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import useLocalStorage from "@/src/components/useLocalStorage";
import { noUrlCheck, StringNoHTMLNonEmpty } from "@langfuse/shared";
@@ -183,7 +184,11 @@ function StandardSignupFlow({
}
}, 100);
} catch (error) {
- captureUnknownError("auth.signUp.checkSso", error);
+ reportError(error, {
+ area: "auth.signUp.checkSso",
+ expected: isJsonParseSyntaxError(error),
+ extra: { context: "auth.signUp.checkSso" },
+ });
setFormError("Unable to check SSO configuration. Please try again.");
} finally {
setContinueLoading(false);