From b68453fa893c87a93589af32d82765cc2538b023 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sat, 12 Dec 2020 10:03:09 +0200 Subject: [PATCH 1/2] Add TOTP possibility to Predefined Sites --- keepassxc-browser/common/sites.js | 9 +++++++++ keepassxc-browser/content/totp-field.js | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/keepassxc-browser/common/sites.js b/keepassxc-browser/common/sites.js index 9800515..08f3c44 100644 --- a/keepassxc-browser/common/sites.js +++ b/keepassxc-browser/common/sites.js @@ -66,3 +66,12 @@ kpxcSites.exceptionFound = function(classList) { return false; }; + +kpxcSites.expectedTOTPMaxLength = function() { + if (document.location.origin.startsWith('https://www.amazon') + && document.location.href.includes('/ap/mfa')) { + return 20; + } + + return MAX_TOTP_INPUT_LENGTH; +}; diff --git a/keepassxc-browser/content/totp-field.js b/keepassxc-browser/content/totp-field.js index 91906d4..a4c285a 100644 --- a/keepassxc-browser/content/totp-field.js +++ b/keepassxc-browser/content/totp-field.js @@ -2,8 +2,8 @@ const ignoreRegex = /(bank|coupon|postal|user|zip).*code|comment|author/i; const ignoredTypes = [ 'email', 'password', 'username' ]; -const MIN_INPUT_LENGTH = 6; -const MAX_INPUT_LENGTH = 10; +const MIN_TOTP_INPUT_LENGTH = 6; +const MAX_TOTP_INPUT_LENGTH = 10; const acceptedOTPFields = [ '2fa', @@ -57,7 +57,7 @@ kpxcTOTPIcons.isValid = function(field, forced) { if (ignoredTypes.some(t => t === field.type) || field.offsetWidth < MINIMUM_INPUT_FIELD_WIDTH || field.size < 2 - || (field.maxLength > 0 && (field.maxLength < MIN_INPUT_LENGTH || field.maxLength > MAX_INPUT_LENGTH)) + || (field.maxLength > 0 && (field.maxLength < MIN_TOTP_INPUT_LENGTH || field.maxLength > kpxcSites.expectedTOTPMaxLength())) || ignoredTypes.some(t => t === field.autocomplete) || field.id.match(ignoreRegex) || field.name.match(ignoreRegex) From 7a9672a3c726b46e965a3828959941c226d6cf57 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sun, 13 Dec 2020 21:25:28 +0200 Subject: [PATCH 2/2] Move constants to one file --- keepassxc-browser/content/totp-field.js | 2 -- keepassxc-browser/content/ui.js | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/keepassxc-browser/content/totp-field.js b/keepassxc-browser/content/totp-field.js index a4c285a..c968b49 100644 --- a/keepassxc-browser/content/totp-field.js +++ b/keepassxc-browser/content/totp-field.js @@ -2,8 +2,6 @@ const ignoreRegex = /(bank|coupon|postal|user|zip).*code|comment|author/i; const ignoredTypes = [ 'email', 'password', 'username' ]; -const MIN_TOTP_INPUT_LENGTH = 6; -const MAX_TOTP_INPUT_LENGTH = 10; const acceptedOTPFields = [ '2fa', diff --git a/keepassxc-browser/content/ui.js b/keepassxc-browser/content/ui.js index bfa7aae..aa3fce6 100644 --- a/keepassxc-browser/content/ui.js +++ b/keepassxc-browser/content/ui.js @@ -1,6 +1,8 @@ 'use strict'; const MINIMUM_INPUT_FIELD_WIDTH = 60; +const MIN_TOTP_INPUT_LENGTH = 6; +const MAX_TOTP_INPUT_LENGTH = 10; const DatabaseState = { DISCONNECTED: 0,