1
0
mirror of https://github.com/bitwarden/server synced 2026-01-02 00:23:40 +00:00

fix(auth-validator): [PM-22975] Client Version Validator - Minor touchups to baserequest validator.

This commit is contained in:
Patrick Pimentel
2025-11-20 10:30:18 -05:00
parent 1af2fba496
commit 47a26bb204
4 changed files with 13 additions and 28 deletions

View File

@@ -10,36 +10,19 @@ public static class EncryptionParsing
/// </summary>
public static EncryptionType GetEncryptionType(string encString)
{
if (string.IsNullOrWhiteSpace(encString))
{
throw new ArgumentException("Encrypted string cannot be null or empty.", nameof(encString));
}
var parts = encString.Split('.');
if (parts.Length == 1)
{
// No header detected; assume AES CBC variants based on number of pieces
var splitParts = encString.Split('|');
if (splitParts.Length == 3)
{
return EncryptionType.AesCbc128_HmacSha256_B64;
}
return EncryptionType.AesCbc256_B64;
throw new ArgumentException("Invalid encryption type string.");
}
// Try parse header as numeric, then as enum name, else fail
if (byte.TryParse(parts[0], out var encryptionTypeNumber))
{
return (EncryptionType)encryptionTypeNumber;
if (Enum.IsDefined(typeof(EncryptionType), encryptionTypeNumber))
{
return (EncryptionType)encryptionTypeNumber;
}
}
if (Enum.TryParse(parts[0], out EncryptionType parsed))
{
return parsed;
}
throw new ArgumentException("Invalid encryption type header.", nameof(encString));
throw new ArgumentException("Invalid encryption type string.");
}
}

View File

@@ -122,6 +122,10 @@ public abstract class BaseRequestValidator<T> where T : class
return;
}
// 1.5 We need to check now the version number
await ValidateClientVersionAsync(context, validatorContext);
// 2. Decide if this user belongs to an organization that requires SSO.
validatorContext.SsoRequired = await RequireSsoLoginAsync(user, request.GrantType);
if (validatorContext.SsoRequired)

View File

@@ -11,7 +11,8 @@ public interface IClientVersionValidator
Task<bool> ValidateAsync(User user, CustomValidatorRequestContext requestContext);
}
public class ClientVersionValidator(ICurrentContext currentContext,
public class ClientVersionValidator(
ICurrentContext currentContext,
IGetMinimumClientVersionForUserQuery getMinimumClientVersionForUserQuery)
: IClientVersionValidator
{
@@ -37,7 +38,7 @@ public class ClientVersionValidator(ICurrentContext currentContext,
{
requestContext.ValidationErrorResult = new ValidationResult
{
Error = "invalid_grant",
Error = "invalid_client_version",
ErrorDescription = UpgradeMessage,
IsError = true
};

View File

@@ -16,11 +16,8 @@ using Bit.Core.Settings;
using Duende.IdentityModel;
using Duende.IdentityServer.Extensions;
using Duende.IdentityServer.Validation;
using HandlebarsDotNet;
using Microsoft.AspNetCore.Identity;
#nullable enable
namespace Bit.Identity.IdentityServer.RequestValidators;
public class CustomTokenRequestValidator : BaseRequestValidator<CustomTokenRequestValidationContext>,