From 60d434f53c10e70fcd73f48703144b5a14901868 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 19:46:33 +0530 Subject: [PATCH 1/5] feat: add corporateEmails policy to block non-corporate sign-ups --- app/config/console.php | 1 + app/controllers/api/account.php | 8 ++++++++ app/controllers/api/users.php | 8 ++++++++ src/Appwrite/Extend/Exception.php | 1 + .../Modules/Organization/Http/Projects/Create.php | 1 + .../Platform/Modules/Projects/Http/Projects/Create.php | 1 + .../Platform/Modules/Teams/Http/Memberships/Create.php | 4 ++++ src/Appwrite/Utopia/Response/Filters/V26.php | 1 + 8 files changed, 25 insertions(+) diff --git a/app/config/console.php b/app/config/console.php index 9a5df31866..bf1850182a 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -49,6 +49,7 @@ $console = [ 'disposableEmails' => false, 'canonicalEmails' => false, 'freeEmails' => false, + 'corporateEmails' => false, 'invalidateSessions' => true ], 'authWhitelistEmails' => (!empty(System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? \explode(',', System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [], diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 74501671ad..4a984af8f1 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -350,6 +350,10 @@ Http::post('/v1/account') throw new Exception(Exception::USER_EMAIL_FREE); } + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); + } + try { $userId = $userId == 'unique()' ? ID::unique() : $userId; $user->setAttributes([ @@ -3438,6 +3442,10 @@ Http::patch('/v1/account/email') throw new Exception(Exception::USER_EMAIL_FREE); } + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); + } + $user ->setAttribute('email', $email) ->setAttribute('emailVerification', false) // After this user needs to confirm mail again diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index d2db2fc69e..380f9b4cf6 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -148,6 +148,10 @@ function createUser(Hash $hash, string $userId, ?string $email, ?string $passwor throw new Exception(Exception::USER_EMAIL_FREE); } + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); + } + $hashedPassword = null; $isHashed = !$hash instanceof Plaintext; @@ -1612,6 +1616,10 @@ Http::patch('/v1/users/:userId/email') throw new Exception(Exception::USER_EMAIL_FREE); } + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); + } + $user ->setAttribute('email', $email) ->setAttribute('emailVerification', false) diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 6506127c59..ca114550b7 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -84,6 +84,7 @@ class Exception extends \Exception public const string USER_EMAIL_ALREADY_EXISTS = 'user_email_already_exists'; public const string USER_EMAIL_DISPOSABLE = 'user_email_disposable'; public const string USER_EMAIL_FREE = 'user_email_free'; + public const string USER_EMAIL_NOT_CORPORATE = 'user_email_not_corporate'; public const string USER_EMAIL_NOT_CANONICAL = 'user_email_not_canonical'; public const string USER_PASSWORD_MISMATCH = 'user_password_mismatch'; public const string USER_SESSION_NOT_FOUND = 'user_session_not_found'; diff --git a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php index 785fddf233..90c3781701 100644 --- a/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Organization/Http/Projects/Create.php @@ -94,6 +94,7 @@ class Create extends Action 'disposableEmails' => false, 'canonicalEmails' => false, 'freeEmails' => false, + 'corporateEmails' => false, 'mockNumbers' => [], 'sessionAlerts' => false, 'membershipsUserName' => false, diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index 1560788d09..28405fe1da 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -97,6 +97,7 @@ class Create extends Action 'disposableEmails' => false, 'canonicalEmails' => false, 'freeEmails' => false, + 'corporateEmails' => false, 'mockNumbers' => [], 'sessionAlerts' => false, 'membershipsUserName' => false, diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php index 3bffb091ba..19d9237ff1 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php @@ -204,6 +204,10 @@ class Create extends Action throw new Exception(Exception::USER_EMAIL_FREE); } + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); + } + $hash = $proofForPassword->hash($proofForPassword->generate()); $userId = ID::unique(); diff --git a/src/Appwrite/Utopia/Response/Filters/V26.php b/src/Appwrite/Utopia/Response/Filters/V26.php index 30b4e7dacb..0f53290749 100644 --- a/src/Appwrite/Utopia/Response/Filters/V26.php +++ b/src/Appwrite/Utopia/Response/Filters/V26.php @@ -51,6 +51,7 @@ class V26 extends Filter $content['authDisposableEmails'] = $auths->getAttribute('disposableEmails', false); $content['authCanonicalEmails'] = $auths->getAttribute('canonicalEmails', false); $content['authFreeEmails'] = $auths->getAttribute('freeEmails', false); + $content['authCorporateEmails'] = $auths->getAttribute('corporateEmails', false); $content['authMockNumbers'] = $auths->getAttribute('mockNumbers', []); $content['authSessionAlerts'] = $auths->getAttribute('sessionAlerts', false); $content['authMembershipsUserName'] = $auths->getAttribute('membershipsUserName', false); From ddf5d17f4130d7025b9997f0c7e74305f9dccd1a Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 20:25:54 +0530 Subject: [PATCH 2/5] fix: add missing corporateEmails enforcement to all email update paths in account.php --- app/controllers/api/account.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 4a984af8f1..f944474a22 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1702,6 +1702,10 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') $failureRedirect(Exception::USER_EMAIL_FREE); } + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + $failureRedirect(Exception::USER_EMAIL_NOT_CORPORATE); + } + try { $userId = ID::unique(); $user->setAttributes([ @@ -1843,6 +1847,10 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') $failureRedirect(Exception::USER_EMAIL_FREE); } + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + $failureRedirect(Exception::USER_EMAIL_NOT_CORPORATE); + } + $user->setAttribute('email', $email); $user->setAttribute('emailCanonical', $emailMetadata['emailCanonical']); $user->setAttribute('emailIsCanonical', $emailMetadata['emailIsCanonical']); @@ -2201,6 +2209,10 @@ Http::post('/v1/account/tokens/magic-url') throw new Exception(Exception::USER_EMAIL_FREE); } + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); + } + $user->setAttributes([ '$id' => $userId, '$permissions' => [ @@ -2521,6 +2533,10 @@ Http::post('/v1/account/tokens/email') throw new Exception(Exception::USER_EMAIL_FREE); } + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); + } + $user->setAttributes([ '$id' => $userId, '$permissions' => [ From fbd025d8df316248253d7e30fe0016570a3e9b2a Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 20:26:30 +0530 Subject: [PATCH 3/5] fix: add USER_EMAIL_NOT_CORPORATE entry to errors.php --- app/config/errors.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/config/errors.php b/app/config/errors.php index 4a6f08d432..a548d75179 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -241,6 +241,11 @@ return [ 'description' => 'This email address must already be in its canonical form. Please remove aliases, tags, or provider-specific variations and try again.', 'code' => 400, ], + Exception::USER_EMAIL_NOT_CORPORATE => [ + 'name' => Exception::USER_EMAIL_NOT_CORPORATE, + 'description' => 'Only corporate email addresses are allowed. Please use a work email address and try again.', + 'code' => 400, + ], Exception::USER_PASSWORD_MISMATCH => [ 'name' => Exception::USER_PASSWORD_MISMATCH, 'description' => 'Passwords do not match. Please check the password and confirm password.', From 8f8d531ec2e4970f1e448c75ec3af33731a237de Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Sat, 6 Jun 2026 12:22:52 +0530 Subject: [PATCH 4/5] fix: remove redundant null coalescing on emailIsCorporate check --- app/controllers/api/account.php | 12 ++++++------ app/controllers/api/users.php | 4 ++-- .../Modules/Teams/Http/Memberships/Create.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index f944474a22..6041d03a7b 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -350,7 +350,7 @@ Http::post('/v1/account') throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); } @@ -1702,7 +1702,7 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') $failureRedirect(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { $failureRedirect(Exception::USER_EMAIL_NOT_CORPORATE); } @@ -1847,7 +1847,7 @@ Http::get('/v1/account/sessions/oauth2/:provider/redirect') $failureRedirect(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { $failureRedirect(Exception::USER_EMAIL_NOT_CORPORATE); } @@ -2209,7 +2209,7 @@ Http::post('/v1/account/tokens/magic-url') throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); } @@ -2533,7 +2533,7 @@ Http::post('/v1/account/tokens/email') throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); } @@ -3458,7 +3458,7 @@ Http::patch('/v1/account/email') throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); } diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 380f9b4cf6..773776b7f4 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -148,7 +148,7 @@ function createUser(Hash $hash, string $userId, ?string $email, ?string $passwor throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); } @@ -1616,7 +1616,7 @@ Http::patch('/v1/users/:userId/email') throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); } diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php index 19d9237ff1..ff0ebaada2 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php @@ -204,7 +204,7 @@ class Create extends Action throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); } From 0fa4a23c4a1e632458a64b183327474bd5f9f304 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Mon, 8 Jun 2026 17:13:40 +0530 Subject: [PATCH 5/5] fix: add null-coalesce on emailIsCorporate in users.php and Memberships --- app/controllers/api/users.php | 4 ++-- .../Platform/Modules/Teams/Http/Memberships/Create.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 773776b7f4..380f9b4cf6 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -148,7 +148,7 @@ function createUser(Hash $hash, string $userId, ?string $email, ?string $passwor throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); } @@ -1616,7 +1616,7 @@ Http::patch('/v1/users/:userId/email') throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); } diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php index ff0ebaada2..19d9237ff1 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php @@ -204,7 +204,7 @@ class Create extends Action throw new Exception(Exception::USER_EMAIL_FREE); } - if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !$emailMetadata['emailIsCorporate']) { + if ((($project->getId() === 'console') || ($plan['supportsCorporateEmailValidation'] ?? false)) && ($project->getAttribute('auths', [])['corporateEmails'] ?? false) && !($emailMetadata['emailIsCorporate'] ?? true)) { throw new Exception(Exception::USER_EMAIL_NOT_CORPORATE); }