mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix(oauth2): derive emailVerification from provider, not assumption
The OAuth2 callback hardcoded 'emailVerification' => true for every new user, on the assumption that "email should already be authenticated by OAuth2 provider". That assumption does not hold: several adapters report no verification signal at all, and many inferred verification from !empty($email) -- conflating "the provider returned a string" with "the provider vouched for the address". $isVerified was already computed and already trusted for the account-linking checks; it just never reached the attribute. - Set emailVerification from $isVerified when creating an OAuth2 user. - Set it on the branch where an existing account gains an email, which previously left the flag untouched against a brand-new address. OR'd with the current value so an already-verified user is never downgraded. - Yahoo: read the email_verified claim it advertises on its OIDC userinfo endpoint. - Bitly: walk emails[].is_verified instead of returning a bare true. - X: read data.confirmed_email directly rather than via getUserEmail(). - Amazon, Box, Etsy, Facebook, Figma, Kick, Microsoft, Notion, Slack, Stripe, Tradeshift, Twitch, Yammer: return false. None of these expose a usable signal at the endpoint the adapter calls, so unverified is the safe default. Tradeshift was additionally testing the whole user array rather than an email. Slack and Twitch do expose email_verified, but only on OIDC endpoints the adapters do not call. Migrating changes the source field for getUserID(), which is the provider UID join key on identities, so it needs its own change with a migration plan. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d848a1e703
commit
eb63257584
17 files changed
+51
-45
No files matched your search
@@ -1807,8 +1807,8 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
Permission::delete(Role::user($userId)),
|
||||
],
|
||||
'email' => $email,
|
||||
'emailVerification' => true,
|
||||
'status' => true, // Email should already be authenticated by OAuth2 provider
|
||||
'emailVerification' => $isVerified, // Trust the provider's userinfo claim, not the mere fact an email was returned
|
||||
'status' => true,
|
||||
'password' => null,
|
||||
'hash' => $proofForPassword->getHash()->getName(),
|
||||
'hashOptions' => $proofForPassword->getHash()->getOptions(),
|
||||
@@ -1866,6 +1866,8 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
'emailIsFree' => null,
|
||||
];
|
||||
|
||||
$isVerified = $oauth2->isEmailVerified($accessToken);
|
||||
|
||||
try {
|
||||
$parsedEmail = new Email($providerEmail);
|
||||
$canonical = $parsedEmail->getCanonical();
|
||||
@@ -1874,7 +1876,7 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
|| ($plan['supportsCanonicalEmailValidation'] ?? false)
|
||||
)
|
||||
&& ($project->getAttribute('auths', [])['canonicalEmails'] ?? false)
|
||||
&& $oauth2->isEmailVerified($accessToken);
|
||||
&& $isVerified;
|
||||
$email = $canonicalize ? $canonical : $providerEmail;
|
||||
$emails = array_values(array_unique([$email, $providerEmail]));
|
||||
$emailMetadata = [
|
||||
@@ -1913,6 +1915,8 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||
}
|
||||
|
||||
$user->setAttribute('email', $email);
|
||||
// Never downgrade an already-verified user; only ever promote to verified
|
||||
$user->setAttribute('emailVerification', $user->getAttribute('emailVerification', false) || $isVerified);
|
||||
$user->setAttribute('emailCanonical', $emailMetadata['emailCanonical']);
|
||||
$user->setAttribute('emailIsCanonical', $emailMetadata['emailIsCanonical']);
|
||||
$user->setAttribute('emailIsCorporate', $emailMetadata['emailIsCorporate']);
|
||||
|
||||
@@ -149,9 +149,8 @@ class Amazon extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -157,7 +157,15 @@ class Bitly extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
return true;
|
||||
$user = $this->getUser($accessToken);
|
||||
|
||||
foreach ($user['emails'] ?? [] as $email) {
|
||||
if (($email['is_verified'] ?? false) === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -150,9 +150,8 @@ class Box extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -158,9 +158,8 @@ class Etsy extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,9 +131,8 @@ class Facebook extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -139,9 +139,8 @@ class Figma extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -147,7 +147,8 @@ class Kick extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
return !empty($this->getUserEmail($accessToken));
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -147,9 +147,8 @@ class Microsoft extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Microsoft explicitly does not verify emails in Graph /me, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -137,9 +137,8 @@ class Notion extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,9 +131,8 @@ class Slack extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// email_verified lives on openid.connect.userInfo, not users.identity; unverified is the safe default until we migrate
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -146,9 +146,8 @@ class Stripe extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -154,9 +154,8 @@ class Tradeshift extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUser($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -144,9 +144,8 @@ class Twitch extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// email_verified lives on the OIDC userinfo endpoint, not Helix /users; unverified is the safe default until we migrate
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -142,7 +142,10 @@ class X extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
return !empty($this->getUserEmail($accessToken));
|
||||
// X only populates confirmed_email once the address is confirmed, so its presence is the verification signal
|
||||
$user = $this->getUser($accessToken);
|
||||
|
||||
return !empty($user['data']['confirmed_email']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -156,7 +156,9 @@ class Yahoo extends OAuth2
|
||||
/**
|
||||
* Check if the OAuth email is verified
|
||||
*
|
||||
* If present, the email is verified. This was verfied through a manual Yahoo sign up process
|
||||
* Yahoo is an OpenID Connect provider and advertises the `email_verified`
|
||||
* claim on its userinfo endpoint, so use that instead of merely assuming a
|
||||
* returned address is confirmed.
|
||||
*
|
||||
* @param string $accessToken
|
||||
*
|
||||
@@ -164,9 +166,9 @@ class Yahoo extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
$user = $this->getUser($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
return $user['email_verified'] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -133,9 +133,8 @@ class Yammer extends OAuth2
|
||||
*/
|
||||
public function isEmailVerified(string $accessToken): bool
|
||||
{
|
||||
$email = $this->getUserEmail($accessToken);
|
||||
|
||||
return !empty($email);
|
||||
// Provider exposes no email verification signal, so treat as unverified until one is confirmed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user