Skip to content

Commit 5f40d24

Browse files
author
Sami Vänttinen
authored
Fix Steam TOTP (#1711)
Fix Steam TOTP
1 parent 908cd41 commit 5f40d24

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

keepassxc-browser/common/sites.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ kpxcSites.totpExceptionFound = function(field) {
139139
return false;
140140
};
141141

142+
/**
143+
* Handles a few exceptions for certain sites where segmented 2FA fields are not regognized properly.
144+
* @param {object} form Form Element
145+
* @returns {boolean} True if an Element has a match with the needed indentfifiers and document location
146+
*/
147+
kpxcSites.segmentedTotpExceptionFound = function(form) {
148+
if (!form || form.nodeName !== 'FORM') {
149+
return false;
150+
}
151+
152+
if (document.location.href.startsWith('https://store.steampowered.com') && form.length === 5) {
153+
return true;
154+
}
155+
156+
return false;
157+
};
158+
142159
kpxcSites.expectedTOTPMaxLength = function() {
143160
if (document.location.origin.startsWith('https://www.amazon')
144161
&& document.location.href.includes('/ap/mfa')) {

keepassxc-browser/content/fields.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const DEFAULT_SEGMENTED_TOTP_FIELDS = 6;
4+
35
/**
46
* @Object kpxcFields
57
* Provides methods for input field handling.
@@ -92,9 +94,12 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
9294
if (!kpxc.settings.showOTPIcon) {
9395
return;
9496
}
95-
const addTotpFieldsToCombination = function(inputFields) {
97+
98+
let exceptionFound = false;
99+
100+
const addTotpFieldsToCombination = function(inputFields, ignoreLength = false) {
96101
const totpInputs = Array.from(inputFields).filter(e => e.nodeName === 'INPUT' && e.type !== 'password' && e.type !== 'hidden');
97-
if (totpInputs.length === 6) {
102+
if (totpInputs.length === DEFAULT_SEGMENTED_TOTP_FIELDS || ignoreLength) {
98103
const combination = {
99104
form: form,
100105
totpInputs: totpInputs,
@@ -121,7 +126,7 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
121126
}
122127

123128
// Accept 6 inputs directly
124-
if (currentForm.length === 6) {
129+
if (currentForm.length === DEFAULT_SEGMENTED_TOTP_FIELDS) {
125130
return true;
126131
}
127132

@@ -132,6 +137,12 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
132137
return true;
133138
}
134139

140+
// Accept any other site-specific exceptions
141+
if (kpxcSites.segmentedTotpExceptionFound(currentForm)) {
142+
exceptionFound = true;
143+
return true;
144+
}
145+
135146
return false;
136147
};
137148

@@ -141,8 +152,8 @@ kpxcFields.getSegmentedTOTPFields = function(inputs, combinations) {
141152
|| (form.name && typeof(form.name) === 'string' && form.name.includes(f))
142153
|| formLengthMatches(form)))) {
143154
// Use the form's elements
144-
addTotpFieldsToCombination(form.elements);
145-
} else if (inputs.length === 6 && inputs.every(i => (i.inputMode === 'numeric' && i.pattern.includes('0-9'))
155+
addTotpFieldsToCombination(form.elements, exceptionFound);
156+
} else if (inputs.length === DEFAULT_SEGMENTED_TOTP_FIELDS && inputs.every(i => (i.inputMode === 'numeric' && i.pattern.includes('0-9'))
146157
|| (i.type === 'text' && i.maxLength === 1)
147158
|| i.type === 'tel')) {
148159
// No form is found, but input fields are possibly segmented TOTP fields

keepassxc-browser/content/fill.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ kpxcFill.setTOTPValue = function(elem, val) {
175175
}
176176

177177
for (const comb of kpxc.combinations) {
178-
if (comb.totpInputs && comb.totpInputs.length === 6) {
178+
if (comb.totpInputs && comb.totpInputs.length > 0) {
179179
kpxcFill.fillSegmentedTotp(elem, val, comb.totpInputs);
180180
return;
181181
}
@@ -186,11 +186,11 @@ kpxcFill.setTOTPValue = function(elem, val) {
186186

187187
// Fill TOTP in parts
188188
kpxcFill.fillSegmentedTotp = function(elem, val, totpInputs) {
189-
if (!totpInputs.includes(elem)) {
189+
if (!totpInputs.includes(elem) || val.length < totpInputs.length) {
190190
return;
191191
}
192192

193-
for (let i = 0; i < 6; ++i) {
193+
for (let i = 0; i < totpInputs.length; ++i) {
194194
kpxc.setValue(totpInputs[i], val[i]);
195195
}
196196
};

0 commit comments

Comments
 (0)