Added temp mail check

This commit is contained in:
Marcel Baumgartner
2023-07-12 14:20:55 +02:00
parent 8f9508f30b
commit b75147e4c0
3 changed files with 47 additions and 3 deletions

View File

@@ -0,0 +1,37 @@
using System.Net.Mail;
using Moonlight.App.Helpers;
namespace Moonlight.App.Services.Background;
public class TempMailService
{
private string[] Domains = Array.Empty<string>();
public TempMailService()
{
Task.Run(Init);
}
private async Task Init()
{
var client = new HttpClient();
var text = await client.GetStringAsync("https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/master/disposable_email_blocklist.conf");
Domains = text
.Split("\n")
.Select(x => x.Trim())
.ToArray();
Logger.Info($"Fetched {Domains.Length} temp mail domains");
}
public Task<bool> IsTempMail(string mail)
{
var address = new MailAddress(mail);
if (Domains.Contains(address.Host))
return Task.FromResult(true);
return Task.FromResult(false);
}
}

View File

@@ -5,6 +5,7 @@ using Moonlight.App.Exceptions;
using Moonlight.App.Helpers; using Moonlight.App.Helpers;
using Moonlight.App.Models.Misc; using Moonlight.App.Models.Misc;
using Moonlight.App.Repositories; using Moonlight.App.Repositories;
using Moonlight.App.Services.Background;
using Moonlight.App.Services.Mail; using Moonlight.App.Services.Mail;
using Moonlight.App.Services.Sessions; using Moonlight.App.Services.Sessions;
@@ -19,6 +20,7 @@ public class UserService
private readonly IpLocateService IpLocateService; private readonly IpLocateService IpLocateService;
private readonly DateTimeService DateTimeService; private readonly DateTimeService DateTimeService;
private readonly ConfigService ConfigService; private readonly ConfigService ConfigService;
private readonly TempMailService TempMailService;
private readonly string JwtSecret; private readonly string JwtSecret;
@@ -29,7 +31,8 @@ public class UserService
MailService mailService, MailService mailService,
IdentityService identityService, IdentityService identityService,
IpLocateService ipLocateService, IpLocateService ipLocateService,
DateTimeService dateTimeService) DateTimeService dateTimeService,
TempMailService tempMailService)
{ {
UserRepository = userRepository; UserRepository = userRepository;
TotpService = totpService; TotpService = totpService;
@@ -38,6 +41,7 @@ public class UserService
IdentityService = identityService; IdentityService = identityService;
IpLocateService = ipLocateService; IpLocateService = ipLocateService;
DateTimeService = dateTimeService; DateTimeService = dateTimeService;
TempMailService = tempMailService;
JwtSecret = configService JwtSecret = configService
.Get() .Get()
@@ -49,6 +53,9 @@ public class UserService
if (ConfigService.Get().Moonlight.Auth.DenyRegister) if (ConfigService.Get().Moonlight.Auth.DenyRegister)
throw new DisplayException("This operation was disabled"); throw new DisplayException("This operation was disabled");
if (await TempMailService.IsTempMail(email))
throw new DisplayException("This email is blacklisted");
// Check if the email is already taken // Check if the email is already taken
var emailTaken = UserRepository.Get().FirstOrDefault(x => x.Email == email) != null; var emailTaken = UserRepository.Get().FirstOrDefault(x => x.Email == email) != null;

View File

@@ -103,8 +103,6 @@ namespace Moonlight
} }
} }
Logger.Info($"Working dir: {Directory.GetCurrentDirectory()}");
Logger.Info("Running pre-init tasks"); Logger.Info("Running pre-init tasks");
var databaseCheckupService = new DatabaseCheckupService(configService); var databaseCheckupService = new DatabaseCheckupService(configService);
@@ -246,6 +244,7 @@ namespace Moonlight
builder.Services.AddSingleton<CleanupService>(); builder.Services.AddSingleton<CleanupService>();
builder.Services.AddSingleton<MalwareScanService>(); builder.Services.AddSingleton<MalwareScanService>();
builder.Services.AddSingleton<TelemetryService>(); builder.Services.AddSingleton<TelemetryService>();
builder.Services.AddSingleton<TempMailService>();
// Other // Other
builder.Services.AddSingleton<MoonlightService>(); builder.Services.AddSingleton<MoonlightService>();
@@ -291,6 +290,7 @@ namespace Moonlight
_ = app.Services.GetRequiredService<DiscordNotificationService>(); _ = app.Services.GetRequiredService<DiscordNotificationService>();
_ = app.Services.GetRequiredService<MalwareScanService>(); _ = app.Services.GetRequiredService<MalwareScanService>();
_ = app.Services.GetRequiredService<TelemetryService>(); _ = app.Services.GetRequiredService<TelemetryService>();
_ = app.Services.GetRequiredService<TempMailService>();
_ = app.Services.GetRequiredService<MoonlightService>(); _ = app.Services.GetRequiredService<MoonlightService>();