1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-01 19:15:01 +02:00

All: Fixed setting issue that would cause a password to be saved in plain text in the database, even when the keychain is working

This commit is contained in:
Laurent Cozic 2020-10-20 16:37:14 +01:00
parent b125a768b8
commit 03063f1137
2 changed files with 15 additions and 0 deletions

View File

@ -79,6 +79,16 @@ describeIfCompatible('services_KeychainService', function() {
// However we should still get it via the Setting class, since it will use the keychain
expect(Setting.value('sync.5.password')).toBe('password');
// Now do it again - because there was a bug that would cause the second attempt to save to the db instead
Setting.setValue('sync.5.username', 'john');
await Setting.saveAll();
{
// Check that it's been removed from the database
const row = await db().selectOne('SELECT * FROM settings WHERE key = "sync.5.password"');
expect(row).toBe(undefined);
}
}));
});

View File

@ -1318,6 +1318,11 @@ class Setting extends BaseModel {
if (currentValue !== s.value) {
const wasSet = await this.keychainService().setPassword(passwordName, s.value);
if (wasSet) continue;
} else {
// The value is already in the keychain - so nothing to do
// Make sure to `continue` here otherwise it will save the password
// in clear text in the database.
continue;
}
} catch (error) {
this.logger().error(`Could not set setting on the keychain. Will be saved to database instead: ${s.key}:`, error);