Skip to content

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

Add bitwarden .zip extension to import, refactor import service valid extension check (#1947)

Leendert de Borste08966c89755
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.razor
index a03aeaa3f..7069b62dd 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
@@ -23,22 +23,22 @@
private static async Task<List<ImportedCredential>> ProcessFile(string filename, byte[] fileBytes)
{
- // Check file extension to determine format
- if (filename.EndsWith(".1pux", StringComparison.OrdinalIgnoreCase))
- {
- // Binary .1pux file with attachments and metadata
- var importer = new OnePassword1puxImporter();
- return await importer.ImportFromArchiveAsync(fileBytes);
- }
- else if (filename.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
- {
- // Text CSV file
- var fileContents = Encoding.UTF8.GetString(fileBytes);
- return await OnePasswordImporter.ImportFromCsvAsync(fileContents);
- }
- else
+ var extension = Path.GetExtension(filename).ToLowerInvariant();
+
+ switch (extension)
{
- throw new InvalidOperationException($"Unsupported file format: {filename}. Please upload a .csv or .1pux file.");
+ case ".1pux":
+ // Binary .1pux file with attachments and metadata
+ var puxImporter = new OnePassword1puxImporter();
+ return await puxImporter.ImportFromArchiveAsync(fileBytes);
+
+ case ".csv":
+ // Text CSV file
+ var fileContents = Encoding.UTF8.GetString(fileBytes);
+ return await OnePasswordImporter.ImportFromCsvAsync(fileContents);
+
+ default:
+ throw new InvalidOperationException($"Unsupported file extension: {extension}");
}
}
}
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceBitwarden.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceBitwarden.razor
index f678b568e..5e78e74f7 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
@@ -23,7 +23,22 @@
private static async Task<List<ImportedCredential>> ProcessFile(string filename, byte[] fileBytes)
{
- var fileContents = Encoding.UTF8.GetString(fileBytes);
- return await BitwardenImporter.ImportFromCsvAsync(fileContents);
+ var extension = Path.GetExtension(filename).ToLowerInvariant();
+
+ switch (extension)
+ {
+ case ".zip":
+ // Binary .zip file with attachments
+ var zipImporter = new BitwardenZipImporter();
+ return await zipImporter.ImportFromArchiveAsync(fileBytes);
+
+ case ".csv":
+ // Text CSV file
+ var fileContents = Encoding.UTF8.GetString(fileBytes);
+ return await BitwardenImporter.ImportFromCsvAsync(fileContents);
+
+ default:
+ throw new InvalidOperationException($"Unsupported file extension: {extension}");
+ }
}
}
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
index 9c74130d5..18565e891 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
@@ -1030,10 +1030,12 @@
return;
}
- // Only show zip warning if this importer doesn't support .zip files
- if (e.File.Name.EndsWith(".zip") && !AcceptedFileExtensions.Any(ext => ext.Equals(".zip", StringComparison.OrdinalIgnoreCase)))
+ // Validate file extension against accepted extensions
+ var fileExtension = Path.GetExtension(e.File.Name);
+ if (!AcceptedFileExtensions.Any(ext => ext.Equals(fileExtension, StringComparison.OrdinalIgnoreCase)))
{
- ImportError = Localizer["ImportErrorZipFile"];
+ var supportedFormats = string.Join(", ", AcceptedFileExtensions);
+ ImportError = Localizer["ImportErrorUnsupportedFormat", supportedFormats];
return;
}
diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx
index 4cd2f12a7..07ad8efac 100644
--- a/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx
+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServiceCard.en.resx
@@ -162,6 +162,10 @@
<value>Please unzip the export file before importing. See the instructions below for more information.</value>
<comment>Error message when user tries to import a zip file</comment>
</data>
+ <data name="ImportErrorUnsupportedFormat" xml:space="preserve">
+ <value>Unsupported file format. Supported formats: {0}</value>
+ <comment>Error message when user selects an unsupported file format. {0} is the list of supported extensions</comment>
+ </data>
<data name="ImportErrorFileTooLarge" xml:space="preserve">
<value>File size exceeds 10MB limit.</value>
<comment>Error message when file is too large</comment>
diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServices.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServices.en.resx
index 3ae176f5b..2729924fd 100644
--- a/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServices.en.resx
+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Settings/ImportExport/ImportServices.en.resx
@@ -77,7 +77,7 @@
<comment>Description for Bitwarden import service</comment>
</data>
<data name="BitwardenInstructionsPart1" xml:space="preserve">
- <value>In order to import your Bitwarden vault, you need to export it as a CSV file. You can do this by logging into your Bitwarden account, going to the 'Tools' menu and selecting 'Export vault' (to CSV).</value>
+ <value>In order to import your Bitwarden vault, you need to export it. You can do this by logging into your Bitwarden account, going to the 'Tools' menu and selecting 'Export vault'.</value>
<comment>Bitwarden export instructions part 1</comment>
</data>
<data name="BitwardenInstructionsPart2" xml:space="preserve">
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Exceptions/UnsupportedFileFormatException.cs b/apps/server/Utilities/AliasVault.ImportExport/Exceptions/UnsupportedFileFormatException.cs
new file mode 100644
index 000000000..44c715c21
--- /dev/null
+++ b/apps/server/Utilities/AliasVault.ImportExport/Exceptions/UnsupportedFileFormatException.cs
@@ -0,0 +1,41 @@
+//-----------------------------------------------------------------------
+// <copyright file="UnsupportedFileFormatException.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.Exceptions;
+
+/// <summary>
+/// Exception thrown when an unsupported file format is provided for import.
+/// </summary>
+public class UnsupportedFileFormatException : Exception
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UnsupportedFileFormatException"/> class.
+ /// </summary>
+ public UnsupportedFileFormatException()
+ : base("Unsupported file format")
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UnsupportedFileFormatException"/> class.
+ /// </summary>
+ /// <param name="message">The error message.</param>
+ public UnsupportedFileFormatException(string message)
+ : base(message)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UnsupportedFileFormatException"/> class.
+ /// </summary>
+ /// <param name="message">The error message.</param>
+ /// <param name="innerException">The inner exception.</param>
+ public UnsupportedFileFormatException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+}