From 570ca76ccac9f2a40fc9ca36fcc6736fe3c6bd11 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sat, 16 Mar 2019 09:14:59 +0200 Subject: [PATCH] Prevent scripts to use autocomplete --- keepassxc-browser/keepassxc-browser.js | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index 26f41e3..5064845 100755 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -127,11 +127,17 @@ cipAutocomplete.init = function(field) { .focus(cipAutocomplete.onFocus); }; -cipAutocomplete.onClick = function() { +cipAutocomplete.onClick = function(e) { + if (!cipAutocomplete.isTrusted(e)) { + return; + } jQuery(this).autocomplete('search', jQuery(this).val()); }; -cipAutocomplete.onOpen = function(event, ui) { +cipAutocomplete.onOpen = function(e, ui) { + if (!cipAutocomplete.isTrusted(e)) { + return; + } jQuery('ul.ui-autocomplete.ui-menu').css('z-index', 2147483636); }; @@ -145,6 +151,9 @@ cipAutocomplete.onSource = function(request, callback) { }; cipAutocomplete.onSelect = function(e, ui) { + if (!cipAutocomplete.isTrusted(e)) { + return; + } e.preventDefault(); cip.setValueWithChange(jQuery(this), ui.item.value); const fieldId = cipFields.prepareId(jQuery(this).attr('data-cip-id')); @@ -171,7 +180,10 @@ cipAutocomplete.onBlur = function() { } }; -cipAutocomplete.onFocus = function() { +cipAutocomplete.onFocus = function(e) { + if (!cipAutocomplete.isTrusted(e)) { + return; + } cip.u = jQuery(this); if (jQuery(this).val() === '') { @@ -179,6 +191,17 @@ cipAutocomplete.onFocus = function() { } }; +// Search for isTrusted from jQuery's originalEvent +cipAutocomplete.isTrusted = function(e) { + for (let f = e.originalEvent; f !== null; f = f.originalEvent) { + if (f.isTrusted !== undefined) { + return f.isTrusted; + } + } + return false; +}; + + var cipPassword = {}; cipPassword.observedIcons = []; cipPassword.observingLock = false;