Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Only return email public keys that exist in the returned bulk page itself
Leendert de Borst9bcaeedafc81
diff --git a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.csindex 72f6fa4d1..754b66c7b 100644--- a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs+++ b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs@@ -87,7 +87,6 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U// Retrieve emails from database, restricted to emails carrying a decryption key the caller can open.var decryptableKeyIds = await EmailAccessHelper.ResolveDecryptableKeyIdsAsync(context, user.Id);- var keyTable = await EmailKeyTable.BuildAsync(context, decryptableKeyIds);var emailQuery = context.Emails.AsNoTracking().Where(x => x.To == sanitizedEmail && x.DecryptionKeys.Any(d => decryptableKeyIds.Contains(d.VaultManifestDeliveryKeyId)));// A removed alias still answers with its owner (so the client can offer to move it), but without its mail.@@ -125,6 +124,7 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U.Take(50).ToListAsync();+ var keyTable = await EmailKeyTable.BuildAsync(context, rows.SelectMany(r => r.DecryptionKeys.Select(d => d.VaultManifestDeliveryKeyId)));var emails = rows.ConvertAll(r =>{r.Mail.DecryptionKeys = keyTable.ToApiModels(r.DecryptionKeys.Select(d => (d.VaultManifestDeliveryKeyId, d.EncryptedSymmetricKey)));@@ -155,7 +155,6 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, Upublic async Task<IActionResult> GetEmailBoxBulk([FromBody] MailboxBulkRequest model){await using var context = await dbContextFactory.CreateDbContextAsync();-var user = await GetCurrentUserAsync();if (user is null){@@ -173,7 +172,6 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U// Restrict to emails this user holds a key for.var decryptableKeyIds = await EmailAccessHelper.ResolveDecryptableKeyIdsAsync(context, user.Id);- var keyTable = await EmailKeyTable.BuildAsync(context, decryptableKeyIds);// Fetch the newest emails for each address individually, restricted to emails carrying a decryption key the caller can open.var cutoffClause = shadowCutoff is null ? string.Empty : @" AND e2.""DateSystem"" <= @cutoff";@@ -227,6 +225,7 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U}).ToListAsync();+ var keyTable = await EmailKeyTable.BuildAsync(context, rows.SelectMany(r => r.DecryptionKeys.Select(d => d.VaultManifestDeliveryKeyId)));var mails = rows.ConvertAll(r =>{r.Mail.DecryptionKeys = keyTable.ToApiModels(r.DecryptionKeys.Select(d => (d.VaultManifestDeliveryKeyId, d.EncryptedSymmetricKey)));diff --git a/apps/server/AliasVault.Api/Helpers/EmailKeyTable.cs b/apps/server/AliasVault.Api/Helpers/EmailKeyTable.csindex 0ecfa59a8..c948b8e70 100644--- a/apps/server/AliasVault.Api/Helpers/EmailKeyTable.cs+++ b/apps/server/AliasVault.Api/Helpers/EmailKeyTable.cs@@ -30,15 +30,21 @@ public sealed class EmailKeyTablepublic List<string> PublicKeys { get; }/// <summary>- /// Build the key table for the encryption keys the caller holds the private half of.+ /// Build the key table for only the delivery keys the returned emails reference./// </summary>/// <param name="context">Database context.</param>- /// <param name="decryptableKeyIds">The encryption key ids resolved by <see cref="EmailAccessHelper.ResolveDecryptableKeyIdsAsync"/>.</param>+ /// <param name="referencedKeyIds">The delivery key ids of the returned emails' decryption keys.</param>/// <returns>The key table.</returns>- public static async Task<EmailKeyTable> BuildAsync(AliasServerDbContext context, List<Guid> decryptableKeyIds)+ public static async Task<EmailKeyTable> BuildAsync(AliasServerDbContext context, IEnumerable<Guid> referencedKeyIds){+ var keyIds = referencedKeyIds.Distinct().ToList();+ if (keyIds.Count == 0)+ {+ return Create([]);+ }+var keys = await context.VaultManifestDeliveryKeys- .Where(k => decryptableKeyIds.Contains(k.Id))+ .Where(k => keyIds.Contains(k.Id)).Select(k => new { k.Id, k.PublicKey }).ToListAsync();