-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(auth-validator): [Auth/PM-22975] Client Version Validator #6588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Patrick-Pimentel-Bitwarden
wants to merge
58
commits into
main
Choose a base branch
from
auth/pm-22975/client-version-validator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
1c4fd6c
feat(auth-validator): [PM-22975] Client Version Validator - initial iโฆ
Patrick-Pimentel-Bitwarden 22e9e5b
mend
Patrick-Pimentel-Bitwarden 1af2fba
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 47a26bb
fix(auth-validator): [PM-22975] Client Version Validator - Minor toucโฆ
Patrick-Pimentel-Bitwarden a82b31c
fix(auth-validator): [PM-22975] Client Version Validator - Fixing somโฆ
Patrick-Pimentel-Bitwarden 7d71ee2
fix(auth-validator): [PM-22975] Client Version Validator - Finished fโฆ
Patrick-Pimentel-Bitwarden 851f963
test(auth-validator): [PM-22975] Client Version Validator - Fixed tesโฆ
Patrick-Pimentel-Bitwarden 756ae5e
fix(auth-validator): [PM-22975] Client Version Validator - Fixed namiโฆ
Patrick-Pimentel-Bitwarden 7874ec7
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 91af02b
test(auth-validator): [PM-22975] Client Version Validator - Fixed tests.
Patrick-Pimentel-Bitwarden 59d9d7b
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 7897485
fix(auth-validator): [PM-22975] Client Version Validator - Renamed vaโฆ
Patrick-Pimentel-Bitwarden d0c5333
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden e46425d
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden d69842d
fix(auth-validator): [PM-22975] Client Version Validator - Added headโฆ
Patrick-Pimentel-Bitwarden 1681703
fix(auth-validator): [PM-22975] Client Version Validator - Trying to โฆ
Patrick-Pimentel-Bitwarden cb146fc
fix(auth-validator): [PM-22975] Client Version Validator - Fixed tests
Patrick-Pimentel-Bitwarden e74682b
Merge remote-tracking branch 'origin' into auth/pm-22975/client-versiโฆ
Patrick-Pimentel-Bitwarden 53e6509
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden b3b1b9b
fix(auth-validator): [PM-22975] Client Version Validator - misc changโฆ
Patrick-Pimentel-Bitwarden 8f89694
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 8b8694e
test(auth-validator): [PM-22975] Client Version Validator - WIP changes.
Patrick-Pimentel-Bitwarden ed89cf8
fix(auth-validator): [PM-22975] Client Version Validator - Made enougโฆ
Patrick-Pimentel-Bitwarden 6696104
fix(auth-validator): [PM-22975] Client Version Validator - Fixed moreโฆ
Patrick-Pimentel-Bitwarden aa4f8ab
test(auth-validator): [PM-22975] Client Version Validator - Fixed theโฆ
Patrick-Pimentel-Bitwarden 86bca81
fix(auth-validator): [PM-22975] Client Version Validator - Changed soโฆ
Patrick-Pimentel-Bitwarden c1bc10b
fix(auth-validator): [PM-22975] Client Version Validator - Removed unโฆ
Patrick-Pimentel-Bitwarden 753670d
fix(auth-validator): [PM-22975] Client Version Validator - Took in feโฆ
Patrick-Pimentel-Bitwarden 544965e
test(auth-validator): [PM-22975] Client Version Validator - Fixed test
Patrick-Pimentel-Bitwarden f719763
fix(auth-validator): [PM-22975] Client Version Validator - Took in teโฆ
Patrick-Pimentel-Bitwarden cff2f5d
fix(auth-validator): [PM-22975] Client Version Validator - Added moreโฆ
Patrick-Pimentel-Bitwarden 2ed458d
fix(auth-validator): [PM-22975] Client Version Validator - Removed onโฆ
Patrick-Pimentel-Bitwarden d706796
fix(auth-validator): [PM-22975] Client Version Validator - Updated vaโฆ
Patrick-Pimentel-Bitwarden 2264056
fix(auth-validator): [PM-22975] Client Version Validator - Updated wiโฆ
Patrick-Pimentel-Bitwarden 55bfb71
test(auth-validator): [PM-22975] Client Version Validator - Added encโฆ
Patrick-Pimentel-Bitwarden 36e7b1c
test(auth-validator): [PM-22975] Client Version Validator - Added stuโฆ
Patrick-Pimentel-Bitwarden 1f8be3b
docs(auth-validator): [PM-22975] Client Version Validator - Updated cโฆ
Patrick-Pimentel-Bitwarden 998aeb1
fix(auth-validator): [PM-22975] Client Version Validator - Not havingโฆ
Patrick-Pimentel-Bitwarden 27c9e4d
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden fb83df3
fix(auth-validator): [PM-22975] Client Version Validator - Minor toucโฆ
Patrick-Pimentel-Bitwarden 10cbfd8
fix(auth-validator): [PM-22975] Client Version Validator - Minor funcโฆ
Patrick-Pimentel-Bitwarden 79256d7
fix(auth-validator): [PM-22975] Client Version Validator - Minor chanโฆ
Patrick-Pimentel-Bitwarden 865e76f
fix(auth-validator): [PM-22975] Client Version Validator - Reorder ofโฆ
Patrick-Pimentel-Bitwarden 50298fb
fix(auth-validator): [PM-22975] Client Version Validator - Fixed testโฆ
Patrick-Pimentel-Bitwarden ad68312
fix(auth-validator): [PM-22975] Client Version Validator - Added tickโฆ
Patrick-Pimentel-Bitwarden 3f0d7d2
test(auth-validator): [PM-22975] Client Version Validator - added oneโฆ
Patrick-Pimentel-Bitwarden fc6a513
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 06224d9
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 6a5518a
fix(auth-validator): [PM-22975] Client Version Validator - Rename funโฆ
Patrick-Pimentel-Bitwarden fcd4b24
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 3736944
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 6ddd8c7
Merge branch 'main' into auth/pm-22975/client-version-validator
JaredSnider-Bitwarden c7ea4ea
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 3bd54e5
test(auth-validator): [PM-22975] Client Version Validator - Fixed tests.
Patrick-Pimentel-Bitwarden f44cd58
Merge remote-tracking branch 'origin' into auth/pm-22975/client-versiโฆ
Patrick-Pimentel-Bitwarden 9a1f91f
fix(auth-validator): [PM-22975] Client Version Validator - Fixed tests.
Patrick-Pimentel-Bitwarden a3f5a32
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden 19d43e9
Merge branch 'main' into auth/pm-22975/client-version-validator
Patrick-Pimentel-Bitwarden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ๏ปฟnamespace Bit.Core.KeyManagement; | ||
|
|
||
| public static class Constants | ||
| { | ||
| public static readonly Version MinimumClientVersion = new Version("2025.11.0"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Core/KeyManagement/Queries/GetMinimumClientVersionForUserQuery.cs
JaredSnider-Bitwarden marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ๏ปฟusing Bit.Core.Entities; | ||
| using Bit.Core.KeyManagement.Queries.Interfaces; | ||
|
|
||
| namespace Bit.Core.KeyManagement.Queries; | ||
|
|
||
| public class GetMinimumClientVersionForUserQuery(IIsV2EncryptionUserQuery isV2EncryptionUserQuery) | ||
| : IGetMinimumClientVersionForUserQuery | ||
| { | ||
| public async Task<Version?> Run(User? user) | ||
| { | ||
| if (user == null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| if (await isV2EncryptionUserQuery.Run(user)) | ||
Patrick-Pimentel-Bitwarden marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| return Constants.MinimumClientVersion; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
src/Core/KeyManagement/Queries/Interfaces/IGetMinimumClientVersionForUserQuery.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ๏ปฟusing Bit.Core.Entities; | ||
|
|
||
| namespace Bit.Core.KeyManagement.Queries.Interfaces; | ||
|
|
||
| public interface IGetMinimumClientVersionForUserQuery | ||
| { | ||
| Task<Version?> Run(User? user); | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/Core/KeyManagement/Queries/Interfaces/IIsV2EncryptionUserQuery.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ๏ปฟusing Bit.Core.Entities; | ||
|
|
||
| namespace Bit.Core.KeyManagement.Queries.Interfaces; | ||
|
|
||
| public interface IIsV2EncryptionUserQuery | ||
| { | ||
| Task<bool> Run(User user); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| ๏ปฟusing Bit.Core.Entities; | ||
| using Bit.Core.Enums; | ||
| using Bit.Core.KeyManagement.Queries.Interfaces; | ||
| using Bit.Core.KeyManagement.Repositories; | ||
| using Bit.Core.KeyManagement.Utilities; | ||
|
|
||
| namespace Bit.Core.KeyManagement.Queries; | ||
|
|
||
| public class IsV2EncryptionUserQuery(IUserSignatureKeyPairRepository userSignatureKeyPairRepository) | ||
quexten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| : IIsV2EncryptionUserQuery | ||
| { | ||
| public async Task<bool> Run(User user) | ||
quexten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| ArgumentNullException.ThrowIfNull(user); | ||
|
|
||
| var hasSignatureKeyPair = await userSignatureKeyPairRepository.GetByUserIdAsync(user.Id) != null; | ||
| var isPrivateKeyEncryptionV2 = | ||
quexten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| !string.IsNullOrWhiteSpace(user.PrivateKey) && | ||
| EncryptionParsing.GetEncryptionType(user.PrivateKey) == EncryptionType.XChaCha20Poly1305_B64; | ||
|
|
||
| return hasSignatureKeyPair switch | ||
quexten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // Valid v2 user | ||
| true when isPrivateKeyEncryptionV2 => true, | ||
| // Valid v1 user | ||
| false when !isPrivateKeyEncryptionV2 => false, | ||
| _ => throw new InvalidOperationException( | ||
Patrick-Pimentel-Bitwarden marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "User is in an invalid state for key rotation. User has a signature key pair, but the private key is not in v2 format, or vice versa.") | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JaredSnider-Bitwarden marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| ๏ปฟusing Bit.Core.Enums; | ||
|
|
||
| namespace Bit.Core.KeyManagement.Utilities; | ||
|
|
||
| public static class EncryptionParsing | ||
| { | ||
| /// <summary> | ||
| /// Helper method to convert an encryption type string to an enum value. | ||
| /// </summary> | ||
| public static EncryptionType GetEncryptionType(string encString) | ||
| { | ||
| var parts = encString.Split('.'); | ||
| if (parts.Length == 1) | ||
Patrick-Pimentel-Bitwarden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| throw new ArgumentException("Invalid encryption type string."); | ||
Patrick-Pimentel-Bitwarden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| if (byte.TryParse(parts[0], out var encryptionTypeNumber)) | ||
| { | ||
| if (Enum.IsDefined(typeof(EncryptionType), encryptionTypeNumber)) | ||
| { | ||
| return (EncryptionType)encryptionTypeNumber; | ||
| } | ||
| } | ||
| throw new ArgumentException("Invalid encryption type string."); | ||
Patrick-Pimentel-Bitwarden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/Identity/IdentityServer/RequestValidators/ClientVersionValidator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| ๏ปฟusing Bit.Core.Context; | ||
| using Bit.Core.Entities; | ||
| using Bit.Core.KeyManagement.Queries.Interfaces; | ||
| using Bit.Core.Models.Api; | ||
| using Duende.IdentityServer.Validation; | ||
|
|
||
| namespace Bit.Identity.IdentityServer.RequestValidators; | ||
|
|
||
| public interface IClientVersionValidator | ||
| { | ||
| Task<bool> ValidateAsync(User user, CustomValidatorRequestContext requestContext); | ||
| } | ||
|
|
||
| public class ClientVersionValidator( | ||
| ICurrentContext currentContext, | ||
| IGetMinimumClientVersionForUserQuery getMinimumClientVersionForUserQuery) | ||
| : IClientVersionValidator | ||
| { | ||
| private static readonly string UpgradeMessage = "Please update your app to continue using Bitwarden"; | ||
|
|
||
Patrick-Pimentel-Bitwarden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public async Task<bool> ValidateAsync(User? user, CustomValidatorRequestContext requestContext) | ||
Patrick-Pimentel-Bitwarden marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (user == null) | ||
Patrick-Pimentel-Bitwarden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return true; | ||
| } | ||
|
|
||
| var clientVersion = currentContext.ClientVersion; | ||
| var minVersion = await getMinimumClientVersionForUserQuery.Run(user); | ||
|
|
||
| // Fail-open if headers are missing or no restriction | ||
| if (minVersion == null) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| if (clientVersion < minVersion) | ||
| { | ||
| requestContext.ValidationErrorResult = new ValidationResult | ||
| { | ||
| Error = "invalid_client_version", | ||
| ErrorDescription = UpgradeMessage, | ||
| IsError = true | ||
| }; | ||
| requestContext.CustomResponse = new Dictionary<string, object> | ||
| { | ||
| { "ErrorModel", new ErrorResponseModel(UpgradeMessage) } | ||
| }; | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.