-
Notifications
You must be signed in to change notification settings - Fork 4
[PB-4737] feat(user): add public keys validation for account recovery #851
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
base: master
Are you sure you want to change the base?
Conversation
4ca295d to
212af49
Compare
212af49 to
c635ea3
Compare
| @ApiProperty() | ||
| @IsOptional() | ||
| kyber?: string; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a line between this class and the next one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why in this class ecc and kyber are optional? Isn't it enough just to have optional public keys field in RecoverAccountDto? Because now we can have {ecc: undefined, kyber: underfined}, {ecc: , kyber: underfined}, {ecc: undefined, kyber: } and I don't think we should accept those as valid input
src/modules/user/user.usecase.ts
Outdated
| } | ||
|
|
||
| if (!withReset && !publicKeys) { | ||
| throw new BadRequestException('Invalid backup file'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Invalid keys' it's a better naming as you do not know if those come from a backup file or anything else in the future
src/modules/user/user.usecase.ts
Outdated
| publicKeys.kyber && existingKeys.kyber !== publicKeys.kyber; | ||
|
|
||
| if (eccMismatch || kyberMismatch) { | ||
| throw new BadRequestException('Invalid backup file'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. In this case it could be worth it to specify which key is failing.
|
WDYT of this PR @TamaraFinogina ? |
|
|
||
| const user = await this.userRepository.findByUuid(userUuid); | ||
|
|
||
| if (publicKeys) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if withReset = true and mismatching public keys, then backup won't go through?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sg-gs Do we require/can send publicKeys for account reset? Becuase now we check public keys and if they fail we abort even if it's withReset=true
src/modules/user/user.usecase.ts
Outdated
|
|
||
| if (publicKeys) { | ||
| const existingKeys = await this.keyServerUseCases.getPublicKeys(user.id); | ||
| const eccMismatch = publicKeys.ecc && existingKeys.ecc !== publicKeys.ecc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we send publicKeys = {ecc: underfined, kyber: underfined}, then publicKeys.ecc would be false, right? so, the eccMismatch will be false without even checking existingKeys.ecc !== publicKeys.ecc; part, no?
I think we shouldn't accept those keys. Or at least use something like
! publicKeys.ecc || existingKeys.ecc !== publicKeys.ecc
then undefined, null or similar keeys will give a mismatch
src/modules/user/user.usecase.ts
Outdated
| const existingKeys = await this.keyServerUseCases.getPublicKeys(user.id); | ||
| const eccMismatch = publicKeys.ecc && existingKeys.ecc !== publicKeys.ecc; | ||
| const kyberMismatch = | ||
| publicKeys.kyber && existingKeys.kyber !== publicKeys.kyber; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@douglas-xt This check would pass for publicKeys = {ecc: underfined, kyber: underfined} without even checking what existingKeys are. I know that now they are not empty, but if we change that in the future this line becomes an issue. Can we remove publicKeys.kyber && and just do the comparison?
|



This PR adds validation of public keys during account recovery to prevent users from restoring their account using a backup file that doesn't belong to them.
When a user performs account recovery, the public keys included in the backup file are now compared against the keys stored in the database. If the keys don't match, the recovery is rejected with a clear error message indicating the backup file doesn't correspond to the account.
This change works in conjunction with updates in the SDK and drive-web that now include public keys in the backup file generation and send them during the recovery request.