Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add max shared manifest / folder name input limit (#2469)
Leendert de Borstd81914f24bbf
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Sharing/SharedVaultModal.tsx b/apps/browser-extension/src/entrypoints/popup/components/Sharing/SharedVaultModal.tsxindex 9e1d9f9f3..f1fa6a8d9 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Sharing/SharedVaultModal.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Sharing/SharedVaultModal.tsx@@ -1,5 +1,5 @@import { hasErrorCode, getErrorMessage } from '@aliasvault/client/api/errors/AppErrorCodes';-import { familySharingText } from '@aliasvault/client/sharing/FamilySharingView';+import { familySharingText, MAX_SHARED_VAULT_NAME_LENGTH } from '@aliasvault/client/sharing/FamilySharingView';import React, { useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';@@ -91,6 +91,7 @@ const SharedVaultModal: React.FC<SharedVaultModalProps> = ({ isOpen, onClose, onvalue={name}onChange={(e) => setName(e.target.value)}placeholder={familySharingText.vaultNamePlaceholder}+ maxLength={MAX_SHARED_VAULT_NAME_LENGTH}autoFocusclassName="w-full p-2 border dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring-1 focus:ring-primary-500 focus:border-primary-500"/>diff --git a/apps/mobile-app/components/sharing/SharedVaultModal.tsx b/apps/mobile-app/components/sharing/SharedVaultModal.tsxindex 3f032eff5..811f43aa7 100644--- a/apps/mobile-app/components/sharing/SharedVaultModal.tsx+++ b/apps/mobile-app/components/sharing/SharedVaultModal.tsx@@ -1,4 +1,4 @@-import { familySharingText } from '@aliasvault/client/sharing/FamilySharingView';+import { familySharingText, MAX_SHARED_VAULT_NAME_LENGTH } from '@aliasvault/client/sharing/FamilySharingView';import * as Haptics from 'expo-haptics';import React, { useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';@@ -136,6 +136,7 @@ export const SharedVaultModal: React.FC<ISharedVaultModalProps> = ({ isOpen, onConChangeText={setName}placeholder={familySharingText.vaultNamePlaceholder}placeholderTextColor={colors.textMuted}+ maxLength={MAX_SHARED_VAULT_NAME_LENGTH}autoFocusautoCapitalize="sentences"returnKeyType="done"diff --git a/apps/web/src/components/folders/FolderModal.tsx b/apps/web/src/components/folders/FolderModal.tsxindex befa6954e..5f2518440 100644--- a/apps/web/src/components/folders/FolderModal.tsx+++ b/apps/web/src/components/folders/FolderModal.tsx@@ -10,12 +10,13 @@ type FolderModalProps = {initialName?: string;onClose: () => void;onSave: (name: string) => Promise<void>;+ maxLength?: number;};/*** Modal for creating or renaming a folder.*/-const FolderModal: React.FC<FolderModalProps> = ({ isOpen, mode, initialName = '', onClose, onSave }) => {+const FolderModal: React.FC<FolderModalProps> = ({ isOpen, mode, initialName = '', onClose, onSave, maxLength }) => {const { t } = useTranslation();const [folderName, setFolderName] = useState(initialName);const [errorMessage, setErrorMessage] = useState('');@@ -73,6 +74,7 @@ const FolderModal: React.FC<FolderModalProps> = ({ isOpen, mode, initialName = 'value={folderName}onChange={(e) => setFolderName(e.target.value)}placeholder={t('items.folders.modal.folderNamePlaceholder')}+ maxLength={maxLength}autoFocusclassName="block w-full rounded-md border-0 py-2 px-3 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:text-sm sm:leading-6 dark:bg-gray-700 dark:text-white dark:ring-gray-600 dark:placeholder:text-gray-500 dark:focus:ring-primary-500" />{errorMessage && (diff --git a/apps/web/src/pages/settings/FamilySharing.tsx b/apps/web/src/pages/settings/FamilySharing.tsxindex 95d8a21d6..8e7d1ba2f 100644--- a/apps/web/src/pages/settings/FamilySharing.tsx+++ b/apps/web/src/pages/settings/FamilySharing.tsx@@ -1,7 +1,7 @@import { apiErrorCodeOf } from '@aliasvault/client/api/errors/ApiRequestError';import { AppErrorCode, formatErrorWithCode } from '@aliasvault/client/api/errors/AppErrorCodes';import { MasterPasswordService } from '@aliasvault/client/auth/MasterPasswordService';-import { canAdministerGroup, describeMemberAccess, familySharingText, holdsManifestKey, ownUserIdIn, roleLabel, sharingErrorMessage } from '@aliasvault/client/sharing/FamilySharingView';+import { canAdministerGroup, describeMemberAccess, familySharingText, holdsManifestKey, MAX_SHARED_VAULT_NAME_LENGTH, ownUserIdIn, roleLabel, sharingErrorMessage } from '@aliasvault/client/sharing/FamilySharingView';import { multiManifestRendering } from '@aliasvault/client/sharing/MultiManifestRendering';import { SharingService } from '@aliasvault/client/sharing/SharingService';import React, { useCallback, useEffect, useState } from 'react';@@ -367,6 +367,7 @@ const FamilySharing: React.FC = () => {onClose={() => setPendingVaultRename(null)}onSave={renameSharedVault}initialName={pendingVaultRename ? vaultLabel(pendingVaultRename.manifest) : ''}+ maxLength={MAX_SHARED_VAULT_NAME_LENGTH}mode="edit"/>@@ -564,6 +565,7 @@ const FamilySharing: React.FC = () => {value={newVaultNames[group.groupId] ?? ''}onValueChange={value => setNewVaultNames(previous => ({ ...previous, [group.groupId]: value }))}placeholder={familySharingText.vaultNamePlaceholder}+ maxLength={MAX_SHARED_VAULT_NAME_LENGTH}/></div><Button type="submit" isDisabled={busy}>{familySharingText.create}</Button>diff --git a/core/client/src/sharing/FamilySharingView.ts b/core/client/src/sharing/FamilySharingView.tsindex 514542b43..7a4a3ff1b 100644--- a/core/client/src/sharing/FamilySharingView.ts+++ b/core/client/src/sharing/FamilySharingView.ts@@ -4,6 +4,12 @@ import type { GroupInfo, GroupMemberInfo, SentManifestInvitation, SharedManifest* What the family sharing screen shows and offers, generic and used by multiple clients.*/+/**+ * Maximum length of a shared vault name in UTF-16 code units. Invitations carry the name RSA-OAEP encrypted, which fits at+ * most 190 UTF-8 bytes; one code unit takes at most 3 bytes, so 60 fits in any script.+ */+export const MAX_SHARED_VAULT_NAME_LENGTH = 60;+/*** The family sharing screen's text strings, in English only on purpose (temporary) as the UI is pending changes* so we don't let the translation platform see this yet until its finalized. TODO: move these strings to locale files.diff --git a/core/rust/src/vault_sync/sharing.rs b/core/rust/src/vault_sync/sharing.rsindex e9b6c13f3..39edd02c2 100644--- a/core/rust/src/vault_sync/sharing.rs+++ b/core/rust/src/vault_sync/sharing.rs@@ -18,6 +18,9 @@ const ROLE_MEMBER: &str = "Member";/// The API error code for a recipient whose account has no keypair yet (legacy non-migrated user account).const INVITE_RECIPIENT_NOT_READY: &str = "INVITE_RECIPIENT_NOT_READY";+/// The longest name an invitation can carry: RSA-2048 OAEP-SHA256 fits 190 bytes. The UI caps names well below this.+const MAX_SHARED_MANIFEST_NAME_BYTES: usize = 190;+#[derive(Debug, Clone, Default, Deserialize)]#[serde(rename_all = "camelCase")]struct GroupOverview {@@ -181,6 +184,14 @@ fn own_user_id(ctx: &Ctx, group: &GroupInfo) -> SyncResult<String> {group.members.iter().find(|member| member.username.eq_ignore_ascii_case(&ctx.request.username)).map(|member| member.user_id.clone()).ok_or_else(|| SyncError::Other("This account is not a member of the group".to_string()))}+/// Refuse a name too long for an invitation to carry.+fn check_name_length(name: &str) -> SyncResult<()> {+ if name.len() > MAX_SHARED_MANIFEST_NAME_BYTES {+ return Err(SyncError::Other(format!("A shared manifest name may be at most {} bytes", MAX_SHARED_MANIFEST_NAME_BYTES)));+ }+ Ok(())+}+/// This account's public key, which a new shared manifest's key is encrypted for.async fn own_public_key(ctx: &Ctx) -> SyncResult<Option<String>> {match &ctx.account_public_key {@@ -193,6 +204,7 @@ async fn create_shared_manifest(ctx: &mut Ctx) -> Outcome {let key = ctx.encryption_key()?;let target = params(ctx)?;let name = target.name.as_deref().map(str::trim).filter(|name| !name.is_empty()).ok_or_else(|| SyncError::Other("A shared manifest needs a name".to_string()))?.to_string();+ check_name_length(&name)?;let group = administered_group(ctx, &target.group_id).await?;@@ -266,6 +278,7 @@ async fn update_shared_manifest(ctx: &mut Ctx) -> Outcome {let target = params(ctx)?;let manifest_id = target.manifest_id.clone().ok_or_else(|| SyncError::Other("The update names no shared manifest".to_string()))?;let name = target.name.as_deref().map(str::trim).filter(|name| !name.is_empty()).ok_or_else(|| SyncError::Other("The update changes nothing".to_string()))?.to_string();+ check_name_length(&name)?;let mut records = keys::shared_manifest_records(ctx).await?;let record = records.values().find(|record| ids_equal(&record.manifest_id, &manifest_id)).cloned().ok_or_else(|| SyncError::Other("This account holds no key for the shared manifest".to_string()))?;@@ -322,8 +335,8 @@ async fn invite_to_shared_manifest(ctx: &mut Ctx) -> Outcome {let record = record.ok_or_else(|| SyncError::Other("This account holds no key for the shared manifest".to_string()))?;let manifest_vek = keys::open_shared_manifest_vek(ctx, &record).await?.ok_or_else(|| SyncError::Other("The key of the shared manifest did not open".to_string()))?;- // The name travels encrypted in the invitation, so the recipient sees what they are invited to.- let name = db::manifest_display_names(&ctx.host).await?.get(&id_key(&manifest.manifest_id)).cloned().filter(|name| !name.is_empty());+ // The name travels encrypted in the invitation, so the recipient sees what they are invited to; one too long to fit is left out.+ let name = db::manifest_display_names(&ctx.host).await?.get(&id_key(&manifest.manifest_id)).cloned().filter(|name| !name.is_empty() && name.len() <= MAX_SHARED_MANIFEST_NAME_BYTES);let encrypted_vek = keys::encrypt_manifest_vek(&manifest_vek, &manifest.manifest_id, &recipient_public_key)?;let grant = ManifestGrant {recipient_user_id: member.user_id.clone(),diff --git a/core/rust/src/vault_sync/tests/mod.rs b/core/rust/src/vault_sync/tests/mod.rsindex 61eaffd50..66c18b0cd 100644--- a/core/rust/src/vault_sync/tests/mod.rs+++ b/core/rust/src/vault_sync/tests/mod.rs@@ -2,7 +2,6 @@mod item_move;mod merge_edge_cases;-mod signatures;mod test_host;mod unloaded_blobs;mod unsupported_grant;