Skip to content

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

Update checks (#2469)

Leendert de Borst412d76a2cf0e
diff --git a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs b/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs
index 8ca0fa618..ae7e39a44 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs
@@ -208,6 +208,12 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
return Ok(new ValidateLoginResponse(true, string.Empty, null));
}
+ // Spend the login exchange so its proof cannot be replayed.
+ if (!AuthHelper.ConsumeSrpSession(cache, user, null))
+ {
+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.USER_NOT_FOUND, 400));
+ }
+
// Reset failed login attempts.
await userManager.ResetAccessFailedCountAsync(user);
await authLoggingService.LogAuthEventSuccessAsync(model.Username, AuthEventType.Login);
@@ -248,6 +254,12 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.INVALID_AUTHENTICATOR_CODE, 400));
}
+ // Spend the login exchange so its proof cannot be replayed.
+ if (!AuthHelper.ConsumeSrpSession(cache, user, null))
+ {
+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.USER_NOT_FOUND, 400));
+ }
+
// Validation of 2-FA token is successful, user is authenticated.
await userManager.ResetAccessFailedCountAsync(user);
await authLoggingService.LogAuthEventSuccessAsync(model.Username, AuthEventType.TwoFactorAuthentication);
@@ -293,6 +305,12 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.INVALID_RECOVERY_CODE, 400));
}
+ // Spend the login exchange so its proof cannot be replayed.
+ if (!AuthHelper.ConsumeSrpSession(cache, user, null))
+ {
+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.USER_NOT_FOUND, 400));
+ }
+
// Recovery code is valid, user is authenticated.
await userManager.ResetAccessFailedCountAsync(user);
await authLoggingService.LogAuthEventSuccessAsync(model.Username, AuthEventType.TwoFactorAuthentication);
diff --git a/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs b/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs
index 433a6272c..50bbc7ac8 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs
@@ -168,6 +168,12 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
return Ok(new ValidateLoginResponse(true, string.Empty, null));
}
+ // Spend the login exchange so its proof cannot be replayed.
+ if (!AuthHelper.ConsumeSrpSession(cache, user, model.LoginSessionId))
+ {
+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.USER_NOT_FOUND, 400));
+ }
+
// Reset failed login attempts.
await userManager.ResetAccessFailedCountAsync(user);
await authLoggingService.LogAuthEventSuccessAsync(model.Username, AuthEventType.Login);
@@ -209,6 +215,12 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.INVALID_AUTHENTICATOR_CODE, 400));
}
+ // Spend the login exchange so its proof cannot be replayed.
+ if (!AuthHelper.ConsumeSrpSession(cache, user, model.LoginSessionId))
+ {
+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.USER_NOT_FOUND, 400));
+ }
+
// Validation of 2-FA token is successful, user is authenticated.
await userManager.ResetAccessFailedCountAsync(user);
await authLoggingService.LogAuthEventSuccessAsync(model.Username, AuthEventType.TwoFactorAuthentication);
@@ -255,6 +267,12 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.INVALID_RECOVERY_CODE, 400));
}
+ // Spend the login exchange so its proof cannot be replayed.
+ if (!AuthHelper.ConsumeSrpSession(cache, user, model.LoginSessionId))
+ {
+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.USER_NOT_FOUND, 400));
+ }
+
// Recovery code is valid, user is authenticated.
await userManager.ResetAccessFailedCountAsync(user);
await authLoggingService.LogAuthEventSuccessAsync(model.Username, AuthEventType.TwoFactorAuthentication);
diff --git a/apps/server/Tests/AliasVault.UnitTests/Utilities/RsaEncryptionTests.cs b/apps/server/Tests/AliasVault.UnitTests/Utilities/RsaEncryptionTests.cs
index ce7218f8d..e6e5949e4 100644
--- a/apps/server/Tests/AliasVault.UnitTests/Utilities/RsaEncryptionTests.cs
+++ b/apps/server/Tests/AliasVault.UnitTests/Utilities/RsaEncryptionTests.cs
@@ -123,6 +123,32 @@ public class RsaEncryptionTests
Assert.That(decryptedKey, Is.EqualTo(symmetricKey), "Decrypted key should match the original symmetric key.");
}
+ /// <summary>
+ /// Tests that a labelled key decrypts only under the same label.
+ /// </summary>
+ [Test]
+ public void EncryptSymmetricKeyWithLabel_DecryptsOnlyUnderSameLabel()
+ {
+ var symmetricKey = Encryption.GenerateRandomSymmetricKey();
+ var encryptedKey = Encryption.EncryptSymmetricKeyWithRsa(symmetricKey, PublicKey, Encryption.MobileLoginPayloadKeyLabel);
+
+ Assert.That(Encryption.DecryptSymmetricKeyWithRsa(encryptedKey, PrivateKey, Encryption.MobileLoginPayloadKeyLabel), Is.EqualTo(symmetricKey));
+ Assert.That(() => Encryption.DecryptSymmetricKeyWithRsa(encryptedKey, PrivateKey, "aliasvault/v1/other"), Throws.Exception);
+ Assert.That(() => Encryption.DecryptSymmetricKeyWithRsa(encryptedKey, PrivateKey), Throws.Exception);
+ }
+
+ /// <summary>
+ /// Tests that the labelled path uses the same OAEP parameters (SHA-256, MGF1-SHA-256) as the built-in one.
+ /// </summary>
+ [Test]
+ public void EncryptSymmetricKeyWithEmptyLabel_MatchesBuiltInOaepSha256()
+ {
+ var symmetricKey = Encryption.GenerateRandomSymmetricKey();
+ var encryptedKey = Encryption.EncryptSymmetricKeyWithRsa(symmetricKey, PublicKey, string.Empty);
+
+ Assert.That(Encryption.DecryptSymmetricKeyWithRsa(encryptedKey, PrivateKey), Is.EqualTo(symmetricKey));
+ }
+
/// <summary>
/// Tests if EncryptSymmetricKey method throws an exception when given an invalid public key.
/// </summary>