From 85b0b7b75f607c12e883d97c591f8b714719fcdb Mon Sep 17 00:00:00 2001 From: Deepankar Bajpeyi Date: Fri, 10 Jan 2025 13:52:26 +0100 Subject: [PATCH] [FormAnalyzer] Don't flip scores on buttons with specific text (#725) * fix: don't flip scores on buttons with specific text * test: add new form (revolut) * feat: evaluate checkboxes * Revert "feat: evaluate checkboxes" This reverts commit dba49b44a8a289f8977931a543a8278a24d2acd9. * fix: don't check for persistent login in button text --- dist/autofill-debug.js | 13 ++- dist/autofill.js | 13 ++- src/Form/FormAnalyzer.js | 13 ++- .../Resources/assets/autofill-debug.js | 13 ++- swift-package/Resources/assets/autofill.js | 13 ++- test-forms/auth_wetransfer_com_login.html | 68 ++++++++++++ test-forms/freshdirect_com_login.html | 46 ++++++++ test-forms/index.json | 5 +- test-forms/revolut_business_login.html | 105 ++++++++++++++++++ 9 files changed, 278 insertions(+), 11 deletions(-) create mode 100644 test-forms/auth_wetransfer_com_login.html create mode 100644 test-forms/freshdirect_com_login.html create mode 100644 test-forms/revolut_business_login.html diff --git a/dist/autofill-debug.js b/dist/autofill-debug.js index 89295c5b9..58030101b 100644 --- a/dist/autofill-debug.js +++ b/dist/autofill-debug.js @@ -11230,8 +11230,7 @@ class FormAnalyzer { } else { // Here we don't think this is a submit, so if there is another submit in the form, flip the score const thereIsASubmitButton = Boolean(this.form.querySelector('input[type=submit], button[type=submit]')); - const isSocialButton = /facebook|twitter|google|apple/i.test(string); - shouldFlip = thereIsASubmitButton && !isSocialButton; + shouldFlip = thereIsASubmitButton && this.shouldFlipScoreForButtonText(string); } const strength = likelyASubmit ? 20 : 4; this.updateSignal({ @@ -11350,6 +11349,16 @@ class FormAnalyzer { this._isCCForm = Boolean(textMatches && deDupedMatches.size > 1); return this._isCCForm; } + + /** + * @param {string} text + * @returns {boolean} + */ + shouldFlipScoreForButtonText(text) { + const isForgotPassword = (0, _autofillUtils.safeRegexTest)(this.matching.getDDGMatcherRegex('resetPasswordLink'), text); + const isSocialButton = /facebook|twitter|google|apple/i.test(text); + return !isForgotPassword && !isSocialButton; + } } var _default = exports.default = FormAnalyzer; diff --git a/dist/autofill.js b/dist/autofill.js index 6256f3b6e..a4d1a1296 100644 --- a/dist/autofill.js +++ b/dist/autofill.js @@ -6867,8 +6867,7 @@ class FormAnalyzer { } else { // Here we don't think this is a submit, so if there is another submit in the form, flip the score const thereIsASubmitButton = Boolean(this.form.querySelector('input[type=submit], button[type=submit]')); - const isSocialButton = /facebook|twitter|google|apple/i.test(string); - shouldFlip = thereIsASubmitButton && !isSocialButton; + shouldFlip = thereIsASubmitButton && this.shouldFlipScoreForButtonText(string); } const strength = likelyASubmit ? 20 : 4; this.updateSignal({ @@ -6987,6 +6986,16 @@ class FormAnalyzer { this._isCCForm = Boolean(textMatches && deDupedMatches.size > 1); return this._isCCForm; } + + /** + * @param {string} text + * @returns {boolean} + */ + shouldFlipScoreForButtonText(text) { + const isForgotPassword = (0, _autofillUtils.safeRegexTest)(this.matching.getDDGMatcherRegex('resetPasswordLink'), text); + const isSocialButton = /facebook|twitter|google|apple/i.test(text); + return !isForgotPassword && !isSocialButton; + } } var _default = exports.default = FormAnalyzer; diff --git a/src/Form/FormAnalyzer.js b/src/Form/FormAnalyzer.js index 8635bacaf..0bef7c7c8 100644 --- a/src/Form/FormAnalyzer.js +++ b/src/Form/FormAnalyzer.js @@ -280,8 +280,7 @@ class FormAnalyzer { } else { // Here we don't think this is a submit, so if there is another submit in the form, flip the score const thereIsASubmitButton = Boolean(this.form.querySelector('input[type=submit], button[type=submit]')); - const isSocialButton = /facebook|twitter|google|apple/i.test(string); - shouldFlip = thereIsASubmitButton && !isSocialButton; + shouldFlip = thereIsASubmitButton && this.shouldFlipScoreForButtonText(string); } const strength = likelyASubmit ? 20 : 4; this.updateSignal({ string, strength, signalType: `button: ${string}`, shouldFlip }); @@ -384,6 +383,16 @@ class FormAnalyzer { this._isCCForm = Boolean(textMatches && deDupedMatches.size > 1); return this._isCCForm; } + + /** + * @param {string} text + * @returns {boolean} + */ + shouldFlipScoreForButtonText(text) { + const isForgotPassword = safeRegexTest(this.matching.getDDGMatcherRegex('resetPasswordLink'), text); + const isSocialButton = /facebook|twitter|google|apple/i.test(text); + return !isForgotPassword && !isSocialButton; + } } export default FormAnalyzer; diff --git a/swift-package/Resources/assets/autofill-debug.js b/swift-package/Resources/assets/autofill-debug.js index 89295c5b9..58030101b 100644 --- a/swift-package/Resources/assets/autofill-debug.js +++ b/swift-package/Resources/assets/autofill-debug.js @@ -11230,8 +11230,7 @@ class FormAnalyzer { } else { // Here we don't think this is a submit, so if there is another submit in the form, flip the score const thereIsASubmitButton = Boolean(this.form.querySelector('input[type=submit], button[type=submit]')); - const isSocialButton = /facebook|twitter|google|apple/i.test(string); - shouldFlip = thereIsASubmitButton && !isSocialButton; + shouldFlip = thereIsASubmitButton && this.shouldFlipScoreForButtonText(string); } const strength = likelyASubmit ? 20 : 4; this.updateSignal({ @@ -11350,6 +11349,16 @@ class FormAnalyzer { this._isCCForm = Boolean(textMatches && deDupedMatches.size > 1); return this._isCCForm; } + + /** + * @param {string} text + * @returns {boolean} + */ + shouldFlipScoreForButtonText(text) { + const isForgotPassword = (0, _autofillUtils.safeRegexTest)(this.matching.getDDGMatcherRegex('resetPasswordLink'), text); + const isSocialButton = /facebook|twitter|google|apple/i.test(text); + return !isForgotPassword && !isSocialButton; + } } var _default = exports.default = FormAnalyzer; diff --git a/swift-package/Resources/assets/autofill.js b/swift-package/Resources/assets/autofill.js index 6256f3b6e..a4d1a1296 100644 --- a/swift-package/Resources/assets/autofill.js +++ b/swift-package/Resources/assets/autofill.js @@ -6867,8 +6867,7 @@ class FormAnalyzer { } else { // Here we don't think this is a submit, so if there is another submit in the form, flip the score const thereIsASubmitButton = Boolean(this.form.querySelector('input[type=submit], button[type=submit]')); - const isSocialButton = /facebook|twitter|google|apple/i.test(string); - shouldFlip = thereIsASubmitButton && !isSocialButton; + shouldFlip = thereIsASubmitButton && this.shouldFlipScoreForButtonText(string); } const strength = likelyASubmit ? 20 : 4; this.updateSignal({ @@ -6987,6 +6986,16 @@ class FormAnalyzer { this._isCCForm = Boolean(textMatches && deDupedMatches.size > 1); return this._isCCForm; } + + /** + * @param {string} text + * @returns {boolean} + */ + shouldFlipScoreForButtonText(text) { + const isForgotPassword = (0, _autofillUtils.safeRegexTest)(this.matching.getDDGMatcherRegex('resetPasswordLink'), text); + const isSocialButton = /facebook|twitter|google|apple/i.test(text); + return !isForgotPassword && !isSocialButton; + } } var _default = exports.default = FormAnalyzer; diff --git a/test-forms/auth_wetransfer_com_login.html b/test-forms/auth_wetransfer_com_login.html new file mode 100644 index 000000000..f16bc1292 --- /dev/null +++ b/test-forms/auth_wetransfer_com_login.html @@ -0,0 +1,68 @@ +
+ +
+
+

Or better yet...

+
+
+
+
+
+ +
+ +
+
diff --git a/test-forms/freshdirect_com_login.html b/test-forms/freshdirect_com_login.html new file mode 100644 index 000000000..0367095dd --- /dev/null +++ b/test-forms/freshdirect_com_login.html @@ -0,0 +1,46 @@ +
+
+
+
+ + > + +
+
+
+
+
+
+ + +
+
+
+

+
+
+
+
+
diff --git a/test-forms/index.json b/test-forms/index.json index f1bd0c77f..ed90df92e 100644 --- a/test-forms/index.json +++ b/test-forms/index.json @@ -548,5 +548,8 @@ { "html": "accounts_oneplus_login.html"}, { "html": "google_password_manager_search.html"}, { "html": "paperlesspost_login.html"}, - { "html": "deltamath_reset_password.html"} + { "html": "deltamath_reset_password.html"}, + { "html": "freshdirect_com_login.html"}, + { "html": "auth_wetransfer_com_login.html"}, + { "html": "revolut_business_login.html"} ] diff --git a/test-forms/revolut_business_login.html b/test-forms/revolut_business_login.html new file mode 100644 index 000000000..8a575240e --- /dev/null +++ b/test-forms/revolut_business_login.html @@ -0,0 +1,105 @@ +Form is seen as signup instead it's a signin (offers to generate a password). +
+
+
+
+
+ +
+
+
+ + + + +
+
+
+ +
+
+
+ + Privacy Policy +
+