From 07ae4bd06a8ce3a3aee5047ad5e43f21a64e3181 Mon Sep 17 00:00:00 2001 From: AKORA <65976562+A-K-O-R-A@users.noreply.github.com> Date: Sun, 6 Oct 2024 20:43:50 +0200 Subject: [PATCH] Automatically fill credentials when site preference override for the setting is present --- .../content/keepassxc-browser.js | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 35b2a1a..74b3b9c 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -501,15 +501,47 @@ kpxc.prepareCredentials = async function() { return; } - if (kpxc.settings.autoFillSingleEntry && kpxc.credentials.length === 1) { + if (kpxc.credentials.length === 1) { + if (kpxc.settings.autoFillSingleEntry) { kpxcFill.fillFromAutofill(); return; + } + + // Check for site preference overrides + const sitePreference = kpxc.retrieveSitePreference(); + if (sitePreference !== null && sitePreference !== undefined) { + if (sitePreference.autoFillCredentials === true) { + kpxcFill.fillFromAutofill(); + return; + } + } } kpxc.initLoginPopup(); kpxc.initAutocomplete(); }; +kpxc.retrieveSitePreference = function() { + // Check for autofill site preferences + for (const site of kpxc.settings.sitePreferences) { + let currentLocation; + try { + currentLocation = window.top.location.href; + } catch (err) { + // Cross-domain security error inspecting window.top.location.href. + // This catches an error when an iframe is being accessed from another (sub)domain + // -> use the iframe URL instead. + currentLocation = window.self.location.href; + } + + if (siteMatch(site.url, currentLocation) || site.url === currentLocation) { + return site; + } + } + + return null; +} + /** * Gets the credential list and shows the update banner * @param {string} usernameValue Submitted username