mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-25 13:58:46 +00:00
Merge commit from fork
* fix: ensure external user's email is verified before auto-linking * fix linking
This commit is contained in:
@@ -101,6 +101,10 @@ describe("processIDPCallback", () => {
|
|||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
email: "[email protected]",
|
email: "[email protected]",
|
||||||
|
verification: {
|
||||||
|
case: "isVerified",
|
||||||
|
value: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
updateHumanUser: {
|
updateHumanUser: {
|
||||||
@@ -112,6 +116,10 @@ describe("processIDPCallback", () => {
|
|||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
email: "[email protected]",
|
email: "[email protected]",
|
||||||
|
verification: {
|
||||||
|
case: "isVerified",
|
||||||
|
value: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -359,8 +359,9 @@ async function handleAutoLinking(ctx: IDPHandlerContext): Promise<IDPHandlerResu
|
|||||||
if (options?.autoLinking) {
|
if (options?.autoLinking) {
|
||||||
let foundUser;
|
let foundUser;
|
||||||
const email = addHumanUser?.email?.email;
|
const email = addHumanUser?.email?.email;
|
||||||
|
const emailVerified = addHumanUser?.email?.verification?.case === "isVerified" && addHumanUser?.email?.verification?.value;
|
||||||
|
|
||||||
if (options.autoLinking === AutoLinkingOption.EMAIL && email) {
|
if (options.autoLinking === AutoLinkingOption.EMAIL && email && emailVerified) {
|
||||||
foundUser = await listUsers({ serviceConfig, email, organizationId: organization }).then((response) => {
|
foundUser = await listUsers({ serviceConfig, email, organizationId: organization }).then((response) => {
|
||||||
return response.result ? response.result[0] : null;
|
return response.result ? response.result[0] : null;
|
||||||
});
|
});
|
||||||
@@ -372,15 +373,6 @@ async function handleAutoLinking(ctx: IDPHandlerContext): Promise<IDPHandlerResu
|
|||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
return response.result ? response.result[0] : null;
|
return response.result ? response.result[0] : null;
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
foundUser = await listUsers({
|
|
||||||
serviceConfig,
|
|
||||||
userName: idpInformation!.userName,
|
|
||||||
email,
|
|
||||||
organizationId: organization,
|
|
||||||
}).then((response) => {
|
|
||||||
return response.result ? response.result[0] : null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundUser) {
|
if (foundUser) {
|
||||||
|
|||||||
@@ -551,7 +551,11 @@ func (l *Login) checkAutoLinking(r *http.Request, authReq *domain.AuthRequest, p
|
|||||||
}
|
}
|
||||||
queries = append(queries, usernameQuery)
|
queries = append(queries, usernameQuery)
|
||||||
case domain.AutoLinkingOptionEmail:
|
case domain.AutoLinkingOptionEmail:
|
||||||
// Email will always be checked against verified email addresses.
|
// When checking for email matches, we need to make sure that both (the one from the IdP and the one in Zitadel)
|
||||||
|
// are verified to prevent potential account takeovers.
|
||||||
|
if !externalUser.IsEmailVerified {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
emailQuery, err := query.NewUserVerifiedEmailSearchQuery(string(externalUser.Email))
|
emailQuery, err := query.NewUserVerifiedEmailSearchQuery(string(externalUser.Email))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user