mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 06:52:24 +00:00
log issues when validating
This commit is contained in:
@@ -47,6 +47,7 @@ const IDP_SCOPE_REGEX = /urn:zitadel:iam:org:idp:id:(.+)/;
|
|||||||
async function isSessionValid(session: Session): Promise<boolean> {
|
async function isSessionValid(session: Session): Promise<boolean> {
|
||||||
// session can't be checked without user
|
// session can't be checked without user
|
||||||
if (!session.factors?.user) {
|
if (!session.factors?.user) {
|
||||||
|
console.warn("Session has no user");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,21 +60,45 @@ async function isSessionValid(session: Session): Promise<boolean> {
|
|||||||
const authMethods = authMethodTypes.authMethodTypes;
|
const authMethods = authMethodTypes.authMethodTypes;
|
||||||
if (authMethods && authMethods.includes(AuthenticationMethodType.TOTP)) {
|
if (authMethods && authMethods.includes(AuthenticationMethodType.TOTP)) {
|
||||||
mfaValid = !!session.factors.totp?.verifiedAt;
|
mfaValid = !!session.factors.totp?.verifiedAt;
|
||||||
|
if (!mfaValid) {
|
||||||
|
console.warn(
|
||||||
|
"Session has no valid totpEmail factor",
|
||||||
|
session.factors.totp?.verifiedAt,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else if (
|
} else if (
|
||||||
authMethods &&
|
authMethods &&
|
||||||
authMethods.includes(AuthenticationMethodType.OTP_EMAIL)
|
authMethods.includes(AuthenticationMethodType.OTP_EMAIL)
|
||||||
) {
|
) {
|
||||||
mfaValid = !!session.factors.otpEmail?.verifiedAt;
|
mfaValid = !!session.factors.otpEmail?.verifiedAt;
|
||||||
|
if (!mfaValid) {
|
||||||
|
console.warn(
|
||||||
|
"Session has no valid otpEmail factor",
|
||||||
|
session.factors.otpEmail?.verifiedAt,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else if (
|
} else if (
|
||||||
authMethods &&
|
authMethods &&
|
||||||
authMethods.includes(AuthenticationMethodType.OTP_SMS)
|
authMethods.includes(AuthenticationMethodType.OTP_SMS)
|
||||||
) {
|
) {
|
||||||
mfaValid = !!session.factors.otpSms?.verifiedAt;
|
mfaValid = !!session.factors.otpSms?.verifiedAt;
|
||||||
|
if (!mfaValid) {
|
||||||
|
console.warn(
|
||||||
|
"Session has no valid otpSms factor",
|
||||||
|
session.factors.otpSms?.verifiedAt,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else if (
|
} else if (
|
||||||
authMethods &&
|
authMethods &&
|
||||||
authMethods.includes(AuthenticationMethodType.U2F)
|
authMethods.includes(AuthenticationMethodType.U2F)
|
||||||
) {
|
) {
|
||||||
mfaValid = !!session.factors.webAuthN?.verifiedAt;
|
mfaValid = !!session.factors.webAuthN?.verifiedAt;
|
||||||
|
if (!mfaValid) {
|
||||||
|
console.warn(
|
||||||
|
"Session has no valid u2f factor",
|
||||||
|
session.factors.webAuthN?.verifiedAt,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// only check settings if no auth methods are available, as this would require a setup
|
// only check settings if no auth methods are available, as this would require a setup
|
||||||
const loginSettings = await getLoginSettings(
|
const loginSettings = await getLoginSettings(
|
||||||
@@ -87,6 +112,12 @@ async function isSessionValid(session: Session): Promise<boolean> {
|
|||||||
|
|
||||||
// must have one single check
|
// must have one single check
|
||||||
mfaValid = !!(otpEmail || otpSms || totp || webAuthN);
|
mfaValid = !!(otpEmail || otpSms || totp || webAuthN);
|
||||||
|
if (!mfaValid) {
|
||||||
|
console.warn(
|
||||||
|
"Session has no valid multifactor",
|
||||||
|
JSON.stringify(session.factors),
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mfaValid = true;
|
mfaValid = true;
|
||||||
}
|
}
|
||||||
@@ -97,12 +128,21 @@ async function isSessionValid(session: Session): Promise<boolean> {
|
|||||||
const validIDP = session?.factors?.intent?.verifiedAt;
|
const validIDP = session?.factors?.intent?.verifiedAt;
|
||||||
|
|
||||||
const stillValid = session.expirationDate
|
const stillValid = session.expirationDate
|
||||||
? timestampDate(session.expirationDate) > new Date()
|
? timestampDate(session.expirationDate).getTime() > new Date().getTime()
|
||||||
: true;
|
: true;
|
||||||
|
|
||||||
const validFactors = !!(validPassword || validPasskey || validIDP);
|
if (!stillValid) {
|
||||||
|
console.warn(
|
||||||
|
"Session is expired",
|
||||||
|
session.expirationDate
|
||||||
|
? timestampDate(session.expirationDate).toDateString()
|
||||||
|
: "no expiration date",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return stillValid && validFactors && mfaValid;
|
const validChecks = !!(validPassword || validPasskey || validIDP);
|
||||||
|
|
||||||
|
return stillValid && validChecks && mfaValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findValidSession(
|
async function findValidSession(
|
||||||
|
|||||||
Reference in New Issue
Block a user