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
+41 -6
View File
@@ -43,7 +43,7 @@ function goToSignedInPage(
export async function completeFlowOrGetUrl(
command: FinishFlowCommand & { organization?: string },
defaultRedirectUri?: string,
): Promise<{ redirect: string } | { error: string }> {
): Promise<{ redirect: string } | { error: string } | { samlData: { url: string; fields: Record<string, string> } }> {
console.log("completeFlowOrGetUrl called with:", command, "defaultRedirectUri:", defaultRedirectUri);
// Complete OIDC/SAML flows directly with server action
@@ -58,16 +58,16 @@ export async function completeFlowOrGetUrl(
sessionId: command.sessionId,
requestId: command.requestId,
});
console.log("completeFlowOrGetUrl: OIDC/SAML flow result:", result);
console.log("completeFlowOrGetUrl: got OIDC/SAML flow result");
return result;
}
console.log("completeFlowOrGetUrl: Regular flow, getting next URL");
// For all other cases, return URL for navigation
const url = await getNextUrl(command, defaultRedirectUri);
console.log("completeFlowOrGetUrl: Next URL:", url);
console.log("completeFlowOrGetUrl: got Next URL:", url);
const result = { redirect: url };
console.log("completeFlowOrGetUrl: Final result:", result);
console.log("completeFlowOrGetUrl: got final result");
return result;
}
@@ -93,7 +93,7 @@ export async function getNextUrl(
...command,
organization: command.organization,
});
console.log("getNextUrl: Device flow result:", result);
console.log("getNextUrl: Got Device flow result");
return result;
}
@@ -106,6 +106,41 @@ export async function getNextUrl(
}
const result = goToSignedInPage(command);
console.log("getNextUrl: Using goToSignedInPage result:", result);
console.log("getNextUrl: got goToSignedInPage result");
return result;
}
export type ServerActionResponse =
| { redirect: string }
| { error: string }
| { samlData: { url: string; fields: Record<string, string> } }
| undefined
| null;
export function handleServerActionResponse(
response: ServerActionResponse,
router: { push: (url: string) => void },
setSamlData: (data: { url: string; fields: Record<string, string> }) => void,
setError: (error: string) => void,
): boolean {
if (!response) {
return false;
}
if ("redirect" in response && response.redirect) {
router.push(response.redirect);
return true;
}
if ("samlData" in response && response.samlData) {
setSamlData(response.samlData);
return true;
}
if ("error" in response && response.error) {
setError(response.error);
return true;
}
return false;
}