Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FormAnalyzer] add external link check for submit buttons #736

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

dbajpeyi
Copy link
Collaborator

@dbajpeyi dbajpeyi commented Jan 10, 2025

Reviewer: @alistairjcbrown
Asana: https://app.asana.com/0/1200930669568058/1209102571867762

Description

It seems like the "Create a User ID" text in fedex' login form is wrongly scored, even though it's actually from a "link" that is outbound and the score should be flipped in this case (notice +4)
image

We already have this logic that is supposed to catch similar links, but sadly the anchor tag in question never reaches it, since it has a "button" like class:

Screenshot 2025-01-14 at 16 16 40

Which means, we should also check for outbound links when checking submit buttons https://github.com/duckduckgo/duckduckgo-autofill/blob/main/src/Form/FormAnalyzer.js#L282

Score after the changes

Screenshot 2025-01-14 at 16 24 04

Other approaches considered

Scanner didn't catch the "Login" submit button, because the form builder bailed out early as the login button is too far. We don't want to ideally increase the depth of the builder as it has significant performance impact.

Steps to test

@dbajpeyi dbajpeyi force-pushed the dbajpeyi/fix/fedex.com branch from 58f30a4 to 6422fea Compare January 10, 2025 11:16
@dbajpeyi dbajpeyi changed the title fix: add external link check for submit buttons [FormAnalyzer] add external link check for submit buttons Jan 10, 2025
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/fix/fedex.com branch from 444a434 to 8e887fd Compare January 10, 2025 14:52
@dbajpeyi dbajpeyi changed the title [FormAnalyzer] add external link check for submit buttons [WIP][FormAnalyzer] add external link check for submit buttons Jan 10, 2025
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/fix/fedex.com branch from 8e887fd to 6e1ef70 Compare January 14, 2025 15:05
@dbajpeyi dbajpeyi changed the title [WIP][FormAnalyzer] add external link check for submit buttons [FormAnalyzer] add external link check for submit buttons Jan 14, 2025
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/fix/fedex.com branch from 6e1ef70 to 72ea68c Compare January 14, 2025 15:09
@dbajpeyi dbajpeyi marked this pull request as ready for review January 14, 2025 15:14
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/fix/fedex.com branch from 72ea68c to a42b5c7 Compare January 14, 2025 15:23
);
};

return isCustomWebElementLink || isElementLikelyALink(el) || isElementLikelyALink(el.closest('a'));
Copy link
Collaborator Author

@dbajpeyi dbajpeyi Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the use of closest here, it seems to be performant as it's natively implemented.

Copy link
Member

@alistairjcbrown alistairjcbrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven’t had a chance to run this, bur reading through the code LGTM :shipit: — and awesome that it didn’t cause any regressions on the other forms 🎉

const isElementLikelyALink = (el) => {
if (el == null) return false;
return (
(el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#') ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: Should we check that it’s not a document fragment too?

Suggested change
(el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#') ||
(el instanceof HTMLAnchorElement && el.href && !el.getAttribute('href').startsWith('#') ||

Copy link
Collaborator Author

@dbajpeyi dbajpeyi Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a nice improvement! 281e61f

@dbajpeyi dbajpeyi force-pushed the dbajpeyi/fix/fedex.com branch from 8ff3e82 to 281e61f Compare January 16, 2025 16:09
@dbajpeyi dbajpeyi merged commit 9ab91fc into main Jan 16, 2025
1 check passed
@dbajpeyi dbajpeyi deleted the dbajpeyi/fix/fedex.com branch January 16, 2025 16:18
graeme added a commit to duckduckgo/BrowserServicesKit that referenced this pull request Jan 31, 2025
Task/Issue URL:
https://app.asana.com/0/1209268905749226/1209268905749226
Autofill Release:
https://github.com/duckduckgo/duckduckgo-autofill/releases/tag/16.2.0


## Description
Updates Autofill to version
[16.2.0](https://github.com/duckduckgo/duckduckgo-autofill/releases/tag/16.2.0).

### Autofill 16.2.0 release notes
## What's Changed
* [Matching] Update regex to match for 'confirm password' by @dbajpeyi
in duckduckgo/duckduckgo-autofill#719
* Update password-related json files (2025-01-06) by @daxmobile in
duckduckgo/duckduckgo-autofill#730
* [FormAnalyzer] Use conservative regex for attributes by @dbajpeyi in
duckduckgo/duckduckgo-autofill#735
* [FormAnalyzer] Don't flip scores on buttons with specific text by
@dbajpeyi in duckduckgo/duckduckgo-autofill#725
* [FormAnalyzer] add external link check for submit buttons by @dbajpeyi
in duckduckgo/duckduckgo-autofill#736
* [FormAnalyzer] scoring password hints by @dbajpeyi in
duckduckgo/duckduckgo-autofill#720
* [Matching] only allow matching on password types by @dbajpeyi in
duckduckgo/duckduckgo-autofill#740
* [Autofill utils] Form wrapper failsafe documentation by @dbajpeyi in
duckduckgo/duckduckgo-autofill#741
* [Form] phone and credit card for recategorization by @dbajpeyi in
duckduckgo/duckduckgo-autofill#733


**Full Changelog**:
duckduckgo/duckduckgo-autofill@16.1.0...16.2.0

## Steps to test
This release has been tested during autofill development. For smoke test
steps see [this
task](https://app.asana.com/0/1198964220583541/1200583647142330/f).

Co-authored-by: dbajpeyi <3018923+dbajpeyi@users.noreply.github.com>
Co-authored-by: Graeme Arthur <2030310+graeme@users.noreply.github.com>
CDRussell pushed a commit to duckduckgo/Android that referenced this pull request Feb 3, 2025
Task/Issue URL:
https://app.asana.com/0/1209268903907280/1209268903907280
Autofill Release:
https://github.com/duckduckgo/duckduckgo-autofill/releases/tag/16.2.0


## Description
Updates Autofill to version
[16.2.0](https://github.com/duckduckgo/duckduckgo-autofill/releases/tag/16.2.0).

### Autofill 16.2.0 release notes
## What's Changed
* [Matching] Update regex to match for 'confirm password' by @dbajpeyi
in duckduckgo/duckduckgo-autofill#719
* Update password-related json files (2025-01-06) by @daxmobile in
duckduckgo/duckduckgo-autofill#730
* [FormAnalyzer] Use conservative regex for attributes by @dbajpeyi in
duckduckgo/duckduckgo-autofill#735
* [FormAnalyzer] Don't flip scores on buttons with specific text by
@dbajpeyi in duckduckgo/duckduckgo-autofill#725
* [FormAnalyzer] add external link check for submit buttons by @dbajpeyi
in duckduckgo/duckduckgo-autofill#736
* [FormAnalyzer] scoring password hints by @dbajpeyi in
duckduckgo/duckduckgo-autofill#720
* [Matching] only allow matching on password types by @dbajpeyi in
duckduckgo/duckduckgo-autofill#740
* [Autofill utils] Form wrapper failsafe documentation by @dbajpeyi in
duckduckgo/duckduckgo-autofill#741
* [Form] phone and credit card for recategorization by @dbajpeyi in
duckduckgo/duckduckgo-autofill#733


**Full Changelog**:
duckduckgo/duckduckgo-autofill@16.1.0...16.2.0

## Steps to test
This release has been tested during autofill development. For smoke test
steps see [this
task](https://app.asana.com/0/1198964220583541/1200583647142330/f).

Co-authored-by: dbajpeyi <3018923+dbajpeyi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants