mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-21 11:25:56 +01:00
Fixed bug with extension fill script when a page has multiple password forms on same page together (register and login). Try to guess proper login form.
This commit is contained in:
parent
16058c5efb
commit
d729f93b17
@ -16,12 +16,59 @@ namespace Bit.iOS.Extension.Models
|
||||
|
||||
DocumentUUID = pageDetails.DocumentUUID;
|
||||
|
||||
var loginForm = pageDetails.Forms.FirstOrDefault(form => pageDetails.Fields.Any(f => f.Form == form.Key && f.Type == "password")).Value;
|
||||
if(loginForm == null)
|
||||
var passwordFields = pageDetails.Fields.Where(f => f.Type == "password");
|
||||
var passwordForms = pageDetails.Forms.Where(form => passwordFields.Any(f => f.Form == form.Key));
|
||||
if(!passwordForms.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PageDetails.Form loginForm = null;
|
||||
if(passwordForms.Count() > 1)
|
||||
{
|
||||
// More than one form with a password field is on the page.
|
||||
// This usually occurs when a website has a login and signup form on the same page.
|
||||
// Let's try to guess which one is the login form.
|
||||
|
||||
// First let's try to guess the correct login form by examining the form attribute strings
|
||||
// for common login form attribute.
|
||||
foreach(var form in passwordForms)
|
||||
{
|
||||
var formDescriptor = string.Format("{0}~{1}~{2}",
|
||||
form.Value?.HtmlName, form.Value?.HtmlId, form.Value?.HtmlAction)
|
||||
?.ToLowerInvariant()?.Replace('_', '-');
|
||||
|
||||
if(formDescriptor.Contains("login") || formDescriptor.Contains("log-in")
|
||||
|| formDescriptor.Contains("signin") || formDescriptor.Contains("sign-in")
|
||||
|| formDescriptor.Contains("logon") || formDescriptor.Contains("log-on"))
|
||||
{
|
||||
loginForm = form.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(loginForm == null)
|
||||
{
|
||||
// Next we can try to find the login form that only has one password field. Typically
|
||||
// a registration form may have two password fields for password confirmation.
|
||||
var fieldGroups = passwordFields.GroupBy(f => f.Form);
|
||||
var singleFields = fieldGroups.FirstOrDefault(f => f.Count() == 1);
|
||||
if(singleFields.Any())
|
||||
{
|
||||
var singlePasswordForms = passwordForms.Where(f => f.Key == singleFields.Key);
|
||||
if(singlePasswordForms.Any())
|
||||
{
|
||||
loginForm = singlePasswordForms.First().Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(loginForm == null)
|
||||
{
|
||||
loginForm = passwordForms.FirstOrDefault().Value;
|
||||
}
|
||||
|
||||
Script = new List<List<string>>();
|
||||
|
||||
var password = pageDetails.Fields.FirstOrDefault(f =>
|
||||
|
@ -10,6 +10,7 @@ BitwardenExtension.prototype = {
|
||||
pageDetails: this.collect(document)
|
||||
};
|
||||
|
||||
console.log(args);
|
||||
arguments.completionFunction(args);
|
||||
},
|
||||
finalize: function (arguments) {
|
||||
|
Loading…
Reference in New Issue
Block a user