commit 6d4f12c6866b3bf2f41888abe014efa679592a02
parent 9243421d508e03d3cd094fb76c109050c7234843
Author: Neil Deakin <neil@mozilla.com>
Date: Tue, 18 Nov 2025 11:47:11 +0000
Bug 1999387, only recognize autocomplete attributes that can be autofilled, r=dimi,credential-management-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D272357
Diffstat:
3 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/browser/extensions/formautofill/test/browser/heuristics/browser_autocomplete_fields.js b/browser/extensions/formautofill/test/browser/heuristics/browser_autocomplete_fields.js
@@ -81,4 +81,39 @@ add_heuristic_tests([
},
],
},
+ {
+ description:
+ "Form containing fields with unused and invalid autocomplete attributes.",
+ fixtureData: `<form>
+ <div>
+ <input autocomplete="postalCode">
+ <label>Postleitzahl*</label>
+ </div>
+ <div>
+ <input autocomplete="street-address">
+ <label>Strasse*</label>
+ </div>
+ <div>
+ <input autocomplete="town">
+ <label>Ort*</label>
+ </div>
+ <div>
+ <input autocomplete="address-level4">
+ <label>Adresszusatz</label>
+ </div>
+ </form>`,
+ expectedResult: [
+ {
+ default: {
+ reason: "regex-heuristic",
+ },
+ fields: [
+ { fieldName: "postal-code" },
+ { fieldName: "street-address", reason: "autocomplete" },
+ { fieldName: "address-level2" },
+ { fieldName: "address-line2" },
+ ],
+ },
+ ],
+ },
]);
diff --git a/toolkit/components/formautofill/shared/FormAutofillHeuristics.sys.mjs b/toolkit/components/formautofill/shared/FormAutofillHeuristics.sys.mjs
@@ -1015,7 +1015,8 @@ export const FormAutofillHeuristics = {
// needs to find the field name.
if (
autocompleteInfo?.fieldName &&
- !["on", "off"].includes(autocompleteInfo.fieldName)
+ !["on", "off"].includes(autocompleteInfo.fieldName) &&
+ !lazy.FormAutofillUtils.isUnsupportedField(autocompleteInfo.fieldName)
) {
inferredInfo.autocompleteInfo = autocompleteInfo;
return [autocompleteInfo.fieldName, inferredInfo];
diff --git a/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs b/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs
@@ -167,6 +167,13 @@ FormAutofillUtils = {
"cc-csc": "creditCard",
},
+ // This list includes autocomplete attributes that indicate that the field
+ // is an address or credit-card field, but the field name is not one we
+ // currently support for autofill. In these cases, we ignore the field
+ // name so that our heuristic can still classify the field using a
+ // supported field name.
+ _unsupportedFieldNameInfo: ["address-level4"],
+
_collators: {},
_reAlternativeCountryNames: {},
@@ -180,6 +187,12 @@ FormAutofillUtils = {
return this._fieldNameInfo?.[fieldName] == "creditCard";
},
+ // Returns true if the field is one we don't fill handle via the autocomplete
+ // attribute. It should be identified using heuristics.
+ isUnsupportedField(fieldName) {
+ return this._unsupportedFieldNameInfo.includes(fieldName);
+ },
+
isCCNumber(ccNumber) {
return ccNumber && lazy.CreditCard.isValidNumber(ccNumber);
},