Plugin: handle salt input more carefully, fixes #16

This commit is contained in:
Val Packett 2023-07-29 02:45:22 -03:00
parent 777aa2d54f
commit bd0aefea34

View file

@ -608,12 +608,21 @@ Formatted with `deno fmt`.
} }
if (askSalt) { if (askSalt) {
this.modal.addSaltInput((e) => { this.modal.addSaltInput((e) => {
try { const saltText = e.target.value.trim();
this.salt = b64dec(e.target.value.trim()); if (saltText.length == 0) {
this.salt = null;
this.modal.setFeedback(''); this.modal.setFeedback('');
} else if (saltText.length < 16) {
this.salt = null;
this.modal.setFeedback('<p class=tiddlypwa-form-error>The salt is too short</p>');
} else {
try {
this.salt = b64dec(saltText);
} catch (_e) { } catch (_e) {
this.salt = null;
this.modal.setFeedback('<p class=tiddlypwa-form-error>Could not decode the salt</p>'); this.modal.setFeedback('<p class=tiddlypwa-form-error>Could not decode the salt</p>');
} }
}
}); });
} }
this.modal.showForm(); this.modal.showForm();