Skip to content

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

Add alias limit reached error (#2469)

Leendert de Borst6cd52c674e1f
diff --git a/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx b/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx
index 7d1de1911..04f3a5704 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx
@@ -261,7 +261,7 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email, manifestId })
setOwnerNotice(null);
setLoading(true);
} catch (err) {
- setError(aliasOwnerErrorText(apiErrorCodeOf(err)) ?? t('common.errors.unknownErrorTryAgain'));
+ setError(aliasOwnerErrorText(apiErrorCodeOf(err)) ?? t('apiErrors.' + apiErrorCodeOf(err), { defaultValue: t('common.errors.unknownErrorTryAgain') }));
}
};
diff --git a/apps/mobile-app/components/items/details/EmailPreview.tsx b/apps/mobile-app/components/items/details/EmailPreview.tsx
index e4b7290e5..dc44a0cd4 100644
--- a/apps/mobile-app/components/items/details/EmailPreview.tsx
+++ b/apps/mobile-app/components/items/details/EmailPreview.tsx
@@ -391,7 +391,7 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email, manifestId })
setOwnerNotice(null);
setLoading(true);
} catch (err) {
- setError(aliasOwnerErrorText(apiErrorCodeOf(err)) ?? t('common.errors.unknownErrorTryAgain'));
+ setError(aliasOwnerErrorText(apiErrorCodeOf(err)) ?? t(`apiErrors.${apiErrorCodeOf(err)}`, { defaultValue: t('common.errors.unknownErrorTryAgain') }));
}
});
};
diff --git a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs
index 61cc95b08..8a0974f65 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/Email/EmailBoxController.cs
@@ -29,8 +29,9 @@ using NpgsqlTypes;
/// <param name="userManager">UserManager instance.</param>
/// <param name="ipBlockListService">IpBlockListService used to shadow-block email retrieval from blocked IPs.</param>
/// <param name="takenAliasLookupRateLimit">Limits how many taken addresses a caller may learn about.</param>
+/// <param name="rateLimitService">RateLimitService used to tell an alias skipped by the alias limit apart from a missing one.</param>
[ApiVersion("2")]
-public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, UserManager<AliasVaultUser> userManager, IpBlockListService ipBlockListService, TakenAliasLookupRateLimitService takenAliasLookupRateLimit) : AuthenticatedRequestController(userManager)
+public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, UserManager<AliasVaultUser> userManager, IpBlockListService ipBlockListService, TakenAliasLookupRateLimitService takenAliasLookupRateLimit, RateLimitService rateLimitService) : AuthenticatedRequestController(userManager)
{
/// <summary>
/// Highest page the bulk mailbox serves; each address scans up to page * pageSize rows.
@@ -83,6 +84,16 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
});
}
+ // A vault push skips new aliases over the alias limit, so an unclaimed address usually means the limit was hit.
+ if (emailClaim is null)
+ {
+ var remaining = await rateLimitService.GetRemainingAliasAllowancesAsync(context, [user.PersonalGroupId]);
+ if (remaining.TryGetValue(user.PersonalGroupId, out var left) && left <= 0)
+ {
+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.ALIAS_LIMIT_REACHED, 400));
+ }
+ }
+
return BadRequest(new ApiErrorResponse
{
Message = "No claim exists for this email address.",
diff --git a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs b/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs
index cfd00ece7..3e3da8dc9 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs
@@ -1357,37 +1357,10 @@ public class VaultController(
/// <param name="caller">The pushing user; their personal group is always a subject via their personal aliases.</param>
/// <param name="sharedGroupIds">The owning group of each shared manifest in this push.</param>
/// <returns>Remaining alias amount per quota group, for the groups that have limits at all.</returns>
- private async Task<Dictionary<Guid, int>> GetRemainingAliasAllowancesAsync(AliasServerDbContext context, AliasVaultUser caller, IEnumerable<Guid> sharedGroupIds)
+ private Task<Dictionary<Guid, int>> GetRemainingAliasAllowancesAsync(AliasServerDbContext context, AliasVaultUser caller, IEnumerable<Guid> sharedGroupIds)
{
// The caller's personal group is always in play; the shared manifests add their owning groups on top.
- var subjectIds = sharedGroupIds.Append(caller.PersonalGroupId).Distinct().ToList();
- var subjects = await context.Groups.Where(g => subjectIds.Contains(g.Id)).ToListAsync();
-
- var remaining = new Dictionary<Guid, int>();
- foreach (var group in subjects)
- {
- var groupId = group.Id;
- foreach (var limit in await rateLimitService.GetLimitsAsync(group, RateLimitType.AliasCreation))
- {
- int currentCount;
- if (limit.WindowSeconds == 0)
- {
- // Global absolute cap: every claim owned by one of this group's manifests, removed ones included.
- currentCount = await context.EmailClaims.CountAsync(c => c.VaultManifest!.OwnerGroupId == groupId);
- }
- else
- {
- // Time-based cap: aliases created within the rolling window (create-then-delete still counts).
- var windowStart = timeProvider.GetUtcNow().UtcDateTime.AddSeconds(-limit.WindowSeconds);
- currentCount = await context.EmailClaims.CountAsync(c => c.CreatedAt >= windowStart && c.VaultManifest!.OwnerGroupId == groupId);
- }
-
- var allowed = limit.MaxCount - currentCount;
- remaining[groupId] = remaining.TryGetValue(groupId, out var existing) ? Math.Min(existing, allowed) : allowed;
- }
- }
-
- return remaining;
+ return rateLimitService.GetRemainingAliasAllowancesAsync(context, sharedGroupIds.Append(caller.PersonalGroupId));
}
/// <summary>
diff --git a/apps/server/AliasVault.Api/Services/RateLimitService.cs b/apps/server/AliasVault.Api/Services/RateLimitService.cs
index a0a3bf438..74c4444d8 100644
--- a/apps/server/AliasVault.Api/Services/RateLimitService.cs
+++ b/apps/server/AliasVault.Api/Services/RateLimitService.cs
@@ -37,6 +37,45 @@ public class RateLimitService(IAliasServerDbContextFactory dbContextFactory, IMe
return RateLimitResolver.Resolve(rules, group, limitType, timeProvider.GetUtcNow().UtcDateTime);
}
+ /// <summary>
+ /// Gets how many new aliases each group may still create; groups without an alias limit are absent (unlimited).
+ /// When multiple limits apply to a group the strictest one wins.
+ /// </summary>
+ /// <param name="context">Database context.</param>
+ /// <param name="groupIds">The quota groups to check.</param>
+ /// <returns>Remaining alias amount per group, for the groups that have limits at all.</returns>
+ public async Task<Dictionary<Guid, int>> GetRemainingAliasAllowancesAsync(AliasServerDbContext context, IEnumerable<Guid> groupIds)
+ {
+ var subjectIds = groupIds.Distinct().ToList();
+ var subjects = await context.Groups.Where(g => subjectIds.Contains(g.Id)).ToListAsync();
+
+ var remaining = new Dictionary<Guid, int>();
+ foreach (var group in subjects)
+ {
+ var groupId = group.Id;
+ foreach (var limit in await GetLimitsAsync(group, RateLimitType.AliasCreation))
+ {
+ int currentCount;
+ if (limit.WindowSeconds == 0)
+ {
+ // Global absolute cap: every claim owned by one of this group's manifests, removed ones included.
+ currentCount = await context.EmailClaims.CountAsync(c => c.VaultManifest!.OwnerGroupId == groupId);
+ }
+ else
+ {
+ // Time-based cap: aliases created within the rolling window (create-then-delete still counts).
+ var windowStart = timeProvider.GetUtcNow().UtcDateTime.AddSeconds(-limit.WindowSeconds);
+ currentCount = await context.EmailClaims.CountAsync(c => c.CreatedAt >= windowStart && c.VaultManifest!.OwnerGroupId == groupId);
+ }
+
+ var allowed = limit.MaxCount - currentCount;
+ remaining[groupId] = remaining.TryGetValue(groupId, out var existing) ? Math.Min(existing, allowed) : allowed;
+ }
+ }
+
+ return remaining;
+ }
+
/// <summary>
/// Returns the enabled rules from cache, refreshing at most once every <see cref="CacheDurationSeconds"/>.
/// </summary>
diff --git a/apps/web/src/components/email/RecentEmails.tsx b/apps/web/src/components/email/RecentEmails.tsx
index ef3956140..fe765e940 100644
--- a/apps/web/src/components/email/RecentEmails.tsx
+++ b/apps/web/src/components/email/RecentEmails.tsx
@@ -201,7 +201,7 @@ const RecentEmails: React.FC<RecentEmailsProps> = ({ emailAddress, manifestId })
await moveAliasHere(webApi, emailAddress, manifestId);
await manualRefresh();
} catch (err) {
- setError(aliasOwnerErrorText(apiErrorCodeOf(err)) ?? t('common.errors.unknownErrorTryAgain'));
+ setError(aliasOwnerErrorText(apiErrorCodeOf(err)) ?? t('apiErrors.' + apiErrorCodeOf(err), { defaultValue: t('common.errors.unknownErrorTryAgain') }));
}
};
diff --git a/core/client/src/email/AliasOwner.ts b/core/client/src/email/AliasOwner.ts
index 910d8ef72..2b6d59fcb 100644
--- a/core/client/src/email/AliasOwner.ts
+++ b/core/client/src/email/AliasOwner.ts
@@ -71,7 +71,6 @@ export function aliasOwnerNotice(
export function aliasOwnerErrorText(code: string | null | undefined): string | null {
switch (code) {
case 'CLAIM_OWNED_BY_OTHER_VAULT': return familySharingText.errors.aliasOwnedByOtherFolder;
- case 'ALIAS_LIMIT_REACHED': return familySharingText.errors.aliasLimitReached;
default: return null;
}
}
diff --git a/core/client/src/sharing/FamilySharingView.ts b/core/client/src/sharing/FamilySharingView.ts
index 7a4a3ff1b..49637b743 100644
--- a/core/client/src/sharing/FamilySharingView.ts
+++ b/core/client/src/sharing/FamilySharingView.ts
@@ -87,7 +87,6 @@ export const familySharingText = {
vaultLimitReached: 'Max amount of shared vaults reached.',
deleteVaultFailed: 'The shared vault could not be deleted. Please try again.',
aliasOwnedByOtherFolder: 'This email alias receives its emails in a shared folder you cannot open, or in the personal vault of another family member. Ask them to move it here.',
- aliasLimitReached: 'The maximum number of email aliases has been reached.',
},
};
diff --git a/core/i18n/locales/en.json b/core/i18n/locales/en.json
index 8d75c05b7..9203a2fba 100644
--- a/core/i18n/locales/en.json
+++ b/core/i18n/locales/en.json
@@ -3,6 +3,7 @@
"ACCOUNT_BLOCKED": "Your account has been disabled. If you believe this is a mistake, please contact support.",
"ACCOUNT_LOCKED": "Account temporarily locked due to too many failed attempts. Please try again later.",
"ACCOUNT_SUCCESSFULLY_DELETED": "Account successfully deleted.",
+ "ALIAS_LIMIT_REACHED": "You have reached the limit for creating new email aliases. Please try again later, or contact support if you need more.",
"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_TAKEN": "This email address is already used by another account. Edit this item and choose a different email address.",
"INTERNAL_SERVER_ERROR": "Internal server error.",