fix(login): refactor SAML Post Flow to bypass cookie limits, fix SAML SP post (#11170)

Closes #10816
Closes #10759

# Which Problems Are Solved

This PR refactors the SAML Post binding flow to address issues with
payloads exceeding browser cookie size limits (typically ~4KB).
Previously, the SAML form data was serialized into a cookie, and the
user was redirected to an intermediate /saml-post page to render the
form. This approach failed for large SAML assertions.

# How the Problems Are Solved

The new implementation bypasses cookies entirely for the payload
transfer. Server actions now return the form data directly to the
client, which immediately renders and submits the form.

- Direct Data Transfer: Updated `startIdentityProviderFlow` to return an
object { url, fields } instead of a redirect URL when the next step is
formData.
- Server Actions: Updated redirectToIdp, sendLoginname, and
completeAuthFlow to propagate this samlData object to the client.
- Client-Side Auto-Submission: Added a new AutoSubmitForm component that
renders a hidden form with the provided fields and automatically submits
it to the IdP on mount.

---------

Co-authored-by: conblem <[email protected]>
This commit is contained in:
Max Peintner
2026-02-09 13:46:30 +01:00
committed by GitHub
co-authored by conblem
parent 6f4f54708e
commit 9492c12c09
36 changed files with 891 additions and 1454 deletions
+67 -69
View File
@@ -14,6 +14,8 @@ import { Button, ButtonVariants } from "./button";
import { TextInput } from "./input";
import { Spinner } from "./spinner";
import { Translated } from "./translated";
import { handleServerActionResponse } from "@/lib/client";
import { AutoSubmitForm } from "./auto-submit-form";
type Inputs = {
password: string;
@@ -36,6 +38,7 @@ export function PasswordForm({ loginSettings, loginName, organization, defaultOr
const [info, setInfo] = useState<string>("");
const [error, setError] = useState<string>("");
const [samlData, setSamlData] = useState<{ url: string; fields: Record<string, string> } | null>(null);
const [loading, setLoading] = useState<boolean>(false);
@@ -45,30 +48,22 @@ export function PasswordForm({ loginSettings, loginName, organization, defaultOr
setError("");
setLoading(true);
const response = await sendPassword({
loginName,
organization,
defaultOrganization,
checks: create(ChecksSchema, {
password: { password: values.password },
}),
requestId,
})
.catch(() => {
setError(t("verify.errors.couldNotVerifyPassword"));
return;
})
.finally(() => {
setLoading(false);
try {
const response = await sendPassword({
loginName,
organization,
defaultOrganization,
checks: create(ChecksSchema, {
password: { password: values.password },
}),
requestId,
});
if (response && "error" in response && response.error) {
setError(response.error);
return;
}
if (response && "redirect" in response && response.redirect) {
return router.push(response.redirect);
handleServerActionResponse(response, router, setSamlData, setError);
} catch {
setError(t("verify.errors.couldNotVerifyPassword"));
} finally {
setLoading(false);
}
}
@@ -114,56 +109,59 @@ export function PasswordForm({ loginSettings, loginName, organization, defaultOr
}
return (
<form className="w-full">
<div className={`${error && "transform-gpu animate-shake"}`}>
<TextInput
type="password"
autoComplete="password"
{...register("password", { required: t("verify.required.password") })}
label={t("verify.labels.password")}
data-testid="password-text-input"
/>
{!loginSettings?.hidePasswordReset && (
<button
className="text-sm transition-all hover:text-primary-light-500 dark:hover:text-primary-dark-500"
onClick={() => resetPasswordAndContinue()}
type="button"
disabled={loading}
data-testid="reset-button"
>
<Translated i18nKey="verify.resetPassword" namespace="password" />
</button>
<>
{samlData && <AutoSubmitForm url={samlData.url} fields={samlData.fields} />}
<form className="w-full">
<div className={`${error && "transform-gpu animate-shake"}`}>
<TextInput
type="password"
autoComplete="password"
{...register("password", { required: t("verify.required.password") })}
label={t("verify.labels.password")}
data-testid="password-text-input"
/>
{!loginSettings?.hidePasswordReset && (
<button
className="text-sm transition-all hover:text-primary-light-500 dark:hover:text-primary-dark-500"
onClick={() => resetPasswordAndContinue()}
type="button"
disabled={loading}
data-testid="reset-button"
>
<Translated i18nKey="verify.resetPassword" namespace="password" />
</button>
)}
{loginName && <input type="hidden" name="loginName" autoComplete="username" value={loginName} />}
</div>
{info && (
<div className="py-4">
<Alert type={AlertType.INFO}>{info}</Alert>
</div>
)}
{loginName && <input type="hidden" name="loginName" autoComplete="username" value={loginName} />}
</div>
{error && (
<div className="py-4" data-testid="error">
<Alert>{error}</Alert>
</div>
)}
{info && (
<div className="py-4">
<Alert type={AlertType.INFO}>{info}</Alert>
<div className="mt-8 flex w-full flex-row items-center">
<BackButton data-testid="back-button" />
<span className="flex-grow"></span>
<Button
type="submit"
className="self-end"
variant={ButtonVariants.Primary}
disabled={loading || !formState.isValid}
onClick={handleSubmit(submitPassword)}
data-testid="submit-button"
>
{loading && <Spinner className="mr-2 h-5 w-5" />} <Translated i18nKey="verify.submit" namespace="password" />
</Button>
</div>
)}
{error && (
<div className="py-4" data-testid="error">
<Alert>{error}</Alert>
</div>
)}
<div className="mt-8 flex w-full flex-row items-center">
<BackButton data-testid="back-button" />
<span className="flex-grow"></span>
<Button
type="submit"
className="self-end"
variant={ButtonVariants.Primary}
disabled={loading || !formState.isValid}
onClick={handleSubmit(submitPassword)}
data-testid="submit-button"
>
{loading && <Spinner className="mr-2 h-5 w-5" />} <Translated i18nKey="verify.submit" namespace="password" />
</Button>
</div>
</form>
</form>
</>
);
}