diff --git a/services/web/frontend/js/features/settings/components/emails/add-email/input.tsx b/services/web/frontend/js/features/settings/components/emails/add-email/input.tsx index 3eecbf71f6..2a723f2e26 100644 --- a/services/web/frontend/js/features/settings/components/emails/add-email/input.tsx +++ b/services/web/frontend/js/features/settings/components/emails/add-email/input.tsx @@ -84,6 +84,9 @@ function Input({ onChange, handleAddNewEmail }: InputProps) { setMatchedDomain(cachedDomain) return } + if (domainBlocklist.some(d => domain.endsWith(d))) { + return + } const query = `?hostname=${domain}&limit=1` getJSON>(`/institutions/domains${query}`, { signal, @@ -92,7 +95,7 @@ function Input({ onChange, handleAddNewEmail }: InputProps) { if (!(data && data[0])) { return } - if (domainBlocklist.has(data[0].hostname)) { + if (domainBlocklist.some(d => data[0].hostname.endsWith(d))) { return } const hostname = data[0]?.hostname diff --git a/services/web/frontend/js/features/settings/domain-blocklist.ts b/services/web/frontend/js/features/settings/domain-blocklist.ts index fa7b2e0fbe..32b4bcb6de 100644 --- a/services/web/frontend/js/features/settings/domain-blocklist.ts +++ b/services/web/frontend/js/features/settings/domain-blocklist.ts @@ -1,4 +1,4 @@ -const domainBlocklist = new Set(['overleaf.com']) +const domainBlocklist = ['overleaf.com'] const commonTLDs = [ 'br', 'cn', @@ -54,8 +54,8 @@ const commonDomains = [ for (const domain of commonDomains) { for (const tld of commonTLDs) { - domainBlocklist.add(`${domain}.${tld}`) + domainBlocklist.push(`${domain}.${tld}`) } } -export default domainBlocklist +export default domainBlocklist as ReadonlyArray diff --git a/services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx b/services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx index 491a940c6c..2f34c84e6a 100644 --- a/services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx +++ b/services/web/test/frontend/features/settings/components/emails/add-email-input.test.tsx @@ -10,6 +10,7 @@ import fetchMock from 'fetch-mock' import Input, { clearDomainCache, } from '../../../../../../frontend/js/features/settings/components/emails/add-email/input' +import domainBlocklist from '../../../../../../frontend/js/features/settings/domain-blocklist' const testInstitutionData = [ { university: { id: 124 }, hostname: 'domain.edu' }, @@ -215,19 +216,40 @@ describe('', function () { }) describe('when there is a match for a blocklisted domain', function () { - beforeEach(function () { + const [blockedDomain] = domainBlocklist + + afterEach(function () { + clearDomainCache() + fetchMock.reset() + }) + + it('should not render the suggestion with blocked domain', async function () { const blockedInstitution = [ - { university: { id: 1 }, hostname: 'overleaf.com' }, + { university: { id: 1 }, hostname: blockedDomain }, ] fetchMock.get('express:/institutions/domains', blockedInstitution) fireEvent.change(screen.getByRole('textbox'), { - target: { value: 'user@o' }, + target: { value: `user@${blockedDomain.split('.')[0]}` }, }) + await fetchMock.flush(true) + expect(screen.queryByText(`user@${blockedDomain}`)).to.be.null }) - it('should not render the suggestion', async function () { + it('should not render the suggestion with blocked domain having a subdomain', async function () { + const blockedInstitution = [ + { + university: { id: 1 }, + hostname: `subdomain.${blockedDomain}`, + }, + ] + fetchMock.get('express:/institutions/domains', blockedInstitution) + fireEvent.change(screen.getByRole('textbox'), { + target: { + value: `user@subdomain.${blockedDomain.split('.')[0]}`, + }, + }) await fetchMock.flush(true) - expect(screen.queryByText('user@overleaf.com')).to.be.null + expect(screen.queryByText(`user@subdomain.${blockedDomain}`)).to.be.null }) })