From f5f594696dfb25190c602e7adb081a621b224fe5 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sun, 28 Feb 2021 08:00:48 +0200 Subject: [PATCH] Add exception for Protonmail mailbox password input --- keepassxc-browser/common/sites.js | 23 ++++++++++++------- .../content/keepassxc-browser.js | 17 +++++++++++++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/keepassxc-browser/common/sites.js b/keepassxc-browser/common/sites.js index 5facf06..2fe703e 100644 --- a/keepassxc-browser/common/sites.js +++ b/keepassxc-browser/common/sites.js @@ -46,22 +46,29 @@ kpxcSites.googlePasswordFormUrl = 'https://accounts.google.com/signin/v2/challen kpxcSites.googleUrl = 'https://accounts.google.com'; kpxcSites.savedForm = undefined; -// Handles a few exceptions for certain sites where password form is inside a div -// or another element that is not detected directly. Triggered by MutationObserver. -// Returns true if an Element has a matching classList. -kpxcSites.exceptionFound = function(classList) { - if (!classList || classList.length === 0) { +/** + * Handles a few exceptions for certain sites where password form is inside a div + * or another element that is not detected directly. Triggered by MutationObserver. + * @param {string} identifier Usually a classList or element id + * @returns {boolean} True if an Element has a match with the identifier and document location + */ +kpxcSites.exceptionFound = function(identifier) { + if (!identifier || identifier.length === 0) { return; } if (document.location.origin === 'https://idmsa.apple.com' - && [ 'password', 'form-row', 'show-password' ].every(c => classList.contains(c))) { + && [ 'password', 'form-row', 'show-password' ].every(c => identifier.contains(c))) { return true; } else if (document.location.origin.startsWith('https://signin.ebay.') - && classList.contains('null')) { + && identifier.contains('null')) { return true; } else if (document.location.origin.startsWith('https://www.fidelity.com') - && classList.contains('fs-mask-username')) { + && identifier.contains('fs-mask-username')) { + return true; + } else if (document.location.origin.startsWith('https://app.protonmail.ch') + || document.location.origin.startsWith('https://mail.protonmail.com') + && identifier === 'mailboxPassword') { return true; } diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index b1f8d4e..a0a4fea 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -51,7 +51,7 @@ kpxcIcons.addIcon = async function(field, iconType) { // Adds all necessary icons to a saved form kpxcIcons.addIconsFromForm = async function(form) { const addUsernameIcons = async function(c) { - if (kpxc.settings.showLoginFormIcon && await kpxc.passwordFilled() === false) { + if (kpxc.settings.showLoginFormIcon && await kpxc.passwordFilledWithExceptions(c) === false) { // Special case where everything else has been hidden, but a single password field is now displayed. // For example PayPal and Amazon is handled like this. if (c.username && !c.password && c.passwordInputs.length === 1) { @@ -1230,6 +1230,21 @@ kpxc.passwordFilled = async function() { return await sendMessage('password_get_filled'); }; +/** + * Handle passwordFilled() with possible exceptions, e.g. Protonmail's mailbox password + * where we actually need two passwords for a successful login. + * If an exception is found, act like password is not yet filled. + * @param {Object} currentForm Current saved form. @see kpxcForm.saveForm + * @returns {boolean} True if password has been already filled + */ +kpxc.passwordFilledWithExceptions = async function(currentForm) { + if (currentForm.password && kpxcSites.exceptionFound(currentForm.password.id)) { + return false; + } + + return await sendMessage('password_get_filled'); +}; + // Prepares autocomplete and login popup ready for user interaction kpxc.prepareCredentials = async function() { if (kpxc.credentials.length === 0) {