Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add missing custom field logic to .avux import flow (#2163)
Leendert de Borst106501193016
diff --git a/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs b/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.csindex 2a7ac2574..3a2e02703 100644--- a/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs@@ -457,6 +457,44 @@ public abstract class ClientPlaywrightTest : PlaywrightTestawait deleteButton.ClickAsync();}+ /// <summary>+ /// Adds a custom (user-defined) field to the current item add/edit form via the "+" menu,+ /// then fills in its value. Exercises the custom field modal (label + type) and the resulting+ /// editor input.+ /// </summary>+ /// <param name="label">The custom field label (e.g. "Membership ID").</param>+ /// <param name="fieldType">The custom field type as stored in the model (e.g. "Text", "Hidden", "TextArea").</param>+ /// <param name="value">The value to fill into the custom field.</param>+ /// <returns>Async task.</returns>+ protected async Task AddCustomFieldAsync(string label, string fieldType, string value)+ {+ // Open the add-field menu and choose "Add Custom Field".+ var addFieldButton = Page.Locator("button.w-full.border-dashed").First;+ await addFieldButton.ClickAsync();+ await Page.ClickAsync("button:has-text('Add Custom Field')");++ // Fill in the custom field modal (label + type).+ await Page.WaitForSelectorAsync("input#custom-field-label-input", new() { State = WaitForSelectorState.Visible });+ await Page.FillAsync("input#custom-field-label-input", label);++ // The type dropdown is uniquely identified by its options (e.g. it contains a "Hidden" option).+ await Page.Locator("select:has(option[value='Hidden'])").SelectOptionAsync(fieldType);++ // Confirm the modal (the confirm button text is exactly "Add").+ await Page.Locator("button:text-is('Add')").ClickAsync();++ // The newly added field is appended to the custom fields list with a dynamic id of the+ // form "custom-{tempId}"; fill the most recently added input/textarea.+ if (fieldType == "TextArea")+ {+ await Page.Locator("textarea[id^='custom-']").Last.FillAsync(value);+ }+ else+ {+ await Page.Locator("input[id^='custom-']").Last.FillAsync(value);+ }+ }+/// <summary>/// Login (again) as current user./// </summary>diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard3/VaultImportTestsBase.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard3/VaultImportTestsBase.csindex c8113525f..c46cd789b 100644--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard3/VaultImportTestsBase.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard3/VaultImportTestsBase.cs@@ -55,11 +55,59 @@ public abstract class VaultImportTestsBase : ClientPlaywrightTestawait VerifySecureNote();await VerifyMultiUrlLogin();await VerifyCredentialInFolder();+ await VerifyCustomFields();// Verify that timestamps were preserved and items appear in creation orderawait VerifyItemsOrderPreserved();}+ /// <summary>+ /// Verifies the "Custom Field Login" item's custom (user-defined) fields are imported correctly.+ /// </summary>+ /// <returns>Async task.</returns>+ protected async Task VerifyCustomFields()+ {+ await NavigateUsingBlazorRouter("items");+ await WaitForUrlAsync("items", "Find all of your items");+ await Page.WaitForTimeoutAsync(1000);++ var itemsPageContent = await Page.TextContentAsync("body");+ if (itemsPageContent == null || !itemsPageContent.Contains("Custom Field Login"))+ {+ TestContext.Progress.WriteLine(+ "VerifyCustomFields: 'Custom Field Login' item not present in the imported vault. " ++ "The TestVault.avux/.avex fixtures predate custom field coverage and must be regenerated " ++ "via the manual GenerateAvuxAvexTestFile test. Skipping custom field assertions.");+ return;+ }++ await Page.ClickAsync("text=Custom Field Login");+ await Page.WaitForURLAsync("**/items/*", new() { Timeout = 5000 });+ await Page.WaitForLoadStateAsync(LoadState.NetworkIdle);++ var pageContent = await Page.TextContentAsync("body");++ // The custom field labels (and thus their definitions and types) should all be present.+ Assert.Multiple(() =>+ {+ Assert.That(pageContent, Does.Contain("Membership ID"), "Text custom field label should be preserved");+ Assert.That(pageContent, Does.Contain("Secret PIN"), "Hidden custom field label should be preserved");+ Assert.That(pageContent, Does.Contain("Recovery Notes"), "Multiline custom field label should be preserved");++ // The multiline (TextArea) value renders as page text and should round-trip verbatim.+ Assert.That(pageContent, Does.Contain("Recovery line one"), "Multiline custom field value should be preserved");+ Assert.That(pageContent, Does.Contain("Recovery line two"), "Multiline custom field value should be preserved");+ });++ // The text custom field value sits in a readonly input whose id matches its label's "for"+ // attribute (the field definition id). Resolve it that way to read the value back.+ var membershipForId = await Page.Locator("label:has-text('Membership ID')").First.GetAttributeAsync("for");+ Assert.That(membershipForId, Is.Not.Null.And.Not.Empty, "Custom field label should reference its input");++ var membershipValue = await Page.Locator($"[id='{membershipForId}']").InputValueAsync();+ Assert.That(membershipValue, Is.EqualTo("MEMBER-12345"), "Text custom field value should be preserved");+ }+/// <summary>/// Verifies the "Basic Login Test" item details./// </summary>diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.csindex 73f19bbd0..16e743eb6 100644--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs@@ -315,7 +315,27 @@ public class TestVaultGeneratorTests : BrowserExtensionPlaywrightTestawait Page.FillAsync("input#service-url-2", "https://admin.example.com");});- // 7. Create a folder and a credential in it+ // 7. Create a login credential with custom (user-defined) fields of different types.+ await CreateItemEntry(+ new Dictionary<string, string>+ {+ { "service-name", "Custom Field Login" },+ { "username", "customfielduser" },+ { "password", "customfieldpass" },+ },+ async () =>+ {+ // Plain text custom field.+ await AddCustomFieldAsync("Membership ID", "Text", "MEMBER-12345");++ // Hidden custom field (value is masked in the UI).+ await AddCustomFieldAsync("Secret PIN", "Hidden", "9876");++ // Multiline custom field.+ await AddCustomFieldAsync("Recovery Notes", "TextArea", "Recovery line one\nRecovery line two");+ });++ // 8. Create a folder and a credential in itawait Page.BringToFrontAsync();await NavigateUsingBlazorRouter("items");await WaitForUrlAsync("items", "Find all of your items");@@ -367,6 +387,7 @@ public class TestVaultGeneratorTests : BrowserExtensionPlaywrightTest"Test Credit Card","Test Secure Note","Multi-URL Login",+ "Custom Field Login",};foreach (var itemName in expectedItems)@@ -475,7 +496,8 @@ public class TestVaultGeneratorTests : BrowserExtensionPlaywrightTestConsole.WriteLine("4. Test Credit Card - credit card entry with all fields");Console.WriteLine("5. Test Secure Note - secure note item");Console.WriteLine("6. Multi-URL Login - credential with multiple URLs");- Console.WriteLine("7. Credential in Folder - credential organized in 'Test Folder'");+ Console.WriteLine("7. Custom Field Login - credential with text, hidden and multiline custom fields");+ Console.WriteLine("8. Credential in Folder - credential organized in 'Test Folder'");Console.WriteLine("\nFiles saved to:");Console.WriteLine($" - Output directory (.avux): {avuxFilePath}");Console.WriteLine($" - Output directory (.avex): {avexFilePath}");diff --git a/apps/server/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj b/apps/server/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csprojindex 8e7728493..f718b66c5 100644--- a/apps/server/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj+++ b/apps/server/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj@@ -72,7 +72,7 @@<EmbeddedResource Include="TestData\Exports\keepass_special_chars.csv" /><EmbeddedResource Include="TestData\Exports\keepassxc.csv" /><EmbeddedResource Include="TestData\Exports\1password_8.csv" />- <EmbeddedResource Include="TestData\Exports\test_export.1pux" />+ <EmbeddedResource Include="TestData\Exports\1password_8.1pux" /><EmbeddedResource Include="TestData\Exports\protonpass.csv" /><EmbeddedResource Include="TestData\Exports\protonpass.zip" /><EmbeddedResource Include="TestData\Exports\lastpass.csv" />diff --git a/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/test_export.1pux b/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/1password_8.1puxsimilarity index 100%rename from apps/server/Tests/AliasVault.UnitTests/TestData/Exports/test_export.1puxrename to apps/server/Tests/AliasVault.UnitTests/TestData/Exports/1password_8.1puxdiff --git a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.csindex 6006d2192..88e4eb459 100644--- a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs+++ b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs@@ -1634,6 +1634,28 @@ public class ImportExportTests});}+ /// <summary>+ /// Helper method to add a custom (user-defined) field value to an item, referencing a field definition.+ /// </summary>+ /// <param name="item">The item to add the field value to.</param>+ /// <param name="definition">The custom field definition the value belongs to.</param>+ /// <param name="value">The field value.</param>+ private static void AddCustomFieldValue(Item item, FieldDefinition definition, string value)+ {+ item.FieldValues.Add(new FieldValue+ {+ Id = Guid.NewGuid(),+ ItemId = item.Id,+ FieldDefinition = definition,+ FieldDefinitionId = definition.Id,+ FieldKey = null,+ Value = value,+ Weight = 0,+ CreatedAt = item.CreatedAt,+ UpdatedAt = item.UpdatedAt,+ });+ }+/// <summary>/// Test case for exporting vault data to .avux format and verifying structure./// </summary>@@ -1853,6 +1875,103 @@ public class ImportExportTests});}+ /// <summary>+ /// Test case verifying that custom (user-defined) fields are exported and imported correctly+ /// during a .avux export and import.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ public async Task AvuxRoundTripPreservesCustomFields()+ {+ // Arrange - an item with two custom fields: a plain text one and a hidden secret one.+ var item = CreateTestItem("Custom Field Item", ItemType.Login, new Dictionary<string, string>+ {+ { FieldKey.LoginUsername, "customuser" },+ });++ var textFieldDef = new FieldDefinition+ {+ Id = Guid.NewGuid(),+ Label = "Security Question",+ FieldType = "Text",+ IsHidden = false,+ Weight = 3,+ CreatedAt = DateTime.UtcNow,+ UpdatedAt = DateTime.UtcNow,+ };+ var hiddenFieldDef = new FieldDefinition+ {+ Id = Guid.NewGuid(),+ Label = "Recovery Code",+ FieldType = "Password",+ IsHidden = true,+ Weight = 5,+ CreatedAt = DateTime.UtcNow,+ UpdatedAt = DateTime.UtcNow,+ };++ AddCustomFieldValue(item, textFieldDef, "My first pet");+ AddCustomFieldValue(item, hiddenFieldDef, "super-secret-recovery");++ var fieldDefinitions = new List<FieldDefinition> { textFieldDef, hiddenFieldDef };++ // Export+ var avuxBytes = await VaultExportService.ExportToAvuxAsync(+ new List<Item> { item },+ new List<Folder>(),+ new List<Tag>(),+ new List<ItemTag>(),+ fieldDefinitions,+ new List<Logo>(),+ "[email protected]");++ // Import+ var importedCredentials = await VaultImportService.ImportFromAvuxAsync(avuxBytes);++ // Assert - custom field values survive the import with their full metadata.+ Assert.That(importedCredentials, Has.Count.EqualTo(1));+ var imported = importedCredentials[0];+ Assert.That(imported.CustomFieldValues, Is.Not.Null);+ Assert.That(imported.CustomFieldValues, Has.Count.EqualTo(2));++ var textField = imported.CustomFieldValues!.First(f => f.Label == "Security Question");+ Assert.Multiple(() =>+ {+ Assert.That(textField.Value, Is.EqualTo("My first pet"));+ Assert.That(textField.FieldType, Is.EqualTo("Text"));+ Assert.That(textField.IsHidden, Is.False);+ Assert.That(textField.Weight, Is.EqualTo(3));+ });++ var hiddenField = imported.CustomFieldValues!.First(f => f.Label == "Recovery Code");+ Assert.Multiple(() =>+ {+ Assert.That(hiddenField.Value, Is.EqualTo("super-secret-recovery"));+ Assert.That(hiddenField.FieldType, Is.EqualTo("Password"));+ Assert.That(hiddenField.IsHidden, Is.True);+ Assert.That(hiddenField.Weight, Is.EqualTo(5));+ });++ // Assert - converting the imported credentials to vault items recreates the custom+ // FieldDefinitions and their FieldValues (this is the path that previously dropped them).+ var convertedItems = BaseImporter.ConvertToItem(importedCredentials);+ var convertedItem = convertedItems.Single();++ var customFieldValues = convertedItem.FieldValues+ .Where(fv => fv.FieldKey == null && fv.FieldDefinition != null)+ .ToList();+ Assert.That(customFieldValues, Has.Count.EqualTo(2));++ var recoveryValue = customFieldValues.First(fv => fv.FieldDefinition!.Label == "Recovery Code");+ Assert.Multiple(() =>+ {+ Assert.That(recoveryValue.Value, Is.EqualTo("super-secret-recovery"));+ Assert.That(recoveryValue.FieldDefinition!.FieldType, Is.EqualTo("Password"));+ Assert.That(recoveryValue.FieldDefinition.IsHidden, Is.True);+ Assert.That(recoveryValue.FieldDefinition.Weight, Is.EqualTo(5));+ });+ }+/// <summary>/// Test case for exporting and importing vault with logos in .avux format./// </summary>@@ -2101,11 +2220,20 @@ public class ImportExportTests// Verify custom fields (all types: Text=0, Hidden=1, Boolean=2)// Linked fields (type 3) are skipped during import- Assert.That(loginItem.CustomFields, Is.Not.Null);- Assert.That(loginItem.CustomFields, Has.Count.EqualTo(3));- Assert.That(loginItem.CustomFields!["Security Question"], Is.EqualTo("My first pet")); // Type 0: Text- Assert.That(loginItem.CustomFields["API Key"], Is.EqualTo("sk_test_123456789")); // Type 1: Hidden- Assert.That(loginItem.CustomFields["Two Factor Enabled"], Is.EqualTo("true")); // Type 2: Boolean+ Assert.That(loginItem.CustomFieldValues, Is.Not.Null);+ Assert.That(loginItem.CustomFieldValues, Has.Count.EqualTo(3));++ var securityQuestion = loginItem.CustomFieldValues!.First(f => f.Label == "Security Question");+ Assert.That(securityQuestion.Value, Is.EqualTo("My first pet")); // Type 0: Text+ Assert.That(securityQuestion.FieldType, Is.EqualTo("Text"));++ var apiKey = loginItem.CustomFieldValues!.First(f => f.Label == "API Key");+ Assert.That(apiKey.Value, Is.EqualTo("sk_test_123456789")); // Type 1: Hidden+ Assert.That(apiKey.FieldType, Is.EqualTo("Hidden"));++ var twoFactorEnabled = loginItem.CustomFieldValues!.First(f => f.Label == "Two Factor Enabled");+ Assert.That(twoFactorEnabled.Value, Is.EqualTo("true")); // Type 2: Boolean+ Assert.That(twoFactorEnabled.FieldType, Is.EqualTo("Text"));// Notes should remain unchanged (linked fields are skipped, not added to notes)Assert.That(loginItem.Notes, Is.EqualTo("This is a test login item"));@@ -2406,7 +2534,7 @@ public class ImportExportTestspublic async Task ImportCredentialsFromOnePassword1pux(){// Arrange- var zipBytes = await ResourceReaderUtility.ReadEmbeddedResourceBytesAsync("AliasVault.UnitTests.TestData.Exports.test_export.1pux");+ var zipBytes = await ResourceReaderUtility.ReadEmbeddedResourceBytesAsync("AliasVault.UnitTests.TestData.Exports.1password_8.1pux");// Actvar importer = new OnePassword1puxImporter();@@ -2431,8 +2559,9 @@ public class ImportExportTestsAssert.That(loginItem.Tags, Has.Count.EqualTo(2));Assert.That(loginItem.Tags, Does.Contain("work"));Assert.That(loginItem.Tags, Does.Contain("important"));- Assert.That(loginItem.CustomFields, Is.Not.Null);- Assert.That(loginItem.CustomFields!["Recovery Email"], Is.EqualTo("[email protected]"));+ Assert.That(loginItem.CustomFieldValues, Is.Not.Null);+ var recoveryEmail = loginItem.CustomFieldValues!.First(f => f.Label == "Recovery Email");+ Assert.That(recoveryEmail.Value, Is.EqualTo("[email protected]"));});// Verify created/updated timestamps are converted from Unix timediff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.csindex e2a6ff9db..14bb7d117 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs@@ -161,6 +161,33 @@ public static class BaseImporterreturn urls.Count > 0 ? urls : null;}+ /// <summary>+ /// Adds a custom (user-defined) field value to the credential.+ /// </summary>+ /// <param name="credential">The credential to add the custom field to.</param>+ /// <param name="label">The field label (display name).</param>+ /// <param name="value">The field value.</param>+ /// <param name="fieldType">The field type.</param>+ public static void AddCustomField(ImportedCredential credential, string? label, string? value, string fieldType = FieldType.Text)+ {+ if (string.IsNullOrWhiteSpace(label) || string.IsNullOrWhiteSpace(value))+ {+ return;+ }++ var resolvedType = string.IsNullOrWhiteSpace(fieldType) ? FieldType.Text : fieldType;++ credential.CustomFieldValues ??= new List<ImportedCustomField>();+ credential.CustomFieldValues.Add(new ImportedCustomField+ {+ DefinitionId = Guid.NewGuid(),+ Label = label,+ Value = value,+ FieldType = resolvedType,+ IsHidden = resolvedType is FieldType.Hidden or FieldType.Password,+ });+ }+/// <summary>/// Converts a list of imported credentials to a list of AliasVault Items./// </summary>@@ -293,32 +320,35 @@ public static class BaseImporter}}- // Add custom fields if present- if (importedCredential.CustomFields != null)+ // Add custom (user-defined) field values if present.+ if (importedCredential.CustomFieldValues != null){- foreach (var customField in importedCredential.CustomFields)+ var definitionsBySourceId = new Dictionary<Guid, FieldDefinition>();+ foreach (var customField in importedCredential.CustomFieldValues){if (string.IsNullOrWhiteSpace(customField.Value)){continue;}- // Create a FieldDefinition for this custom field- var fieldDefinition = new FieldDefinition+ if (!definitionsBySourceId.TryGetValue(customField.DefinitionId, out var fieldDefinition)){- Id = Guid.NewGuid(),- Label = customField.Key,- FieldType = "Text", // Default to Text type for all custom fields- IsMultiValue = false,- IsHidden = false,- EnableHistory = false,- Weight = 0,- ApplicableToTypes = null, // Applicable to all types- CreatedAt = createdAt,- UpdatedAt = updatedAt,- };+ fieldDefinition = new FieldDefinition+ {+ Id = Guid.NewGuid(),+ Label = customField.Label,+ FieldType = string.IsNullOrWhiteSpace(customField.FieldType) ? FieldType.Text : customField.FieldType,+ IsMultiValue = customField.IsMultiValue,+ IsHidden = customField.IsHidden,+ EnableHistory = customField.EnableHistory,+ Weight = customField.Weight,+ ApplicableToTypes = customField.ApplicableToTypes,+ CreatedAt = createdAt,+ UpdatedAt = updatedAt,+ };+ definitionsBySourceId[customField.DefinitionId] = fieldDefinition;+ }- // Create a FieldValue that references this definitionitem.FieldValues.Add(new FieldValue{Id = Guid.NewGuid(),@@ -327,7 +357,7 @@ public static class BaseImporterFieldDefinitionId = fieldDefinition.Id,FieldKey = null, // Custom fields don't use FieldKeyValue = customField.Value,- Weight = 0,+ Weight = customField.ValueWeight,CreatedAt = createdAt,UpdatedAt = updatedAt,});diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenZipImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenZipImporter.csindex 901049b17..274b6255b 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenZipImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/BitwardenZipImporter.cs@@ -9,6 +9,7 @@ namespace AliasVault.ImportExport.Importers;using System.IO.Compression;using System.Text.Json;+using AliasClientDb.Models;using AliasVault.ImportExport.Exceptions;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;@@ -248,11 +249,15 @@ public class BitwardenZipImporter : BaseArchiveImportercontinue;}- // For all other types (Text, Hidden, Boolean), add to custom fields if value exists+ // For all other types (Text, Hidden, Boolean), add to custom fields if value exists.+ // Bitwarden field type 1 is "Hidden"; everything else maps to a plain text field.if (!string.IsNullOrWhiteSpace(field.Value)){- credential.CustomFields ??= new Dictionary<string, string>();- credential.CustomFields[field.Name] = field.Value;+ BaseImporter.AddCustomField(+ credential,+ field.Name,+ field.Value,+ field.Type == 1 ? FieldType.Hidden : FieldType.Text);}}}diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePassword1puxImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePassword1puxImporter.csindex a6b86a51e..e2483a5c6 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePassword1puxImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/OnePassword1puxImporter.cs@@ -9,6 +9,7 @@ namespace AliasVault.ImportExport.Importers;using System.IO.Compression;using System.Text.Json;+using AliasClientDb.Models;using AliasVault.ImportExport.Exceptions;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;@@ -325,12 +326,18 @@ public class OnePassword1puxImporter : BaseArchiveImporterExtractCreditCardField(credential, field);}- // Add other fields as custom fields+ // Add other fields as custom fields. A concealed value (no plain string content)+ // indicates a hidden field; everything else defaults to a plain text field.var fieldValue = GetFieldValueAsString(field.Value);if (!string.IsNullOrWhiteSpace(fieldValue)){- credential.CustomFields ??= new Dictionary<string, string>();- credential.CustomFields[field.Title] = fieldValue;+ var isConcealed = string.IsNullOrWhiteSpace(field.Value.String)+ && !string.IsNullOrWhiteSpace(field.Value.Concealed);+ BaseImporter.AddCustomField(+ credential,+ field.Title,+ fieldValue,+ isConcealed ? FieldType.Hidden : FieldType.Text);}}}diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassZipImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassZipImporter.csindex 985157fa5..7ee643a26 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassZipImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassZipImporter.cs@@ -9,6 +9,7 @@ namespace AliasVault.ImportExport.Importers;using System.IO.Compression;using System.Text.Json;+using AliasClientDb.Models;using AliasVault.ImportExport.Exceptions;using AliasVault.ImportExport.Models;using AliasVault.ImportExport.Models.Imports;@@ -412,23 +413,15 @@ public class ProtonPassZipImporter : BaseArchiveImportercontinue;}- AddCustomField(credential, field.FieldName, value);+ // Proton Pass marks concealed fields with type "hidden"; everything else is plain text.+ BaseImporter.AddCustomField(+ credential,+ field.FieldName,+ value,+ type == "hidden" ? FieldType.Hidden : FieldType.Text);}}- /// <summary>- /// Adds a key/value pair to the credential's CustomFields dictionary,- /// initialising it if necessary.- /// </summary>- /// <param name="credential">The credential to modify.</param>- /// <param name="name">The custom field name.</param>- /// <param name="value">The custom field value.</param>- private static void AddCustomField(ImportedCredential credential, string name, string value)- {- credential.CustomFields ??= new Dictionary<string, string>();- credential.CustomFields[name] = value;- }-/// <summary>/// Extracts attachments referenced by an item's files array. Proton Pass stores/// file blobs under "Proton Pass/files/<fileId>" within the archive.diff --git a/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCredential.cs b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCredential.csindex 6f3ec6fe9..afb01351c 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCredential.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCredential.cs@@ -104,8 +104,7 @@ public class ImportedCredentialpublic List<ImportedAttachment>? Attachments { get; set; }/// <summary>- /// Gets or sets custom field definitions for this credential.- /// Key is the field label, value is the field value.+ /// Gets or sets the custom (user-defined) field values for this credential./// </summary>- public Dictionary<string, string>? CustomFields { get; set; }+ public List<ImportedCustomField>? CustomFieldValues { get; set; }}diff --git a/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCustomField.cs b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCustomField.csnew file mode 100644index 000000000..a1a5056f1--- /dev/null+++ b/apps/server/Utilities/AliasVault.ImportExport/Models/ImportedCustomField.cs@@ -0,0 +1,71 @@+//-----------------------------------------------------------------------+// <copyright file="ImportedCustomField.cs" company="aliasvault">+// Copyright (c) aliasvault. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.ImportExport.Models;++/// <summary>+/// Represents a single custom (user-defined) field value with the metadata of its+/// field definition.+/// </summary>+public class ImportedCustomField+{+ /// <summary>+ /// Gets or sets the source field definition ID. Multiple values that belong to the same+ /// multi-value field definition share this ID so they can be grouped under a single+ /// recreated <c>FieldDefinition</c> during import.+ /// </summary>+ public Guid DefinitionId { get; set; }++ /// <summary>+ /// Gets or sets the field label (display name).+ /// </summary>+ public string Label { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the field value.+ /// </summary>+ public string? Value { get; set; }++ /// <summary>+ /// Gets or sets the field type. Use the canonical constants from+ /// <see cref="AliasClientDb.Models.FieldType"/> (Text, Password, Hidden, Email, URL, Date, etc.)+ /// rather than raw strings, so a renamed/removed field type breaks compilation at the call site.+ /// Stored as a string to match the vault data model and the .avux export format.+ /// </summary>+ public string FieldType { get; set; } = AliasClientDb.Models.FieldType.Text;++ /// <summary>+ /// Gets or sets a value indicating whether this field supports multiple values.+ /// </summary>+ public bool IsMultiValue { get; set; }++ /// <summary>+ /// Gets or sets a value indicating whether the field value is hidden (masked) by default in the UI.+ /// </summary>+ public bool IsHidden { get; set; }++ /// <summary>+ /// Gets or sets a value indicating whether history tracking is enabled for this field.+ /// </summary>+ public bool EnableHistory { get; set; }++ /// <summary>+ /// Gets or sets the display order weight of the field definition (custom field ordering in the UI).+ /// </summary>+ public int Weight { get; set; }++ /// <summary>+ /// Gets or sets the display order weight of this individual value (ordering within a multi-value field).+ /// </summary>+ public int ValueWeight { get; set; }++ /// <summary>+ /// Gets or sets the applicable item types as a JSON array (e.g., '["Login","Identity"]').+ /// Null means applicable to all types.+ /// </summary>+ public string? ApplicableToTypes { get; set; }+}diff --git a/apps/server/Utilities/AliasVault.ImportExport/VaultImportService.cs b/apps/server/Utilities/AliasVault.ImportExport/VaultImportService.csindex ff807be08..9af8905b9 100644--- a/apps/server/Utilities/AliasVault.ImportExport/VaultImportService.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/VaultImportService.cs@@ -133,6 +133,7 @@ public static class VaultImportService{var credentials = new List<ImportedCredential>();var folderMap = BuildFolderPathMap(manifest.Folders);+ var fieldDefinitionsById = manifest.FieldDefinitions.ToDictionary(fd => fd.Id);foreach (var item in manifest.Items){@@ -156,7 +157,7 @@ public static class VaultImportService}// Extract field values- ExtractFieldValues(credential, item.FieldValues);+ ExtractFieldValues(credential, item.FieldValues, fieldDefinitionsById);// Add TOTP codesif (item.TotpCodes.Count > 0)@@ -234,13 +235,35 @@ public static class VaultImportService/// <summary>/// Extracts field values from the AvuxItem and populates the ImportedCredential./// </summary>- private static void ExtractFieldValues(ImportedCredential credential, List<AvuxFieldValue> fieldValues)+ /// <param name="credential">The credential to populate.</param>+ /// <param name="fieldValues">The field values from the AvuxItem.</param>+ /// <param name="fieldDefinitionsById">Lookup of custom field definitions keyed by their ID.</param>+ private static void ExtractFieldValues(ImportedCredential credential, List<AvuxFieldValue> fieldValues, Dictionary<Guid, AvuxFieldDefinition> fieldDefinitionsById){foreach (var fieldValue in fieldValues){if (string.IsNullOrEmpty(fieldValue.FieldKey)){- // Custom field - will be handled separately+ // Custom fields are imported as ImportedCustomField objects.+ if (fieldValue.FieldDefinitionId.HasValue+ && fieldDefinitionsById.TryGetValue(fieldValue.FieldDefinitionId.Value, out var definition))+ {+ credential.CustomFieldValues ??= new List<ImportedCustomField>();+ credential.CustomFieldValues.Add(new ImportedCustomField+ {+ DefinitionId = definition.Id,+ Label = definition.Label,+ Value = fieldValue.Value,+ FieldType = definition.FieldType,+ IsMultiValue = definition.IsMultiValue,+ IsHidden = definition.IsHidden,+ EnableHistory = definition.EnableHistory,+ Weight = definition.Weight,+ ValueWeight = fieldValue.Weight,+ ApplicableToTypes = definition.ApplicableToTypes,+ });+ }+continue;}