mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
parent
908cd41037
commit
5f40d24df1
3 changed files with 36 additions and 8 deletions
|
|
@ -139,6 +139,23 @@ kpxcSites.totpExceptionFound = function(field) {
|
|||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles a few exceptions for certain sites where segmented 2FA fields are not regognized properly.
|
||||
* @param {object} form Form Element
|
||||
* @returns {boolean} True if an Element has a match with the needed indentfifiers and document location
|
||||
*/
|
||||
kpxcSites.segmentedTotpExceptionFound = function(form) {
|
||||
if (!form || form.nodeName !== 'FORM') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (document.location.href.startsWith('https://store.steampowered.com') && form.length === 5) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
kpxcSites.expectedTOTPMaxLength = function() {
|
||||
if (document.location.origin.startsWith('https://www.amazon')
|
||||
&& document.location.href.includes('/ap/mfa')) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const DEFAULT_SEGMENTED_TOTP_FIELDS = 6;
|
||||
|
||||
/**
|
||||
* @Object kpxcFields
|
||||
* Provides methods for input field handling.
|
||||
|
|
@ -92,9 +94,12 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
|
|||
if (!kpxc.settings.showOTPIcon) {
|
||||
return;
|
||||
}
|
||||
const addTotpFieldsToCombination = function(inputFields) {
|
||||
|
||||
let exceptionFound = false;
|
||||
|
||||
const addTotpFieldsToCombination = function(inputFields, ignoreLength = false) {
|
||||
const totpInputs = Array.from(inputFields).filter(e => e.nodeName === 'INPUT' && e.type !== 'password' && e.type !== 'hidden');
|
||||
if (totpInputs.length === 6) {
|
||||
if (totpInputs.length === DEFAULT_SEGMENTED_TOTP_FIELDS || ignoreLength) {
|
||||
const combination = {
|
||||
form: form,
|
||||
totpInputs: totpInputs,
|
||||
|
|
@ -121,7 +126,7 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
|
|||
}
|
||||
|
||||
// Accept 6 inputs directly
|
||||
if (currentForm.length === 6) {
|
||||
if (currentForm.length === DEFAULT_SEGMENTED_TOTP_FIELDS) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -132,6 +137,12 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Accept any other site-specific exceptions
|
||||
if (kpxcSites.segmentedTotpExceptionFound(currentForm)) {
|
||||
exceptionFound = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
@ -141,8 +152,8 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
|
|||
|| (form.name && typeof(form.name) === 'string' && form.name.includes(f))
|
||||
|| formLengthMatches(form)))) {
|
||||
// Use the form's elements
|
||||
addTotpFieldsToCombination(form.elements);
|
||||
} else if (inputs.length === 6 && inputs.every(i => (i.inputMode === 'numeric' && i.pattern.includes('0-9'))
|
||||
addTotpFieldsToCombination(form.elements, exceptionFound);
|
||||
} else if (inputs.length === DEFAULT_SEGMENTED_TOTP_FIELDS && inputs.every(i => (i.inputMode === 'numeric' && i.pattern.includes('0-9'))
|
||||
|| (i.type === 'text' && i.maxLength === 1)
|
||||
|| i.type === 'tel')) {
|
||||
// No form is found, but input fields are possibly segmented TOTP fields
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ kpxcFill.setTOTPValue = function(elem, val) {
|
|||
}
|
||||
|
||||
for (const comb of kpxc.combinations) {
|
||||
if (comb.totpInputs && comb.totpInputs.length === 6) {
|
||||
if (comb.totpInputs && comb.totpInputs.length > 0) {
|
||||
kpxcFill.fillSegmentedTotp(elem, val, comb.totpInputs);
|
||||
return;
|
||||
}
|
||||
|
|
@ -186,11 +186,11 @@ kpxcFill.setTOTPValue = function(elem, val) {
|
|||
|
||||
// Fill TOTP in parts
|
||||
kpxcFill.fillSegmentedTotp = function(elem, val, totpInputs) {
|
||||
if (!totpInputs.includes(elem)) {
|
||||
if (!totpInputs.includes(elem) || val.length < totpInputs.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < 6; ++i) {
|
||||
for (let i = 0; i < totpInputs.length; ++i) {
|
||||
kpxc.setValue(totpInputs[i], val[i]);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue