@@ -880,22 +880,38 @@ defmodule Teiserver.Moderation do
880880 Repo . all ( BannedDomain )
881881 end
882882
883- @ spec list_banned_domains_cache :: [ String . t ( ) ]
883+ @ spec list_banned_domains_cache :: MapSet . t ( String . t ( ) )
884884 def list_banned_domains_cache do
885- Teiserver . cache_get ( :application_metadata_cache , "banned_domains" , [ ] )
885+ Teiserver . cache_get ( :application_metadata_cache , "banned_domains" , MapSet . new ( ) )
886886 end
887887
888888 @ spec banned_domain? ( String . t ( ) ) :: boolean ( )
889889 def banned_domain? ( email ) do
890890 case String . split ( email , "@" ) do
891891 [ _start , domain ] ->
892- String . contains? ( domain , list_banned_domains_cache ( ) )
892+ banned_domains = list_banned_domains_cache ( )
893+
894+ domain
895+ |> String . downcase ( )
896+ |> split_domain_segments ( )
897+ |> Enum . any? ( & MapSet . member? ( banned_domains , & 1 ) )
893898
894899 _no_email ->
895900 false
896901 end
897902 end
898903
904+ defp split_domain_segments ( domain ) do
905+ parts = String . split ( domain , "." )
906+ count = length ( parts )
907+
908+ Enum . map ( 0 .. ( count - 1 ) , fn i ->
909+ parts
910+ |> Enum . drop ( i )
911+ |> Enum . join ( "." )
912+ end )
913+ end
914+
899915 @ doc """
900916 Gets a single banned_domain.
901917
@@ -993,9 +1009,9 @@ defmodule Teiserver.Moderation do
9931009 Repo . all ( BannedIP )
9941010 end
9951011
996- @ spec list_banned_ips_cache :: [ BannedIP . t ( ) ]
1012+ @ spec list_banned_ips_cache :: MapSet . t ( BannedIP . t ( ) )
9971013 def list_banned_ips_cache do
998- Teiserver . cache_get ( :application_metadata_cache , "banned_ip_ranges" , [ ] )
1014+ Teiserver . cache_get ( :application_metadata_cache , "banned_ip_ranges" , MapSet . new ( ) )
9991015 end
10001016
10011017 @ doc """
@@ -1199,9 +1215,9 @@ defmodule Teiserver.Moderation do
11991215 end
12001216
12011217 # VPNs
1202- @ spec list_vpn_cache :: [ String . t ( ) ]
1218+ @ spec list_vpn_cache :: MapSet . t ( String . t ( ) )
12031219 def list_vpn_cache do
1204- Teiserver . cache_get ( :application_metadata_cache , "blocked_vpn_ranges " , [ ] )
1220+ Teiserver . cache_get ( :application_metadata_cache , "banned_vpn_ranges " , MapSet . new ( ) )
12051221 end
12061222
12071223 @ spec vpn_ip? ( String . t ( ) | nil ) :: boolean ( )
0 commit comments