Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Reject emails addressed to disabled email claim (#711)
Leendert de Borste782a6a51f29
diff --git a/src/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs b/src/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.csindex c25bb5c7a..e01d373be 100644--- a/src/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs+++ b/src/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs@@ -327,6 +327,16 @@ public class DatabaseMessageStore(ILogger<DatabaseMessageStore> logger, Config creturn false;}+ // Check if the email claim is disabled.+ if (userEmailClaim.Disabled)+ {+ // Email claim is disabled, so we cannot process this email.+ logger.LogWarning(+ "Rejected email: email for {ToAddress} is claimed but is disabled which means the user has deleted the email alias.",+ toAddress.User + "@" + toAddress.Host);+ return false;+ }+// Retrieve user public encryption key from databasevar userPublicKey = await dbContext.UserEncryptionKeys.FirstOrDefaultAsync(x =>diff --git a/src/Tests/AliasVault.IntegrationTests/SmtpServer/SmtpServerTests.cs b/src/Tests/AliasVault.IntegrationTests/SmtpServer/SmtpServerTests.csindex 54f5fc481..7dd81a9bf 100644--- a/src/Tests/AliasVault.IntegrationTests/SmtpServer/SmtpServerTests.cs+++ b/src/Tests/AliasVault.IntegrationTests/SmtpServer/SmtpServerTests.cs@@ -75,6 +75,7 @@ public class SmtpServerTestsAddressDomain = "example.tld",};dbContext.UserEmailClaims.Add(emailClaim);+var emailClaim2 = new UserEmailClaim{UserId = user.Id,@@ -84,6 +85,17 @@ public class SmtpServerTests};dbContext.UserEmailClaims.Add(emailClaim2);+ // Create disabled email claim.+ var emailClaimDisabled = new UserEmailClaim+ {+ UserId = user.Id,+ Address = "[email protected]",+ AddressLocal = "disabled",+ AddressDomain = "example.tld",+ Disabled = true,+ };+ dbContext.UserEmailClaims.Add(emailClaimDisabled);+// Create public key.var encryptionKey = new UserEncryptionKey{@@ -218,7 +230,7 @@ public class SmtpServerTests[Test]public async Task MultipleRecipientsEmail(){- // Send an email to the SMTP server.+ // Send email to the SMTP server.var message = new MimeMessage();message.From.Add(new MailboxAddress("Test Sender", "[email protected]"));message.To.Add(new MailboxAddress("Test Recipient", "[email protected]"));@@ -240,7 +252,7 @@ public class SmtpServerTests[Test]public void SingleEmailUnknownRecipientDomain(){- // Send an email to the SMTP server.+ // Send email to the SMTP server.var message = new MimeMessage();message.From.Add(new MailboxAddress("Test Sender", "[email protected]"));message.To.Add(new MailboxAddress("Test Recipient", "[email protected]"));@@ -252,6 +264,24 @@ public class SmtpServerTestsAssert.ThrowsAsync<SmtpCommandException>(async () => await SendMessageToSmtpServer(message));}+ /// <summary>+ /// Tests sending an email to an existing but disabled email claim, we expect to get an error from the SMTP server.+ /// </summary>+ [Test]+ public void SingleEmailDisabledUserClaim()+ {+ // Send email to the SMTP server.+ var message = new MimeMessage();+ message.From.Add(new MailboxAddress("Test Sender", "[email protected]"));+ message.To.Add(new MailboxAddress("Test Recipient", "[email protected]"));+ message.Subject = "Test Email";+ const string textBody = "This is a test email plain.";+ message.Body = new BodyBuilder { TextBody = textBody }.ToMessageBody();++ // Expect error from SmtpClient when sending email to unknown domain.+ Assert.ThrowsAsync<SmtpCommandException>(async () => await SendMessageToSmtpServer(message));+ }+/// <summary>/// Tests sending a single email to a known recipient domain but with no valid user claim. We expect/// to get an error from the SMTP server.@@ -259,7 +289,7 @@ public class SmtpServerTests[Test]public void SingleEmailNoUserClaim(){- // Send an email to the SMTP server.+ // Send email to the SMTP server.var message = new MimeMessage();message.From.Add(new MailboxAddress("Test Sender", "[email protected]"));message.To.Add(new MailboxAddress("Test Recipient", "[email protected]"));