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

[SG-1026 / PM-1125] - Document / Improve Form Detection in Notification Bar #4798

Conversation

JaredSnider-Bitwarden
Copy link
Contributor

@JaredSnider-Bitwarden JaredSnider-Bitwarden commented Feb 17, 2023

Type of change

- [X] Bug fix
- [ ] New feature development
- [X] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [X] Other

Objectives

SG-1026 / PM-1125

  1. Document the notification-bar.ts to provide additional clarity in preparation for handoff to new autofill team.
  2. Review user reported failures of form detection for (1) Account Creation (2) Password Changes and (3) Adding New logins not yet tracked by Bitwarden, and identify areas for improvement
  3. Surgically refactor / address smaller bugs to improve the reliability of showing the notification bar (with a bias towards false positives if possible) while writing up recommendations for any changes needed to resolve larger issues.

Code changes

This might be easier to review by commits, but I'll break down the largest changes here as well:

  • apps/browser/src/autofill/services/autofill.service.ts:

    • On account creation, even if the pageDetails contained a valid form to watch, the loadPasswordFields method parameter for fillNewPassword being false for inputs with autoCompleteType of "new-password" would cause the account creation form to not be watched (null form data returned to notification bar). Setting this to true will help capture more account creations in the above specified scenario.
      • AutofillService.loadPasswordFields(pageDetails, true, true, false, **true**);
      • Website used: talkshoe.com - pulled from user reported spreadsheet and used for some testing as it had easy account creation / deletion features
    • Added additional logic to group most likely related password fields to improve detection of password change forms with poor mark up design
  • apps/browser/src/autofill/content/notification-bar.ts:

    • Added code regions / JS Doc style method comments / inline comments to document all behavior to improve code approachability
    • Added TypeScript types where possible
    • Improved form detection on load and page change
      • Refactored the page details collection on load behavior to eagerly setup mutation observer while still waiting 1 second minimum to collect the page details to prevent forms from being missed
      • Built deterministic hook for mutation observer to call the new handlePageChange(...) method on SPA page change vs. just depending on a scheduled call to the same method.
    • Improved form submit button listening logic
      • When retrieving a form submit button, we must use both the loginButtonNames and the changePasswordButton names as we don't know what type of form we are listening to.
    • Added new fallback to submit button retrieval logic
      • If we cannot find a submit button within a form, try going up one level to the parent element and searching again
    • Improve formSubmitted logic
      • When listening to a form with a submit button, we can attach the form one password id to the button so we can only have DOM traversal in one location and retrieve the form off the button later on in the form submission logic.
        • For now, I just added it as a fallback, but it could be the primary approach with more testing.
      • Added logic for handling multi-step login forms where the next button gets swapped for a submit button
        • Website used: login.live.com
        • This logic works sometimes as the submit button page change often stops the submit button event listeners from being able to fire and send the login to the background script. However, that is a separate issue to be solved, and sometimes is better than never.
        • This type of logic might be useful in solving the multi-step account creation form on https://signup.live.com/signup but that will require additional changes to the autofill service which currently intercepts forms without passwords and prevents them from reaching the notification-bar.ts content script.

Before you submit

  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

…ies for specific sites as part of research to identify areas for possible improvement + added types where appropriate.
…com), even if the pageDetails contained a valid form to watch, the loadPasswordFields method parameter for fillNewPassword being false for inputs with autoCompleteType of "new-password" would cause the account creation form to not be watched (null form data returned to notification bar). Setting this to true will help capture more account creations in the above specified scenario.
…d change form on talkshoe.com: (1) Update autofill.service getFormsWithPasswordFields(...) method to group autofill.js found password type fields under a single form in a very specific scenario where the most likely case is that it is a password change form with poorly designed mark up in a SPA (2) Notification bar - when listening to a form, we must use both the loginButtonNames and the changePasswordButton names as we don't know what type of form we are listening to (3) Notification bar - on page change, we must empty out the watched forms array to prevent forms w/ the same opId being added to the array on SPA url change (4) Notification bar - getSubmitButton update - If we cannot find a submit button within a form, try going up one level to the parent element and searching again (+ added save to changePasswordButtonNames). (5) Notification bar - when listening to a form with a submit button, we can attach the formOpId to the button so we can only have DOM traversal in one location and retrieve the form off the button later on in the form submission logic. For now, I'm just adding it as a fallback, but it could be the primary approach with more testing.
…ould start observing the DOM immediately so we properly catch rendered forms instead of waiting for a second. This was especially prevelant on refreshing the password change form page on talkshoe.com.
…ollectPageDetailsIfNeeded (now handlePageChange), the mutation observer could get setup late and miss forms loading (ex: refreshing a password change page on talkshoe.com). DOM observation is now setup as fast as possible on page load for SPAs/Non SPAs and on change for SPAs by having the mutation observer itself detect page change and deterministically calling handlePageChange(). However, with these changes, page detail collection still only occurs after a minimum of ~1 second whether or not it was triggered from the mutation observer detecting forms being injected onto the page or the scheduleHandlePageChange running (which has a theoretical maximum time to page detail collection of ~1.999 seconds but this does require the mutation observer to miss the page change in a SPA which shouldn't happen).
…ll service which prevents multi-step account creation forms from being returned to the notification-bar content script from the notification.background.ts script.
…multi-step login form (email then password on https://login.live.com/login.srf) with next button that gets swapped out for a true submit button in order to prompt for saving user credentials if not in Bitwarden. This logic works *sometimes* as the submit button page change often stops the submit button event listeners from being able to fire and send the login to the background script. However, that is a separate issue to be solved, and sometimes is better than never. This type of logic might be useful in solving the multi-step account creation form on https://signup.live.com/signup but that will require additional changes to the autofill service which current intercepts forms without passwords and prevents them from reaching the notification-bar.ts content script.
@JaredSnider-Bitwarden JaredSnider-Bitwarden changed the title Sg 1026 document and research autofill notification bar [SG-1026] - Document / Improve Form Detection in Notification Bar Feb 22, 2023
@JaredSnider-Bitwarden JaredSnider-Bitwarden marked this pull request as ready for review February 22, 2023 17:51
@JaredSnider-Bitwarden JaredSnider-Bitwarden changed the title [SG-1026] - Document / Improve Form Detection in Notification Bar [SG-1026 / PM-1125] - Document / Improve Form Detection in Notification Bar Feb 22, 2023
@JaredSnider-Bitwarden JaredSnider-Bitwarden requested a review from a team as a code owner March 2, 2023 15:18
@github-actions github-actions bot added the needs-qa Marks a PR as requiring QA approval label Mar 2, 2023
@sonarcloud
Copy link

sonarcloud bot commented Apr 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@differsthecat differsthecat left a comment

Choose a reason for hiding this comment

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

Couple of comments; the main one being some concerns with the tree walker changes potentially slowing pages down.

Copy link
Member

@differsthecat differsthecat left a comment

Choose a reason for hiding this comment

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

Fantastic work on this @JaredSnider-Bitwarden !

Copy link
Contributor

@djsmith85 djsmith85 left a comment

Choose a reason for hiding this comment

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

@JaredSnider-Bitwarden: Outstanding work 🚀
Breaking sections down, documenting them, renaming things to clarify what is going on and then starting to add some tweaks for a better detection 💪 :bitwarden-love

This is a huge step, to aid the AutoFill team to start working on this.

Thank you so much for looking into this!

@JaredSnider-Bitwarden JaredSnider-Bitwarden removed the needs-qa Marks a PR as requiring QA approval label Apr 13, 2023
@JaredSnider-Bitwarden
Copy link
Contributor Author

QA tested and approved to merge.

@JaredSnider-Bitwarden JaredSnider-Bitwarden merged commit b3d4d98 into master Apr 13, 2023
@JaredSnider-Bitwarden JaredSnider-Bitwarden deleted the SG-1026-document-and-research-autofill-notification-bar branch April 13, 2023 19:59
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.

None yet

3 participants