Skip to content

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

Silently fail incorrect 2FA codes during import instead of throwing exception (#852)

Leendert de Borst461c1a042d51
diff --git a/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/bitwarden.csv b/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/bitwarden.csv
index b43c15745..33b6580c1 100644
--- a/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/bitwarden.csv
+++ b/apps/server/Tests/AliasVault.UnitTests/TestData/Exports/bitwarden.csv
@@ -4,3 +4,6 @@ Business,,login,Item for business folder,,,0,,crisply,4CSp43uhSZri8A,
,,login,Test,,,0,,test2,asdasd,
Business,,login,TutaNota,,,0,,[email protected],blabla,otpauth://totp/Strongbox?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&algorithm=SHA1&digits=6&period=30
Business,,login,Aliasvault.net,,,0,https://www.aliasvault.net,root,toor,
+Business,,login,TutaNota3,,,0,,[email protected],blabla,otpauth://totp/Test%20name%3Atest%40test.org?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&issuer=Alias%20Vault
+Business,,login,TutaNota4,,,0,,[email protected],blabla,otpauth://totp/[email protected]?secret=TEST!INVALID&issuer=Alias%20Vault&algorithm=SHA1&digits=6&period=30
+Business,,login,TutaNota5,,,0,,[email protected],blabla,incorrectstring
diff --git a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs
index f5cab17dd..81ab01ea5 100644
--- a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs
+++ b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs
@@ -107,7 +107,10 @@ public class ImportExportTests
var importedCredentials = await BitwardenImporter.ImportFromCsvAsync(fileContent);
// Assert
- Assert.That(importedCredentials, Has.Count.EqualTo(5));
+ Assert.That(importedCredentials, Has.Count.EqualTo(8));
+
+ // There is one entry which has an invalid TOTP code ("! in the secret), we ensure this logic does not throw a fatal error.
+ var convertedCredentials = BaseImporter.ConvertToCredential(importedCredentials);
// Test specific entries
var tutaNotaCredential = importedCredentials.First(c => c.ServiceName == "TutaNota");
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs
index a2beb0d06..0c7577ba8 100644
--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs
+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/BaseImporter.cs
@@ -53,18 +53,27 @@ public static class BaseImporter
if (!string.IsNullOrEmpty(importedCredential.TwoFactorSecret))
{
// Sanitize the secret key by converting from potential URI to secret key and name.
- var (secretKey, name) = TotpHelper.SanitizeSecretKey(importedCredential.TwoFactorSecret);
-
- credential.TotpCodes = new List<TotpCode>
+ try
{
- new()
+ var (secretKey, name) = TotpHelper.SanitizeSecretKey(importedCredential.TwoFactorSecret);
+
+ credential.TotpCodes = new List<TotpCode>
{
- Name = name ?? "Authenticator",
- SecretKey = secretKey,
- CreatedAt = importedCredential.CreatedAt ?? DateTime.UtcNow,
- UpdatedAt = importedCredential.UpdatedAt ?? DateTime.UtcNow,
- }
- };
+ new()
+ {
+ Name = name ?? "Authenticator",
+ SecretKey = secretKey,
+ CreatedAt = importedCredential.CreatedAt ?? DateTime.UtcNow,
+ UpdatedAt = importedCredential.UpdatedAt ?? DateTime.UtcNow,
+ }
+ };
+ }
+ catch (Exception ex)
+ {
+ // 2FA extraction failed, log the error and continue with the next credential
+ // so the import doesn't fail due to failed 2FA extraction.
+ Console.WriteLine($"Error importing TOTP code: {ex.Message}");
+ }
}
credentials.Add(credential);
@@ -72,4 +81,4 @@ public static class BaseImporter
return credentials;
}
-}
\ No newline at end of file
+}