-
-
Notifications
You must be signed in to change notification settings - Fork 249
refactor: cache vault data while unlock #6205
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
Conversation
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
08fa4b0
to
848c8e7
Compare
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
packages/seedless-onboarding-controller/src/SeedlessOnboardingController.ts
Outdated
Show resolved
Hide resolved
packages/seedless-onboarding-controller/src/SeedlessOnboardingController.ts
Outdated
Show resolved
Hide resolved
packages/seedless-onboarding-controller/src/SeedlessOnboardingController.ts
Outdated
Show resolved
Hide resolved
packages/seedless-onboarding-controller/src/SeedlessOnboardingController.ts
Show resolved
Hide resolved
packages/seedless-onboarding-controller/src/SeedlessOnboardingController.ts
Outdated
Show resolved
Hide resolved
becffc2
to
d084fe8
Compare
I notice that you've applied the |
packages/seedless-onboarding-controller/src/SeedlessOnboardingController.ts
Outdated
Show resolved
Hide resolved
d37d238
to
4efa65b
Compare
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
Hi @mcmire, Yes, this is a refactor PR and some optimization (caching) for internal vault logics |
revokeToken, | ||
accessToken, | ||
}; | ||
const deserializedVaultData = deserializeVaultData(vaultData); |
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.
Hm, I don't understand why you separate parsing and deserialization? Why don't you merge deserialization into #decryptAndParseVaultData
?
await expect( | ||
controller.submitPassword(MOCK_PASSWORD), | ||
).rejects.toThrow( | ||
SeedlessOnboardingControllerErrorMessage.InvalidVaultData, |
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.
Are you throwing a different error here than before? If so, this can be considered a breaking change (depending on your definition of breaking change).
/** | ||
* The TTL of the password outdated cache in milliseconds. | ||
*/ | ||
readonly #passwordOutdatedCacheTTL: number; | ||
|
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 did you move that up?
TransactionController is maintaining an alphabetical ordering on properties and I kind of like it.
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.
I just wanna group the readonly
variables in one block. That's why I moved that up.
); | ||
decryptedVaultData = result.vault; | ||
vaultEncryptionKey = result.exportedKeyString; | ||
vaultEncryptionSalt = result.salt; |
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.
It's not supposed to validate the password, if the key is given, right?
SeedlessOnboardingControllerErrorMessage.InvalidVaultData, | ||
); | ||
throw new Error(SeedlessOnboardingControllerErrorMessage.VaultDataError); | ||
} | ||
|
||
let parsedVaultData: unknown; | ||
try { | ||
parsedVaultData = JSON.parse(data); | ||
} catch { | ||
throw new Error( | ||
SeedlessOnboardingControllerErrorMessage.InvalidVaultData, | ||
); | ||
throw new Error(SeedlessOnboardingControllerErrorMessage.VaultDataError); |
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.
Changing the error type can be considered a breaking change.
Why did you change it?
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.
Previously, it throws Invalid vault data
error.
But I think the error should be The decrypted vault has an unexpected shape.
since this is the parse error.
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.
I see. I think the previous error message was fine, but the new one is more differentiated. I think the error variable names are not expressive enough to reflect that meaning, so this can lead to them not being used correctly.
| SeedlessOnboardingControllerEvents | ||
| ExtractAvailableEvent<SeedlessOnboardingControllerMessenger> |
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.
Nit: SeedlessOnboardingControllerEvents
is already included in ExtractAvailableEvent<SeedlessOnboardingControllerMessenger>
, so you should be able to simplify this:
| SeedlessOnboardingControllerEvents | |
| ExtractAvailableEvent<SeedlessOnboardingControllerMessenger> | |
ExtractAvailableEvent<SeedlessOnboardingControllerMessenger> |
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.
Thanks for the review. I've addressed it in this commit, d7be4d5
| SeedlessOnboardingControllerEvents | ||
| ExtractAvailableEvent<SeedlessOnboardingControllerMessenger> |
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.
Nit: SeedlessOnboardingControllerEvents
is already included in ExtractAvailableEvent<SeedlessOnboardingControllerMessenger>
, so you should be able to simplify this:
| SeedlessOnboardingControllerEvents | |
| ExtractAvailableEvent<SeedlessOnboardingControllerMessenger> | |
ExtractAvailableEvent<SeedlessOnboardingControllerMessenger> |
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.
Addressed here, d7be4d5
d7be4d5
to
5c673a8
Compare
await this.#decryptAndParseVaultData(password, encryptionKey); | ||
if (this.#cachedDecryptedVaultData) { | ||
return this.#cachedDecryptedVaultData; | ||
} |
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.
Bug: Premature Cache Return Bypasses Security Checks
The caching in #unlockVaultAndGetVaultData
returns cached vault data prematurely. This bypasses all validation checks, including password, encryption key, and salt verification, which could lead to incorrect credentials appearing valid or the use of stale/compromised data.
Another worthwhile optimization would be to use the cached encryption key for encryption as well. (Currently it's only used for decryption.) And we may want to rotate the key after each controller unlock, like the KeyringController does it. |
Yes definitely. I will address this in the new PR, coz that includes breaking change to the encryptor interface. |
5c673a8
to
2fccc63
Compare
Explanation
This PR includes some refactors and optimizations of vault operations (lock/unlock) in the SeedlessOnboarding controller.
References
Changelog
Checklist