Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: restrict alias emails on signup and invite flows

mertmit986a778b08a5
diff --git a/packages/nocodb/src/models/User.ts b/packages/nocodb/src/models/User.ts
index a71a681a23..e5ed8085a6 100644
--- a/packages/nocodb/src/models/User.ts
+++ b/packages/nocodb/src/models/User.ts
@@ -20,6 +20,7 @@ import {
} from '~/utils/globals';
import { Base, BaseUser, PresignedUrl, UserRefreshToken } from '~/models';
import { sanitiseUserObj } from '~/utils';
+import { normalizeEmail } from '~/utils/emailUtils';
import { parseMetaProp, prepareForDb } from '~/utils/modelUtils';
export default class User implements UserType {
@@ -83,7 +84,7 @@ export default class User implements UserType {
}
if (insertObj.email) {
- insertObj.email = insertObj.email.toLowerCase();
+ insertObj.email = normalizeEmail(insertObj.email);
}
const { id } = await ncMeta.metaInsert2(
@@ -128,7 +129,7 @@ export default class User implements UserType {
]);
if (updateObj.email) {
- updateObj.email = updateObj.email.toLowerCase();
+ updateObj.email = normalizeEmail(updateObj.email);
// check if the target email addr is in use or not
const targetUser = await this.getByEmail(updateObj.email, ncMeta);
@@ -161,7 +162,7 @@ export default class User implements UserType {
}
public static async getByEmail(_email: string, ncMeta = Noco.ncMeta) {
- const email = _email?.toLowerCase();
+ const email = _email ? normalizeEmail(_email) : _email;
let user =
email &&
(await NocoCache.get(
diff --git a/packages/nocodb/src/modules/auth/auth.service.ts b/packages/nocodb/src/modules/auth/auth.service.ts
index bfd80f8a08..f372af8e79 100644
--- a/packages/nocodb/src/modules/auth/auth.service.ts
+++ b/packages/nocodb/src/modules/auth/auth.service.ts
@@ -7,6 +7,7 @@ import { v4 as uuidv4 } from 'uuid';
import Noco from '~/Noco';
import { genJwt } from '~/services/users/helpers';
import { UsersService } from '~/services/users/users.service';
+import { normalizeEmail } from '~/utils/emailUtils';
import { NcError } from '~/helpers/ncError';
export class CreateUserDto {
@@ -55,7 +56,7 @@ export class AuthService {
let { password } = createUserDto;
- const email = _email.toLowerCase();
+ const email = normalizeEmail(_email);
let user = await this.usersService.findOne(email);
diff --git a/packages/nocodb/src/services/base-users/base-users.service.ts b/packages/nocodb/src/services/base-users/base-users.service.ts
index 6d18d9228d..f078f74f4e 100644
--- a/packages/nocodb/src/services/base-users/base-users.service.ts
+++ b/packages/nocodb/src/services/base-users/base-users.service.ts
@@ -26,6 +26,7 @@ import { randomTokenString } from '~/helpers/stringHelpers';
import { Base, BaseUser, PresignedUrl, User } from '~/models';
import { MetaTable } from '~/utils/globals';
import { extractProps } from '~/helpers/extractProps';
+import { normalizeEmail } from '~/utils/emailUtils';
import { getProjectRole, getProjectRolePower } from '~/utils/roleHelper';
import { MailService } from '~/services/mail/mail.service';
import { MailEvent } from '~/interface/Mail';
@@ -93,9 +94,9 @@ export class BaseUsersService {
}
const emails = (param.baseUser.email || '')
- .toLowerCase()
.split(/\s*,\s*/)
- .map((v) => v.trim());
+ .map((v) => normalizeEmail(v.trim()))
+ .filter(Boolean);
// check for invalid emails
const invalidEmails = emails.filter((v) => !validator.isEmail(v));
diff --git a/packages/nocodb/src/services/org-users.service.ts b/packages/nocodb/src/services/org-users.service.ts
index cf084bc03e..b867f44739 100644
--- a/packages/nocodb/src/services/org-users.service.ts
+++ b/packages/nocodb/src/services/org-users.service.ts
@@ -16,6 +16,7 @@ import { validatePayload } from '~/helpers';
import { NcBaseError, NcError } from '~/helpers/catchError';
import { extractProps } from '~/helpers/extractProps';
import { randomTokenString } from '~/helpers/stringHelpers';
+import { normalizeEmail } from '~/utils/emailUtils';
import { BaseUser, PresignedUrl, SyncSource, User } from '~/models';
import Noco from '~/Noco';
@@ -135,9 +136,9 @@ export class OrgUsersService {
// extract emails from request body
const emails = (param.user.email || '')
- .toLowerCase()
.split(/\s*,\s*/)
- .map((v) => v.trim());
+ .map((v) => normalizeEmail(v.trim()))
+ .filter(Boolean);
// check for invalid emails
const invalidEmails = emails.filter((v) => !validator.isEmail(v));
diff --git a/packages/nocodb/src/services/users/users.service.ts b/packages/nocodb/src/services/users/users.service.ts
index a415021ab8..f7a1f8255b 100644
--- a/packages/nocodb/src/services/users/users.service.ts
+++ b/packages/nocodb/src/services/users/users.service.ts
@@ -14,6 +14,7 @@ import type {
} from 'nocodb-sdk';
import type { NcRequest } from '~/interface/config';
import { verifyDefaultWorkspace } from '~/helpers/verifyDefaultWorkspace';
+import { normalizeEmail } from '~/utils/emailUtils';
import { isEE, T } from '~/utils';
import { genJwt, setTokenCookie } from '~/services/users/helpers';
import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
@@ -53,7 +54,7 @@ export class UsersService {
}
async findOne(_email: string) {
- const email = _email.toLowerCase();
+ const email = normalizeEmail(_email);
const user = await this.metaService.metaGet(
RootScopes.ROOT,
RootScopes.ROOT,
@@ -87,7 +88,7 @@ export class UsersService {
MetaTable.USERS,
{
...param,
- email: param.email?.toLowerCase(),
+ email: param.email ? normalizeEmail(param.email) : undefined,
},
);
}
@@ -269,7 +270,7 @@ export class UsersService {
NcError.badRequest('Please enter your email address.');
}
- const email = _email.toLowerCase();
+ const email = normalizeEmail(_email);
const user = await User.getByEmail(email);
if (user) {
@@ -499,7 +500,7 @@ export class UsersService {
NcError.badRequest(`Invalid email`);
}
- const email = _email.toLowerCase();
+ const email = normalizeEmail(_email);
this.validateEmailPattern(email);
diff --git a/packages/nocodb/src/utils/emailUtils.ts b/packages/nocodb/src/utils/emailUtils.ts
index 11fca53b59..4fbf7fb029 100644
--- a/packages/nocodb/src/utils/emailUtils.ts
+++ b/packages/nocodb/src/utils/emailUtils.ts
@@ -1,5 +1,40 @@
import inflection from 'inflection';
+/**
+ * Domains where dots in the local part are ignored by the provider.
+ */
+const GMAIL_DOMAINS = ['gmail.com', 'googlemail.com'];
+
+/**
+ * Normalize an email address to its canonical form to prevent alias abuse.
+ *
+ * - Strips plus addressing (`user+tag@` β†’ `user@`) for all providers
+ * - Removes dots from the local part for Gmail/Googlemail
+ * - Normalizes `googlemail.com` β†’ `gmail.com`
+ * - Lowercases the entire address
+ */
+export function normalizeEmail(email: string): string {
+ const atIndex = email.lastIndexOf('@');
+ if (atIndex === -1) return email.toLowerCase();
+
+ let localPart = email.substring(0, atIndex).toLowerCase();
+ let domain = email.substring(atIndex + 1).toLowerCase();
+
+ // Strip plus addressing (user+tag β†’ user)
+ const plusIndex = localPart.indexOf('+');
+ if (plusIndex !== -1) {
+ localPart = localPart.substring(0, plusIndex);
+ }
+
+ // Gmail/Googlemail: dots in local part are insignificant
+ if (GMAIL_DOMAINS.includes(domain)) {
+ localPart = localPart.replace(/\./g, '');
+ domain = 'gmail.com';
+ }
+
+ return `${localPart}@${domain}`;
+}
+
// html encode string
const encode = (str: string) => {
return str