mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-18 11:15:12 +00:00
fix(login): cleanup server logs (#11195)
Closes #11184 # Which Problems Are Solved - loginName: This information is already retrievable from the URL parameters during the authentication flow, so logging it presented no additional exposure. - idpIntent: This was being logged to the server console (server-side logs), so it was never exposed to the client/browser. These changes simply clean up the server logs to prevent unnecessary data noise. # How the Problems Are Solved - Removed idpIntent logging from `apps/login/src/lib/server/idp-intent.ts` - Removed loginName logging from `apps/login/src/lib/server/password.ts` --------- Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
parent
072755f85a
commit
9f1119823b
@@ -7,7 +7,7 @@ import { Skeleton } from "@/components/skeleton";
|
||||
import { ThemeProvider } from "@/components/theme-provider";
|
||||
import * as Tooltip from "@radix-ui/react-tooltip";
|
||||
import { Lato } from "next/font/google";
|
||||
import { ReactNode, Suspense } from "react";
|
||||
import React, { Suspense } from "react";
|
||||
import ThemeSwitch from "@/components/theme-switch";
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
@@ -22,7 +22,7 @@ export async function generateMetadata(): Promise<Metadata> {
|
||||
return { title: t("title") };
|
||||
}
|
||||
|
||||
export default async function RootLayout({ children }: { children: ReactNode }) {
|
||||
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html className={`${lato.className}`} suppressHydrationWarning>
|
||||
<head />
|
||||
|
||||
+14
-11
@@ -13,20 +13,21 @@ type LoginWithOIDCAndSession = {
|
||||
sessions: Session[];
|
||||
sessionCookies: Cookie[];
|
||||
};
|
||||
export async function loginWithOIDCAndSession({ serviceConfig, authRequest, sessionId, sessions, sessionCookies }: LoginWithOIDCAndSession): Promise<{ error: string } | { redirect: string }> {
|
||||
console.log(`Login with session: ${sessionId} and authRequest: ${authRequest}`);
|
||||
|
||||
export async function loginWithOIDCAndSession({
|
||||
serviceConfig,
|
||||
authRequest,
|
||||
sessionId,
|
||||
sessions,
|
||||
sessionCookies,
|
||||
}: LoginWithOIDCAndSession): Promise<{ error: string } | { redirect: string }> {
|
||||
const selectedSession = sessions.find((s) => s.id === sessionId);
|
||||
|
||||
if (selectedSession && selectedSession.id) {
|
||||
console.log(`Found session ${selectedSession.id}`);
|
||||
|
||||
const isValid = await isSessionValid({ serviceConfig, session: selectedSession });
|
||||
|
||||
console.log("Session is valid:", isValid);
|
||||
|
||||
if (!isValid && selectedSession.factors?.user) {
|
||||
console.log("Session is not valid, need to re-authenticate user");
|
||||
// if the session is not valid anymore, we need to redirect the user to re-authenticate /
|
||||
// TODO: handle IDP intent direcly if available
|
||||
const command: SendLoginnameCommand = {
|
||||
@@ -38,7 +39,6 @@ export async function loginWithOIDCAndSession({ serviceConfig, authRequest, sess
|
||||
const res = await sendLoginname(command);
|
||||
|
||||
if (res && "redirect" in res && res?.redirect) {
|
||||
console.log("Redirecting to re-authenticate:", res.redirect);
|
||||
return { redirect: res.redirect };
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,9 @@ export async function loginWithOIDCAndSession({ serviceConfig, authRequest, sess
|
||||
};
|
||||
|
||||
try {
|
||||
const { callbackUrl } = await createCallback({ serviceConfig, req: create(CreateCallbackRequestSchema, {
|
||||
const { callbackUrl } = await createCallback({
|
||||
serviceConfig,
|
||||
req: create(CreateCallbackRequestSchema, {
|
||||
authRequestId: authRequest,
|
||||
callbackKind: {
|
||||
case: "session",
|
||||
@@ -61,7 +63,6 @@ export async function loginWithOIDCAndSession({ serviceConfig, authRequest, sess
|
||||
}),
|
||||
});
|
||||
if (callbackUrl) {
|
||||
console.log("Redirecting to callback URL:", callbackUrl);
|
||||
return { redirect: callbackUrl };
|
||||
} else {
|
||||
return { error: "An error occurred!" };
|
||||
@@ -70,7 +71,10 @@ export async function loginWithOIDCAndSession({ serviceConfig, authRequest, sess
|
||||
// handle already handled gracefully as these could come up if old emails with requestId are used (reset password, register emails etc.)
|
||||
console.error(error);
|
||||
if (error && typeof error === "object" && "code" in error && error?.code === 9) {
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: selectedSession.factors?.user?.organizationId });
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceConfig,
|
||||
organization: selectedSession.factors?.user?.organizationId,
|
||||
});
|
||||
|
||||
if (loginSettings?.defaultRedirectUri) {
|
||||
return { redirect: loginSettings.defaultRedirectUri };
|
||||
@@ -85,7 +89,6 @@ export async function loginWithOIDCAndSession({ serviceConfig, authRequest, sess
|
||||
if (selectedSession.factors?.user?.organizationId) {
|
||||
params.append("organization", selectedSession.factors?.user?.organizationId);
|
||||
}
|
||||
console.log("Redirecting to signed-in page:", signedinUrl + "?" + params.toString());
|
||||
return { redirect: signedinUrl + "?" + params.toString() };
|
||||
} else {
|
||||
return { error: "Unknown error occurred" };
|
||||
|
||||
@@ -24,7 +24,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||
import { cookies } from "next/headers";
|
||||
import { isSessionValid } from "./session";
|
||||
import { sendLoginname } from "@/lib/server/loginname";
|
||||
import {createResponse, getLoginSettings, ServiceConfig} from "@/lib/zitadel";
|
||||
import { createResponse, getLoginSettings, ServiceConfig } from "@/lib/zitadel";
|
||||
|
||||
describe("saml", () => {
|
||||
let mockCookies: any;
|
||||
@@ -133,8 +133,8 @@ describe("saml", () => {
|
||||
|
||||
await setSAMLFormCookie(largeSamlValue);
|
||||
|
||||
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining("SAML form cookie value is large"));
|
||||
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining("5000 characters"));
|
||||
// Expect no warning about size as it was removed for security/performance
|
||||
expect(console.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should handle empty SAML value", async () => {
|
||||
@@ -154,7 +154,8 @@ describe("saml", () => {
|
||||
const uid = await setSAMLFormCookie(longValue);
|
||||
|
||||
expect(uid).toBe(mockUid);
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
// Expect no warning for long values
|
||||
expect(console.warn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throw error when cookie setting fails", async () => {
|
||||
@@ -169,14 +170,6 @@ describe("saml", () => {
|
||||
mockCookies.set.mockRejectedValue(error);
|
||||
|
||||
await expect(setSAMLFormCookie("test-value")).rejects.toThrow();
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Failed to set SAML form cookie"),
|
||||
expect.objectContaining({
|
||||
error,
|
||||
uid: mockUid,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -202,7 +195,6 @@ describe("saml", () => {
|
||||
const result = await getSAMLFormCookie("non-existent-uid");
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining("SAML form cookie not found"));
|
||||
});
|
||||
|
||||
it("should return null if cookie has empty value", async () => {
|
||||
@@ -214,7 +206,6 @@ describe("saml", () => {
|
||||
const result = await getSAMLFormCookie("test-uid");
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining("empty value"));
|
||||
});
|
||||
|
||||
it("should handle errors gracefully", async () => {
|
||||
@@ -226,7 +217,6 @@ describe("saml", () => {
|
||||
const result = await getSAMLFormCookie("test-uid");
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(console.error).toHaveBeenCalledWith(expect.stringContaining("Error retrieving SAML form cookie"), error);
|
||||
});
|
||||
|
||||
it("should handle null cookie value", async () => {
|
||||
@@ -271,7 +261,7 @@ describe("saml", () => {
|
||||
};
|
||||
|
||||
const baseParams = {
|
||||
serviceConfig: {baseUrl: "https://example.com"} as ServiceConfig,
|
||||
serviceConfig: { baseUrl: "https://example.com" } as ServiceConfig,
|
||||
samlRequest: "saml-request-id",
|
||||
sessionId: "session-123",
|
||||
sessions: [mockSession],
|
||||
|
||||
+15
-25
@@ -25,13 +25,7 @@ export async function setSAMLFormCookie(value: string): Promise<string> {
|
||||
const uid = await getSAMLFormUID();
|
||||
|
||||
try {
|
||||
// Check cookie size limits (typical limit is 4KB)
|
||||
if (value.length > 4000) {
|
||||
console.warn(`SAML form cookie value is large (${value.length} characters), may exceed browser limits`);
|
||||
}
|
||||
|
||||
// Log the attempt
|
||||
console.log(`Setting SAML form cookie with uid: ${uid}, value length: ${value.length}`);
|
||||
|
||||
await cookiesList.set({
|
||||
name: uid,
|
||||
@@ -49,11 +43,6 @@ export async function setSAMLFormCookie(value: string): Promise<string> {
|
||||
|
||||
return uid;
|
||||
} catch (error) {
|
||||
console.error(`Failed to set SAML form cookie with uid: ${uid}`, {
|
||||
error,
|
||||
valueLength: value.length,
|
||||
uid,
|
||||
});
|
||||
throw new Error(`Failed to set SAML form cookie: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
@@ -65,35 +54,31 @@ export async function getSAMLFormCookie(uid: string): Promise<string | null> {
|
||||
const cookie = cookiesList.get(uid);
|
||||
|
||||
if (!cookie) {
|
||||
console.warn(`SAML form cookie not found for uid: ${uid}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!cookie.value) {
|
||||
console.warn(`SAML form cookie found but empty value for uid: ${uid}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log(`Successfully retrieved SAML form cookie for uid: ${uid}, value length: ${cookie.value.length}`);
|
||||
return cookie.value;
|
||||
} catch (error) {
|
||||
console.error(`Error retrieving SAML form cookie for uid: ${uid}`, error);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function loginWithSAMLAndSession({ serviceConfig, samlRequest, sessionId, sessions, sessionCookies }: LoginWithSAMLAndSession): Promise<{ error: string } | { redirect: string }> {
|
||||
console.log(`Login with session: ${sessionId} and samlRequest: ${samlRequest}`);
|
||||
|
||||
export async function loginWithSAMLAndSession({
|
||||
serviceConfig,
|
||||
samlRequest,
|
||||
sessionId,
|
||||
sessions,
|
||||
sessionCookies,
|
||||
}: LoginWithSAMLAndSession): Promise<{ error: string } | { redirect: string }> {
|
||||
const selectedSession = sessions.find((s) => s.id === sessionId);
|
||||
|
||||
if (selectedSession && selectedSession.id) {
|
||||
console.log(`Found session ${selectedSession.id}`);
|
||||
|
||||
const isValid = await isSessionValid({ serviceConfig, session: selectedSession });
|
||||
|
||||
console.log("Session is valid:", isValid);
|
||||
|
||||
if (!isValid && selectedSession.factors?.user) {
|
||||
// if the session is not valid anymore, we need to redirect the user to re-authenticate /
|
||||
// TODO: handle IDP intent direcly if available
|
||||
@@ -120,7 +105,9 @@ export async function loginWithSAMLAndSession({ serviceConfig, samlRequest, sess
|
||||
|
||||
// works not with _rsc request
|
||||
try {
|
||||
const { url } = await createResponse({ serviceConfig, req: create(CreateResponseRequestSchema, {
|
||||
const { url } = await createResponse({
|
||||
serviceConfig,
|
||||
req: create(CreateResponseRequestSchema, {
|
||||
samlRequestId: samlRequest,
|
||||
responseKind: {
|
||||
case: "session",
|
||||
@@ -138,7 +125,10 @@ export async function loginWithSAMLAndSession({ serviceConfig, samlRequest, sess
|
||||
console.error(error);
|
||||
|
||||
if (error && typeof error === "object" && "code" in error && error?.code === 9) {
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: selectedSession.factors?.user?.organizationId });
|
||||
const loginSettings = await getLoginSettings({
|
||||
serviceConfig,
|
||||
organization: selectedSession.factors?.user?.organizationId,
|
||||
});
|
||||
|
||||
if (loginSettings?.defaultRedirectUri) {
|
||||
return { redirect: loginSettings.defaultRedirectUri };
|
||||
|
||||
@@ -594,12 +594,6 @@ export async function processIDPCallback({
|
||||
}
|
||||
|
||||
try {
|
||||
console.log("[IDP Process] Retrieving IDP intent (single call):", {
|
||||
id,
|
||||
tokenPreview: token.substring(0, 10) + "...",
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
|
||||
// Consume the single-use token ONCE
|
||||
const intent = await retrieveIDPIntent({ serviceConfig, id, token });
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ export async function sendPassword(command: UpdateSessionCommand): Promise<{ err
|
||||
}
|
||||
|
||||
// Regular flow (no requestId) - return URL for client-side navigation
|
||||
console.log("Password auth: Regular flow with loginName:", session.factors.user.loginName);
|
||||
|
||||
const result = await completeFlowOrGetUrl(
|
||||
{
|
||||
loginName: session.factors.user.loginName,
|
||||
@@ -292,7 +292,6 @@ export async function sendPassword(command: UpdateSessionCommand): Promise<{ err
|
||||
},
|
||||
loginSettings?.defaultRedirectUri,
|
||||
);
|
||||
console.log("Password auth: Regular flow result:", result);
|
||||
|
||||
// Safety net - ensure we always return a valid object
|
||||
if (!result || typeof result !== "object" || (!("redirect" in result) && !("error" in result))) {
|
||||
|
||||
@@ -104,7 +104,8 @@ describe("isSessionValid", () => {
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("Session has no user");
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).not.toHaveBeenCalled();
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
@@ -123,7 +124,8 @@ describe("isSessionValid", () => {
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("Session is expired", expect.any(String));
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("[Session] Session is expired", expect.any(String));
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
@@ -245,12 +247,7 @@ describe("isSessionValid", () => {
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
"Session has no valid MFA factor. Configured methods:",
|
||||
expect.any(Array),
|
||||
"Session factors:",
|
||||
expect.any(Object),
|
||||
);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("[Session] MFA is required but not valid");
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
@@ -450,17 +447,7 @@ describe("isSessionValid", () => {
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
"Session has no valid MFA factor. Configured methods:",
|
||||
[AuthenticationMethodType.TOTP],
|
||||
"Session factors:",
|
||||
expect.objectContaining({
|
||||
totp: undefined,
|
||||
otpEmail: undefined,
|
||||
otpSms: undefined,
|
||||
webAuthN: undefined,
|
||||
}),
|
||||
);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("[Session] MFA is required but not valid");
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
@@ -614,7 +601,7 @@ describe("isSessionValid", () => {
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("Session has no valid multifactor", expect.any(Object));
|
||||
expect(consoleSpy).toHaveBeenCalledWith("[Session] MFA is required but not valid");
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
@@ -780,10 +767,7 @@ describe("isSessionValid", () => {
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
"Session invalid: Email not verified and EMAIL_VERIFICATION is enabled",
|
||||
mockUserId,
|
||||
);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("[Session] Email is not verified");
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
@@ -1178,7 +1162,7 @@ describe("isSessionValid", () => {
|
||||
forceMfaLocalOnly: false,
|
||||
} as any);
|
||||
|
||||
const result = await isSessionValid({ serviceUrl: mockServiceUrl, session });
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
@@ -1210,11 +1194,11 @@ describe("isSessionValid", () => {
|
||||
authMethodTypes: [],
|
||||
} as any);
|
||||
|
||||
const result = await isSessionValid({ serviceUrl: mockServiceUrl, session });
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
// Session expiring exactly now should be considered expired
|
||||
expect(result).toBe(false);
|
||||
expect(consoleSpy).toHaveBeenCalledWith("Session is expired", expect.any(String));
|
||||
expect(consoleSpy).toHaveBeenCalledWith("[Session] Session is expired", expect.any(String));
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
@@ -1299,7 +1283,7 @@ describe("isSessionValid", () => {
|
||||
} as any);
|
||||
|
||||
// Malformed timestamps are handled gracefully, returning false for invalid sessions
|
||||
const result = await isSessionValid({ serviceUrl: mockServiceUrl, session });
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
expect(result).toBe(false);
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
@@ -1347,7 +1331,7 @@ describe("isSessionValid", () => {
|
||||
forceMfaLocalOnly: false,
|
||||
} as any);
|
||||
|
||||
const result = await isSessionValid({ serviceUrl: mockServiceUrl, session });
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
@@ -1386,7 +1370,7 @@ describe("isSessionValid", () => {
|
||||
} as any);
|
||||
|
||||
// Old verification timestamps are still valid as long as session hasn't expired
|
||||
const result = await isSessionValid({ serviceUrl: mockServiceUrl, session });
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
@@ -1420,7 +1404,7 @@ describe("isSessionValid", () => {
|
||||
} as any);
|
||||
|
||||
// Future timestamps should still be considered valid
|
||||
const result = await isSessionValid({ serviceUrl: mockServiceUrl, session });
|
||||
const result = await isSessionValid({ serviceConfig: { baseUrl: mockServiceUrl }, session });
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
@@ -16,23 +16,33 @@ type LoadMostRecentSessionParams = {
|
||||
};
|
||||
};
|
||||
|
||||
export async function loadMostRecentSession({ serviceConfig, sessionParams }: LoadMostRecentSessionParams): Promise<Session | undefined> {
|
||||
export async function loadMostRecentSession({
|
||||
serviceConfig,
|
||||
sessionParams,
|
||||
}: LoadMostRecentSessionParams): Promise<Session | undefined> {
|
||||
const recent = await getMostRecentCookieWithLoginname({
|
||||
loginName: sessionParams.loginName,
|
||||
organization: sessionParams.organization,
|
||||
});
|
||||
|
||||
return getSession({ serviceConfig, sessionId: recent.id, sessionToken: recent.token }).then((resp: GetSessionResponse) => resp.session);
|
||||
return getSession({ serviceConfig, sessionId: recent.id, sessionToken: recent.token }).then(
|
||||
(resp: GetSessionResponse) => resp.session,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* mfa is required, session is not valid anymore (e.g. session expired, user logged out, etc.)
|
||||
* to check for mfa for automatically selected session -> const response = await listAuthenticationMethodTypes(userId);
|
||||
**/
|
||||
export async function isSessionValid({ serviceConfig, session }: { serviceConfig: ServiceConfig; session: Session }): Promise<boolean> {
|
||||
export async function isSessionValid({
|
||||
serviceConfig,
|
||||
session,
|
||||
}: {
|
||||
serviceConfig: ServiceConfig;
|
||||
session: Session;
|
||||
}): Promise<boolean> {
|
||||
// session can't be checked without user
|
||||
if (!session.factors?.user) {
|
||||
console.warn("Session has no user");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -72,15 +82,6 @@ export async function isSessionValid({ serviceConfig, session }: { serviceConfig
|
||||
const u2fValid = mfaMethods.includes(AuthenticationMethodType.U2F) && !!session.factors.webAuthN?.verifiedAt;
|
||||
|
||||
mfaValid = totpValid || otpEmailValid || otpSmsValid || u2fValid;
|
||||
|
||||
if (!mfaValid) {
|
||||
console.warn("Session has no valid MFA factor. Configured methods:", mfaMethods, "Session factors:", {
|
||||
totp: session.factors.totp?.verifiedAt,
|
||||
otpEmail: session.factors.otpEmail?.verifiedAt,
|
||||
otpSms: session.factors.otpSms?.verifiedAt,
|
||||
webAuthN: session.factors.webAuthN?.verifiedAt,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// No specific MFA methods configured, but MFA is forced - check for any verified MFA factors
|
||||
// (excluding IDP which should be handled separately)
|
||||
@@ -91,9 +92,6 @@ export async function isSessionValid({ serviceConfig, session }: { serviceConfig
|
||||
// Note: Removed IDP (session.factors.intent?.verifiedAt) as requested
|
||||
|
||||
mfaValid = !!(otpEmail || otpSms || totp || webAuthN);
|
||||
if (!mfaValid) {
|
||||
console.warn("Session has no valid multifactor", session.factors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +101,7 @@ export async function isSessionValid({ serviceConfig, session }: { serviceConfig
|
||||
|
||||
if (!stillValid) {
|
||||
console.warn(
|
||||
"Session is expired",
|
||||
"[Session] Session is expired",
|
||||
session.expirationDate ? timestampDate(session.expirationDate).toDateString() : "no expiration date",
|
||||
);
|
||||
return false;
|
||||
@@ -116,6 +114,7 @@ export async function isSessionValid({ serviceConfig, session }: { serviceConfig
|
||||
}
|
||||
|
||||
if (!mfaValid) {
|
||||
console.warn("[Session] MFA is required but not valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -126,7 +125,7 @@ export async function isSessionValid({ serviceConfig, session }: { serviceConfig
|
||||
const humanUser = userResponse?.user?.type.case === "human" ? userResponse?.user.type.value : undefined;
|
||||
|
||||
if (humanUser && !humanUser.email?.isVerified) {
|
||||
console.warn("Session invalid: Email not verified and EMAIL_VERIFICATION is enabled", session.factors.user.id);
|
||||
console.warn("[Session] Email is not verified");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,14 +89,6 @@ export async function checkMFAFactors(
|
||||
organization?: string,
|
||||
requestId?: string,
|
||||
) {
|
||||
console.log("checkMFAFactors called with session:", {
|
||||
sessionId: session.id,
|
||||
userId: session.factors?.user?.id,
|
||||
loginName: session.factors?.user?.loginName,
|
||||
hasIntentFactor: !!session.factors?.intent?.verifiedAt,
|
||||
hasPasswordFactor: !!session.factors?.password?.verifiedAt,
|
||||
hasWebAuthNFactor: !!session.factors?.webAuthN?.verifiedAt,
|
||||
});
|
||||
const availableMultiFactors = authMethods?.filter(
|
||||
(m: AuthenticationMethodType) =>
|
||||
m === AuthenticationMethodType.TOTP ||
|
||||
|
||||
@@ -225,7 +225,6 @@ export async function createSessionForUserIdAndIdpIntent({
|
||||
};
|
||||
lifetime: Duration;
|
||||
}>) {
|
||||
console.log("Creating session for userId and IDP intent", { userId, idpIntent, lifetime });
|
||||
const sessionService: Client<typeof SessionService> = await createServiceForHost(SessionService, serviceConfig);
|
||||
|
||||
const userAgent = await getUserAgent();
|
||||
@@ -796,16 +795,7 @@ export async function startIdentityProviderFlow({
|
||||
const redirectUrl = "/saml-post";
|
||||
|
||||
try {
|
||||
// Log the attempt with structure inspection
|
||||
console.log("Attempting to stringify formData.fields:", {
|
||||
fields: formData.fields,
|
||||
fieldsType: typeof formData.fields,
|
||||
fieldsKeys: Object.keys(formData.fields || {}),
|
||||
fieldsEntries: Object.entries(formData.fields || {}),
|
||||
});
|
||||
|
||||
const stringifiedFields = JSON.stringify(formData.fields);
|
||||
console.log("Successfully stringified formData.fields, length:", stringifiedFields.length);
|
||||
|
||||
// Check cookie size limits (typical limit is 4KB)
|
||||
if (stringifiedFields.length > 4000) {
|
||||
@@ -819,7 +809,6 @@ export async function startIdentityProviderFlow({
|
||||
|
||||
return `${redirectUrl}?${params.toString()}`;
|
||||
} catch (stringifyError) {
|
||||
console.error("JSON serialization failed:", stringifyError);
|
||||
throw new Error(
|
||||
`Failed to serialize SAML form data: ${stringifyError instanceof Error ? stringifyError.message : String(stringifyError)}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user