Skip to content

The open alternative to Salesforce, designed for AI.

fix(server): match blocklist entries case-insensitively (#26403)

Belkouche6c9e4b7231da
diff --git a/packages/twenty-server/src/modules/blocklist/utils/__tests__/is-email-blocklisted.util.spec.ts b/packages/twenty-server/src/modules/blocklist/utils/__tests__/is-email-blocklisted.util.spec.ts
index 9f8c35ee71e..64a3f2a79b9 100644
--- a/packages/twenty-server/src/modules/blocklist/utils/__tests__/is-email-blocklisted.util.spec.ts
+++ b/packages/twenty-server/src/modules/blocklist/utils/__tests__/is-email-blocklisted.util.spec.ts
@@ -17,6 +17,30 @@ describe('isEmailBlocklisted', () => {
expect(result).toBe(false);
});
+ it('should ignore case when matching a blocklisted email', () => {
+ const channelHandles = ['[email protected]'];
+ const email = '[email protected]';
+ const blocklist = ['[email protected]'];
+ const result = isEmailBlocklisted(channelHandles, email, blocklist);
+
+ expect(result).toBe(true);
+ });
+ it('should ignore case when matching a blocklisted domain', () => {
+ const channelHandles = ['[email protected]'];
+ const email = '[email protected]';
+ const blocklist = ['@acme.com'];
+ const result = isEmailBlocklisted(channelHandles, email, blocklist);
+
+ expect(result).toBe(true);
+ });
+ it('should ignore case when the email is a channel handle', () => {
+ const channelHandles = ['[email protected]'];
+ const email = '[email protected]';
+ const blocklist = ['@example.com'];
+ const result = isEmailBlocklisted(channelHandles, email, blocklist);
+
+ expect(result).toBe(false);
+ });
it('should return false if email is null', () => {
const channelHandles = ['[email protected]'];
const email = null;
diff --git a/packages/twenty-server/src/modules/blocklist/utils/is-email-blocklisted.util.ts b/packages/twenty-server/src/modules/blocklist/utils/is-email-blocklisted.util.ts
index c5983e6d5e6..50dd5011904 100644
--- a/packages/twenty-server/src/modules/blocklist/utils/is-email-blocklisted.util.ts
+++ b/packages/twenty-server/src/modules/blocklist/utils/is-email-blocklisted.util.ts
@@ -5,13 +5,23 @@ export const isEmailBlocklisted = (
email: string | null | undefined,
blocklist: string[],
): boolean => {
- if (!email || channelHandle.includes(email)) {
+ if (!email) {
return false;
}
- const domain = getDomainFromEmail(email);
+ const normalizedEmail = email.toLowerCase();
+
+ if (
+ channelHandle.some((handle) => handle.toLowerCase() === normalizedEmail)
+ ) {
+ return false;
+ }
+
+ const domain = getDomainFromEmail(normalizedEmail);
+
+ return blocklist.some((rawItem) => {
+ const item = rawItem.toLowerCase();
- return blocklist.some((item) => {
if (item.startsWith('@')) {
const bareDomain = item.slice(1);
@@ -20,6 +30,6 @@ export const isEmailBlocklisted = (
);
}
- return email === item;
+ return normalizedEmail === item;
});
};