Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add TOTP urldecode on import (#773)
Leendert de Borst2a9bba79daed
diff --git a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.csindex f39a025f8..1dd548a19 100644--- a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs+++ b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs@@ -117,7 +117,7 @@ public class ImportExportTestsAssert.That(aliasVaultCredential.Password, Is.EqualTo("toor"));});- // Test entry with multiple URLs (TutaNota3)+ // Test entry with multiple URLs (TutaNota3) and URL-encoded TOTP URIvar multiUrlCredential = importedCredentials.First(c => c.ServiceName == "TutaNota3");Assert.Multiple(() =>{@@ -127,6 +127,7 @@ public class ImportExportTestsAssert.That(multiUrlCredential.ServiceUrls[1], Is.EqualTo("https://app.aliasvault.net"));Assert.That(multiUrlCredential.ServiceUrls[2], Is.EqualTo("https://downloads.aliasvault.net"));Assert.That(multiUrlCredential.Username, Is.EqualTo("[email protected]"));+ Assert.That(multiUrlCredential.TwoFactorSecret, Is.EqualTo("otpauth://totp/Test%20name%3Atest%40test.org?secret=PLW4SB3PQ7MKVXY2MXF4NEXS6Y&issuer=Alias%20Vault"));});// Verify multiple URLs get converted to multiple FieldValues@@ -142,6 +143,15 @@ public class ImportExportTestsAssert.That(urlFieldValues[1].Weight, Is.EqualTo(1));Assert.That(urlFieldValues[2].Weight, Is.EqualTo(2));});++ // Verify TOTP code name is properly URL-decoded when converting from otpauth URI+ var multiUrlItemTotpCode = multiUrlItem.TotpCodes.FirstOrDefault();+ Assert.That(multiUrlItemTotpCode, Is.Not.Null);+ Assert.Multiple(() =>+ {+ Assert.That(multiUrlItemTotpCode!.SecretKey, Is.EqualTo("PLW4SB3PQ7MKVXY2MXF4NEXS6Y"));+ Assert.That(multiUrlItemTotpCode.Name, Is.EqualTo("Alias Vault: Test name:[email protected]"), "TOTP name should be URL-decoded from the otpauth URI");+ });}/// <summary>diff --git a/apps/server/Utilities/AliasVault.TotpGenerator/TotpHelper.cs b/apps/server/Utilities/AliasVault.TotpGenerator/TotpHelper.csindex ab5f1116c..b0a02b877 100644--- a/apps/server/Utilities/AliasVault.TotpGenerator/TotpHelper.cs+++ b/apps/server/Utilities/AliasVault.TotpGenerator/TotpHelper.cs@@ -35,13 +35,25 @@ public static class TotpHelperif (string.IsNullOrWhiteSpace(name)){// The label is everything after 'totp/' and before '?'- var label = uri.AbsolutePath.TrimStart('/');+ var label = System.Web.HttpUtility.UrlDecode(uri.AbsolutePath.TrimStart('/'));- // If the label contains ':', take the part after it- name = label.Contains(':') ? label.Split(':')[1] : label;+ // Check if there's an issuer in the query params+ var issuer = queryParams["issuer"];++ // If the label contains ':', it might be in the format "issuer:account"+ // Only split if there's no issuer in query params (to avoid splitting account names with colons)+ if (label.Contains(':') && string.IsNullOrWhiteSpace(issuer))+ {+ // Split on the first colon only+ var colonIndex = label.IndexOf(':');+ name = label.Substring(colonIndex + 1);+ }+ else+ {+ name = label;+ }// If there's an issuer in the query params, use it as a prefix- var issuer = queryParams["issuer"];if (!string.IsNullOrWhiteSpace(issuer)){name = $"{issuer}: {name}";