Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update password importers to strip any leading UTF-8 byte order marks (#2363)
Leendert de Borstb1f94ad6d3d6
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportService1Password.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportService1Password.razorindex 9ee695a3e..55285d22a 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportService1Password.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportService1Password.razor@@ -1,7 +1,6 @@@using AliasVault.ImportExport.Models@using AliasVault.ImportExport.Importers@using Microsoft.Extensions.Localization-@using System.Text@inject NavigationManager NavigationManager@inject GlobalNotificationService GlobalNotificationService@inject IStringLocalizerFactory LocalizerFactory@@ -34,7 +33,7 @@case ".csv":// Text CSV file- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await OnePasswordImporter.ImportFromCsvAsync(fileContents);default:diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceAliasVault.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceAliasVault.razorindex 8eb45af79..db23c8335 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceAliasVault.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceAliasVault.razor@@ -6,7 +6,6 @@@using AliasVault.ImportExport.Importers@using AliasVault.ImportExport@using Microsoft.Extensions.Localization-@using System.Text<ImportServiceCard@ref="importServiceCard"@@ -43,7 +42,7 @@else if (filename.EndsWith(".csv", StringComparison.OrdinalIgnoreCase)){// Process as text CSV file- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await ItemCsvService.ImportItemsFromCsv(fileContents);}elsediff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceBitwarden.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceBitwarden.razorindex d5fc31fce..ad064427c 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceBitwarden.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceBitwarden.razor@@ -1,7 +1,6 @@@using AliasVault.ImportExport.Models@using AliasVault.ImportExport.Importers@using Microsoft.Extensions.Localization-@using System.Text@inject NavigationManager NavigationManager@inject GlobalNotificationService GlobalNotificationService@inject IStringLocalizerFactory LocalizerFactory@@ -34,7 +33,7 @@case ".csv":// Text CSV file- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await BitwardenImporter.ImportFromCsvAsync(fileContents);default:diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceChrome.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceChrome.razorindex 5520d0205..b057095e0 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceChrome.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceChrome.razor@@ -1,7 +1,6 @@@using AliasVault.ImportExport.Models@using AliasVault.ImportExport.Importers@using Microsoft.Extensions.Localization-@using System.Text@inject NavigationManager NavigationManager@inject GlobalNotificationService GlobalNotificationService@inject IStringLocalizerFactory LocalizerFactory@@ -23,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await ChromeImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceDashlane.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceDashlane.razorindex 184e67040..e10b242fc 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceDashlane.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceDashlane.razor@@ -1,7 +1,6 @@@using AliasVault.ImportExport.Models@using AliasVault.ImportExport.Importers@using Microsoft.Extensions.Localization-@using System.Text@inject NavigationManager NavigationManager@inject GlobalNotificationService GlobalNotificationService@inject IStringLocalizerFactory LocalizerFactory@@ -23,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await DashlaneImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceDropbox.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceDropbox.razorindex e8f3a6f46..2a7cdd112 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceDropbox.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceDropbox.razor@@ -1,7 +1,6 @@@using AliasVault.ImportExport.Models@using AliasVault.ImportExport.Importers@using Microsoft.Extensions.Localization-@using System.Text@inject NavigationManager NavigationManager@inject GlobalNotificationService GlobalNotificationService@inject IStringLocalizerFactory LocalizerFactory@@ -23,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await DropboxImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceEdge.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceEdge.razorindex 700bc8b6b..e2cedab6f 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceEdge.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceEdge.razor@@ -1,7 +1,6 @@@using AliasVault.ImportExport.Models@using AliasVault.ImportExport.Importers@using Microsoft.Extensions.Localization-@using System.Text@inject NavigationManager NavigationManager@inject GlobalNotificationService GlobalNotificationService@inject IStringLocalizerFactory LocalizerFactory@@ -23,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await EdgeImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceEnpass.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceEnpass.razorindex a8a3ec62b..065b7c826 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceEnpass.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceEnpass.razor@@ -1,7 +1,6 @@@using AliasVault.ImportExport.Models@using AliasVault.ImportExport.Importers@using Microsoft.Extensions.Localization-@using System.Text@inject NavigationManager NavigationManager@inject GlobalNotificationService GlobalNotificationService@inject IStringLocalizerFactory LocalizerFactory@@ -23,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await EnpassImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceFirefox.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceFirefox.razorindex 4b568933b..2158c4442 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceFirefox.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceFirefox.razor@@ -1,7 +1,6 @@@using AliasVault.ImportExport.Models@using AliasVault.ImportExport.Importers@using Microsoft.Extensions.Localization-@using System.Text@inject NavigationManager NavigationManager@inject GlobalNotificationService GlobalNotificationService@inject IStringLocalizerFactory LocalizerFactory@@ -23,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await FirefoxImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceGenericCsv.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceGenericCsv.razorindex ea93205dd..5cf5fdefb 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceGenericCsv.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceGenericCsv.razor@@ -40,7 +40,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = System.Text.Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await GenericCsvImporter.ImportFromCsvAsync(fileContents);}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceKeePass.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceKeePass.razorindex b87c289f6..a3026c04c 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceKeePass.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceKeePass.razor@@ -22,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = System.Text.Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await KeePassImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceKeePassXC.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceKeePassXC.razorindex a37a2dab7..e7e5b9f8a 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceKeePassXC.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceKeePassXC.razor@@ -22,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = System.Text.Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await KeePassXcImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceLastPass.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceLastPass.razorindex 320b7a6b9..a9a1dd786 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceLastPass.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceLastPass.razor@@ -22,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = System.Text.Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await LastPassImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceNordPass.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceNordPass.razorindex 4487568ac..d44943efd 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceNordPass.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceNordPass.razor@@ -22,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = System.Text.Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await NordPassImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceProtonPass.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceProtonPass.razorindex 9ca25f447..181925eb7 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceProtonPass.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceProtonPass.razor@@ -1,7 +1,6 @@@using AliasVault.ImportExport.Models@using AliasVault.ImportExport.Importers@using Microsoft.Extensions.Localization-@using System.Text@inject NavigationManager NavigationManager@inject GlobalNotificationService GlobalNotificationService@inject IStringLocalizerFactory LocalizerFactory@@ -34,7 +33,7 @@case ".csv":// Text CSV file- var fileContents = Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await ProtonPassImporter.ImportFromCsvAsync(fileContents);default:diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceRoboform.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceRoboform.razorindex 0918bf3b5..57835ba2f 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceRoboform.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceRoboform.razor@@ -22,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = System.Text.Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await RoboformImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceStrongbox.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceStrongbox.razorindex 72cd02a87..e1f56e69c 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceStrongbox.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceStrongbox.razor@@ -22,7 +22,7 @@private static async Task<ImportFileResult> ProcessFile(string filename, byte[] fileBytes){- var fileContents = System.Text.Encoding.UTF8.GetString(fileBytes);+ var fileContents = await BaseImporter.DecodeFileContentAsync(fileBytes);return await StrongboxImporter.ImportFromCsvAsync(fileContents);}}diff --git a/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/roboform.csv b/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/roboform.csvindex 376f772a4..31917bf57 100644--- a/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/roboform.csv+++ b/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/roboform.csv@@ -3,3 +3,7 @@ Com,https://www.example.com.com,https://www.example.com,username1,password1,,,"UExample,https://www.example.com,https://www.example.com,exampleusername,examplepassword,Examplenote,,"User ID$,,,txt,exampleusername","Password$,,,pwd,examplepassword"Safenotename,,,,,Safenote content example here,Business,https://www.business.com,https://www.business.com,businessusername,businesspassword,,/Business,"User ID$,,,txt,businessusername","Password$,,,pwd,businesspassword"+Multiline safenote,,,,,"First note line+Second note line++Fourth note line after a blank one",diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.csindex 223a2201d..d23c21e76 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs@@ -8,6 +8,7 @@namespace AliasVault.ImportExport.Importers;using System.Globalization;+using System.Text;using System.Text.RegularExpressions;using AliasClientDb;using AliasClientDb.Models;@@ -40,6 +41,18 @@ public static class BaseImporter};}+ /// <summary>+ /// Decodes uploaded file bytes into text.+ /// </summary>+ /// <param name="fileBytes">The raw bytes of the uploaded file.</param>+ /// <returns>The decoded file content.</returns>+ public static async Task<string> DecodeFileContentAsync(byte[] fileBytes)+ {+ using var stream = new MemoryStream(fileBytes);+ using var reader = new StreamReader(stream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true);+ return await reader.ReadToEndAsync();+ }+/// <summary>/// Creates a CsvReader with configuration and improved error handling./// </summary>