mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Merge pull request #1909 from keepassxreboot/fix/improvements_to_segmented_totp
Improvements to segmented TOTP field detection
This commit is contained in:
commit
273cdfd2b8
1 changed files with 23 additions and 5 deletions
|
|
@ -56,10 +56,8 @@ kpxcFields.getAllCombinations = async function(inputs) {
|
|||
combinations.push(combination);
|
||||
}
|
||||
|
||||
// Check for multiple segmented TOTP fields
|
||||
if (combinations.length === 0) {
|
||||
kpxcFields.getSegmentedTOTPFields(inputs, combinations);
|
||||
}
|
||||
// Check for segmented TOTP fields
|
||||
kpxcFields.handleSegmentedTOTPFields(inputs, combinations);
|
||||
|
||||
return combinations;
|
||||
};
|
||||
|
|
@ -98,7 +96,7 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
|
|||
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');
|
||||
const totpInputs = Array.from(inputFields).filter(e => e.nodeName === 'INPUT' && e.type !== 'password' && e.type !== 'hidden' && e.type !== 'submit');
|
||||
if (totpInputs.length === DEFAULT_SEGMENTED_TOTP_FIELDS || ignoreLength) {
|
||||
const combination = {
|
||||
form: form,
|
||||
|
|
@ -300,6 +298,26 @@ kpxcFields.getElementFromXPathId = function(xpath) {
|
|||
return (new XPathEvaluator()).evaluate(xpath, document.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
};
|
||||
|
||||
// Checks if inputs or combinations contain segmented TOTP fields
|
||||
kpxcFields.handleSegmentedTOTPFields = function(inputs, combinations) {
|
||||
// Check for multiple segmented TOTP fields when there are no inputs, or combination contains the segemented fields
|
||||
const segmentedFields = combinations.filter(c => c.totp);
|
||||
if (combinations.length === 0 || segmentedFields.length === DEFAULT_SEGMENTED_TOTP_FIELDS) {
|
||||
kpxcFields.getSegmentedTOTPFields(inputs, combinations);
|
||||
}
|
||||
|
||||
// Remove previously detected segmented TOTP fields from the combination.
|
||||
// This prevents adding icons to each single field when segmented fields are used.
|
||||
if (segmentedFields.length === DEFAULT_SEGMENTED_TOTP_FIELDS) {
|
||||
const firstTotpField = combinations.findIndex(c => c.totp);
|
||||
if (firstTotpField >= 0) {
|
||||
combinations.splice(firstTotpField, DEFAULT_SEGMENTED_TOTP_FIELDS);
|
||||
}
|
||||
}
|
||||
|
||||
return combinations;
|
||||
};
|
||||
|
||||
// Check for new password via autocomplete attribute
|
||||
kpxcFields.isAutocompleteAppropriate = function(field) {
|
||||
const autocomplete = field.getLowerCaseAttribute('autocomplete');
|
||||
|
|
|
|||
Loading…
Reference in a new issue