Skip to content

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

Merge email claim client side errors (#2469)

Leendert de Borsta18a431b0b93
diff --git a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs
index d08db407b..a57d096d4 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs
@@ -49,9 +49,10 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
var sanitizedEmail = to.Trim().ToLower();
- // See if this user has a valid claim to the email address.
+ // Unclaimed and claimed by someone else return the same error on purpose.
var emailClaim = await context.EmailClaims.FirstOrDefaultAsync(x => x.Address == sanitizedEmail && x.Links.Any(l => l.State != EmailClaimLinkState.Removed));
- if (emailClaim is null)
+ var hasPersonalLink = emailClaim is not null && await context.EmailClaimLinks.AnyAsync(l => l.EmailClaimId == emailClaim.Id && l.State != EmailClaimLinkState.Removed && l.VaultManifest.OwnerGroupId == user.PersonalGroupId);
+ if (!hasPersonalLink)
{
return BadRequest(new ApiErrorResponse
{
@@ -63,19 +64,6 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
});
}
- var hasPersonalLink = await context.EmailClaimLinks.AnyAsync(l => l.EmailClaimId == emailClaim.Id && l.State != EmailClaimLinkState.Removed && l.VaultManifest.OwnerGroupId == user.PersonalGroupId);
- if (!hasPersonalLink)
- {
- return BadRequest(new ApiErrorResponse
- {
- Message = "Claim does not match user.",
- Code = "CLAIM_DOES_NOT_MATCH_USER",
- Details = new { ProvidedEmail = to },
- StatusCode = StatusCodes.Status400BadRequest,
- Timestamp = DateTime.UtcNow,
- });
- }
-
var personalKeyIds = await context.VaultManifestDeliveryKeys
.Where(k => context.VaultManifests.Any(m => m.ManifestId == k.VaultManifestId && m.OwnerGroupId == user.PersonalGroupId))
.Select(k => k.Id)
diff --git a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs
index 19517bb83..6aa6a0c1d 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs
@@ -50,9 +50,9 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
var sanitizedEmail = to.Trim().ToLower();
- // See if this user has a valid claim to the email address.
+ // Unclaimed and claimed by someone else return the same error, so this endpoint does not reveal which addresses are taken.
var emailClaim = await context.EmailClaims.FirstOrDefaultAsync(x => x.Address == sanitizedEmail && x.Links.Any(l => l.State != EmailClaimLinkState.Removed));
- if (emailClaim is null)
+ if (emailClaim is null || !await EmailAccessHelper.CanReadClaimAsync(context, emailClaim, user.Id))
{
return BadRequest(new ApiErrorResponse
{
@@ -64,19 +64,6 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
});
}
- // Check if the user has access to the email address.
- if (!await EmailAccessHelper.CanReadClaimAsync(context, emailClaim, user.Id))
- {
- return BadRequest(new ApiErrorResponse
- {
- Message = "Claim does not match user.",
- Code = "CLAIM_DOES_NOT_MATCH_USER",
- Details = new { ProvidedEmail = to },
- StatusCode = StatusCodes.Status400BadRequest,
- Timestamp = DateTime.UtcNow,
- });
- }
-
// 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);
diff --git a/apps/web/src/components/email/RecentEmails.tsx b/apps/web/src/components/email/RecentEmails.tsx
index dc93563bf..c6b55a30a 100644
--- a/apps/web/src/components/email/RecentEmails.tsx
+++ b/apps/web/src/components/email/RecentEmails.tsx
@@ -74,9 +74,7 @@ const RecentEmails: React.FC<RecentEmailsProps> = ({ emailAddress }) => {
setError('');
}
} catch (err) {
- if (apiErrorCodeOf(err) === 'CLAIM_DOES_NOT_MATCH_USER') {
- setError(t('apiErrors.CLAIM_DOES_NOT_MATCH_USER'));
- } else if (apiErrorCodeOf(err) === 'CLAIM_DOES_NOT_EXIST') {
+ if (apiErrorCodeOf(err) === 'CLAIM_DOES_NOT_EXIST') {
/*
* The server learns about a new address when the vault push that follows a save lands. A load that races
* that push is retried once instead of shown as an error.
diff --git a/core/i18n/locales/en.json b/core/i18n/locales/en.json
index 72a3ebdff..c06091fca 100644
--- a/core/i18n/locales/en.json
+++ b/core/i18n/locales/en.json
@@ -4,7 +4,6 @@
"ACCOUNT_LOCKED": "Account temporarily locked due to too many failed attempts. Please try again later.",
"ACCOUNT_SUCCESSFULLY_DELETED": "Account successfully deleted.",
"CLAIM_DOES_NOT_EXIST": "An error occurred while trying to load the emails. Please try to edit and save the credential entry to synchronize the database, then try again.",
- "CLAIM_DOES_NOT_MATCH_USER": "The current chosen email address is already in use. Please change the email address by editing this credential.",
"INTERNAL_SERVER_ERROR": "Internal server error.",
"INVALID_AUTHENTICATOR_CODE": "Invalid authenticator code. Please try again.",
"INVALID_RECOVERY_CODE": "Invalid recovery code. Please try again.",