Skip to content

Commit

Permalink
fix: only allow suffix matches for domains NOT emails
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeg committed Apr 12, 2024
1 parent 72f39bd commit 28604a0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/services/identity/UsersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class UsersService {
}

async canSendEmailOtp(email: string) {
const parsedEmail = email.toLowerCase()
const normalizedEmail = email.toLowerCase()
const whitelistEntries = await this.whitelist.findAll({
attributes: ["email"],
where: {
Expand All @@ -165,8 +165,15 @@ class UsersService {
})
const whitelistDomains = whitelistEntries.map((entry) => entry.email)
const hasMatchDomain =
whitelistDomains.filter((domain) => parsedEmail.endsWith(domain)).length >
0
whitelistDomains.filter((domain) => {
// if domain is really just a domain (does not include a @ OR starts with a @), we can do a prefix match
if (/^@|^[^@]+$/.test(domain)) {
return normalizedEmail.endsWith(domain)
}

return normalizedEmail === domain
// otherwise we can ONLY do an exact match
}).length > 0
return hasMatchDomain
}

Expand Down

0 comments on commit 28604a0

Please sign in to comment.