validate email domain again a list of allowed domains which can contain wildcards for subdomains

Viewed 13

Upfront: This is not the standard case match email against regex I guess...
We got a tool where users can register through their email.
To decide if they are allowed to logon we maintain a list of domains like [ example.com, anotherexample.com].
bill@example.com can register, bill@badexample.com will not be allowed.

We now got asked to enable wildcards for subdomains in the allow list. So that list can look like [ *.example.com, anotherexample.com] meaning bill@abc.example.com and bill@def.example.com can register, bill@example.com cannot register.

The challenge I now have is how to enable this without allowing someone to use toplevel domains like '*.co.uk' in the allow list that would leave the tool wide open.

I was thinking about counting the '.' and make sure there is at least 2 of the asterisks but toplevel domains like uk are a problem.
I see no other solution than maintain a list of the those special top level domains and treat them as an exception. Like if special top level we need at least 3 dots, else we need at least 2 Anybody got another idea?

0 Answers
Related