Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Disable registration in v1 auth controller (#2159)
Leendert de Borste25602d49cf9
diff --git a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs b/apps/server/AliasVault.Api/Controllers/V1/AuthController.csindex 958248ed4..aaa190ecd 100644--- a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs+++ b/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs@@ -40,19 +40,16 @@ using SecureRemotePassword;/// </summary>/// <param name="dbContextFactory">AliasServerDbContext instance.</param>/// <param name="userManager">UserManager instance.</param>-/// <param name="signInManager">SignInManager instance.</param>/// <param name="configuration">IConfiguration instance.</param>/// <param name="cache">IMemoryCache instance for persisting SRP values during multistep login process.</param>/// <param name="timeProvider">ITimeProvider instance. This returns the time which can be mutated for testing.</param>/// <param name="authLoggingService">AuthLoggingService instance. This is used to log auth attempts to the database.</param>/// <param name="config">Config instance.</param>/// <param name="settingsService">ServerSettingsService instance.</param>-/// <param name="registrationRateLimitService">RegistrationRateLimitService instance.</param>-/// <param name="ipBlockListService">IpBlockListService instance.</param>[Route("v{version:apiVersion}/[controller]")][ApiController][ApiVersion("1")]-public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserManager<AliasVaultUser> userManager, SignInManager<AliasVaultUser> signInManager, IConfiguration configuration, IMemoryCache cache, ITimeProvider timeProvider, AuthLoggingService authLoggingService, Config config, ServerSettingsService settingsService, RegistrationRateLimitService registrationRateLimitService, IpBlockListService ipBlockListService) : ControllerBase+public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserManager<AliasVaultUser> userManager, IConfiguration configuration, IMemoryCache cache, ITimeProvider timeProvider, AuthLoggingService authLoggingService, Config config, ServerSettingsService settingsService) : ControllerBase{/// <summary>/// Timeout in minutes for mobile login requests. Clients use 2 minutes for countdown, we use 3 here to give a bit of extra buffer time.@@ -429,89 +426,16 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM}/// <summary>- /// Register endpoint used to register a new user.+ /// Register endpoint (v1). Account creation via the v1 API is no longer supported: starting from+ /// this release only v2-capable clients are allowed to create accounts. The account-creation logic+ /// has been intentionally removed so that outdated clients (and old tests) can no longer register via v1./// </summary>- /// <param name="model">Register request model.</param>/// <returns>IActionResult.</returns>[HttpPost("register")]- public async Task<IActionResult> Register([FromBody] RegisterRequest model)+ public IActionResult Register(){- // Check if public registration is disabled in the configuration.- if (!config.PublicRegistrationEnabled)- {- return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.PUBLIC_REGISTRATION_DISABLED, 400));- }-- // Check the IP blocklist using the raw IP address.- var rawIpAddress = IpAddressUtility.GetRawIpAddressFromContext(HttpContext);- if (await ipBlockListService.IsBlockedForRegistrationAsync(rawIpAddress))- {- await authLoggingService.LogAuthEventFailAsync(model.Username, AuthEventType.Register, AuthFailureReason.IpBlocked);- return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.REGISTRATION_FAILED, 400));- }-- // Check IP-based registration rate limit- var settings = await settingsService.GetAllSettingsAsync();- var ipAddress = IpAddressUtility.GetAnonymizedIpFromContext(HttpContext, config.IpLoggingEnabled);- if (await registrationRateLimitService.IsRateLimitExceededAsync(ipAddress, settings.MaxRegistrationsPerIpPer24Hours))- {- await authLoggingService.LogAuthEventFailAsync(model.Username, AuthEventType.Register, AuthFailureReason.RegistrationRateLimitExceeded);- return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.REGISTRATION_RATE_LIMIT_EXCEEDED, 429));- }-- // Validate the username.- var (isValid, apiErrorCode) = await ValidateUsername(model.Username);- if (!isValid)- {- return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(apiErrorCode, 400));- }-- // Use the SrpIdentity from the request if provided (typically a GUID generated by the client),- // otherwise fall back to lowercase username for backward compatibility.- var srpIdentity = model.SrpIdentity ?? model.Username.ToLowerInvariant();-- var user = new AliasVaultUser- {- UserName = UsernameHelper.NormalizeUsername(model.Username),- SrpIdentity = srpIdentity,- CreatedAt = timeProvider.UtcNow,- UpdatedAt = timeProvider.UtcNow,- PasswordChangedAt = timeProvider.UtcNow,- };-- user.VaultManifests.Add(new AliasServerDb.VaultManifest- {- ManifestId = Guid.NewGuid(),- Category = AliasVault.Shared.Models.WebApi.V2.Vault.VaultManifestCategory.Main,- VaultBlob = string.Empty,- StorageFormat = "sqlite-blob",- Version = "0.0.0",- RevisionNumber = 0,- Salt = model.Salt,- Verifier = model.Verifier,- EncryptionType = model.EncryptionType,- EncryptionSettings = model.EncryptionSettings,- FileSize = 0,- CreatedAt = timeProvider.UtcNow,- UpdatedAt = timeProvider.UtcNow,- });-- var result = await userManager.CreateAsync(user);-- if (result.Succeeded)- {- await authLoggingService.LogAuthEventSuccessAsync(model.Username, AuthEventType.Register);-- // When a user is registered, they are automatically signed in.- await signInManager.SignInAsync(user, isPersistent: false);-- // Return the token.- var tokenModel = await GenerateNewTokensForUser(user, extendedLifetime: true);- return Ok(tokenModel);- }-- var errors = result.Errors.Select(e => e.Description).ToArray();- return BadRequest(ServerValidationErrorResponse.Create(errors, 400));+ // v1 registration is intentionally disabled. Clients must use the v2 API to create accounts.+ return StatusCode(410, ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.REGISTRATION_FAILED, 410));}/// <summary>