Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Ensure email claim UpdatedAt is properly triggered and re-enabled if claimed again by same user (#920)

Leendert de Borstc5ea7d01437d
diff --git a/apps/server/AliasVault.Api/Controllers/VaultController.cs b/apps/server/AliasVault.Api/Controllers/VaultController.cs
index db6e36852..b5ed41c5c 100644
--- a/apps/server/AliasVault.Api/Controllers/VaultController.cs
+++ b/apps/server/AliasVault.Api/Controllers/VaultController.cs
@@ -423,7 +423,7 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
private async Task UpdateUserEmailClaims(AliasServerDbContext context, AliasVaultUser user, List<string> newEmailAddresses)
{
// Get all existing user email claims.
- var existingEmailClaims = await context.UserEmailClaims
+ var userOwnedEmailClaims = await context.UserEmailClaims
.Where(x => x.UserId == user.Id)
.ToListAsync();
@@ -458,15 +458,23 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
}
// If email address is already claimed by current user, we don't need to claim it again.
- if (existingEmailClaims.Any(x => x.Address == sanitizedEmail))
+ var existingUserClaim = userOwnedEmailClaims.FirstOrDefault(x => x.Address == sanitizedEmail);
+ if (existingUserClaim != null)
{
+ // Claim already exists but is disabled, so we can re-enable it.
+ if (existingUserClaim.Disabled)
+ {
+ existingUserClaim.Disabled = false;
+ existingUserClaim.UpdatedAt = timeProvider.UtcNow;
+ }
+
+ // If the claim already exists and is not disabled, everything is good, we don't need to do anything.
continue;
}
// Check if the email address is already claimed (by another user).
- var existingClaim = await context.UserEmailClaims.FirstOrDefaultAsync(x => x.Address == sanitizedEmail);
-
- if (existingClaim != null && existingClaim.UserId != user.Id)
+ var existingForeignClaim = await context.UserEmailClaims.FirstOrDefaultAsync(x => x.Address == sanitizedEmail);
+ if (existingForeignClaim != null && existingForeignClaim.UserId != user.Id)
{
// Email address is already claimed by another user. Log the error and continue.
logger.LogWarning("{User} tried to claim email address: {Email} but it is already claimed by another user.", user.UserName, sanitizedEmail);
@@ -497,12 +505,13 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
// Important: we do not delete email claims ever, as they may be re-used by the user in the future.
// We also don't want to allow other users to re-use emails used by other users.
// Email claims are considered permanent.
- foreach (var existingClaim in existingEmailClaims.Where(x => !x.Disabled).ToList())
+ foreach (var existingClaim in userOwnedEmailClaims.Where(x => !x.Disabled).ToList())
{
if (!processedEmailAddresses.Contains(existingClaim.Address))
{
// Email address is no longer in the new list and has not been disabled yet, so disable it.
existingClaim.Disabled = true;
+ existingClaim.UpdatedAt = timeProvider.UtcNow;
}
}
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
index 8c67eb55d..0f9c4243e 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
@@ -398,6 +398,17 @@ public class EmailDecryptionTests : ClientPlaywrightTest
Assert.That(claim1.Disabled, Is.True, "Claim for deleted alias is not marked as disabled after deletion.");
Assert.That(claim2.Disabled, Is.False, "Claim for existing email address is marked disabled after deleting another claim.");
});
+
+ // Create a new credential with the same email as the one that was disabled.
+ await CreateCredentialEntry(new Dictionary<string, string>
+ {
+ { "service-name", serviceName1 },
+ { "email", email1 },
+ });
+
+ // Assert that the first email claim is enabled again.
+ claim1 = await ApiDbContext.UserEmailClaims.AsNoTracking().FirstAsync(x => x.Address == email1);
+ Assert.That(claim1.Disabled, Is.False, "Claim is not marked as (re)enabled when user re-claims it after having previously deleted it.");
}
/// <summary>