Ensure auto auto-fill ignores new-password

This commit is contained in:
Chad Scharf 2020-09-21 15:41:06 -04:00
parent 5ec2a70027
commit 7f1cc0199b
4 changed files with 13 additions and 5 deletions

View File

@ -188,6 +188,7 @@ export default class RuntimeBackground {
const totpCode = await this.autofillService.doAutoFill({ const totpCode = await this.autofillService.doAutoFill({
cipher: this.main.loginToAutoFill, cipher: this.main.loginToAutoFill,
pageDetails: this.pageDetailsToAutoFill, pageDetails: this.pageDetailsToAutoFill,
fillNewPassword: true
}); });
if (totpCode != null) { if (totpCode != null) {

View File

@ -147,6 +147,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
cipher: cipher, cipher: cipher,
pageDetails: this.pageDetails, pageDetails: this.pageDetails,
doc: window.document, doc: window.document,
fillNewPassword: true,
}); });
this.analytics.eventTrack.next({ action: 'Autofilled' }); this.analytics.eventTrack.next({ action: 'Autofilled' });
if (this.totpCode != null) { if (this.totpCode != null) {

View File

@ -220,6 +220,7 @@ export class ViewComponent extends BaseViewComponent {
cipher: this.cipher, cipher: this.cipher,
pageDetails: this.pageDetails, pageDetails: this.pageDetails,
doc: window.document, doc: window.document,
fillNewPassword: true,
}); });
if (this.totpCode != null) { if (this.totpCode != null) {
this.platformUtilsService.copyToClipboard(this.totpCode, { window: window }); this.platformUtilsService.copyToClipboard(this.totpCode, { window: window });

View File

@ -126,7 +126,7 @@ export default class AutofillService implements AutofillServiceInterface {
getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] { getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] {
const formData: any[] = []; const formData: any[] = [];
const passwordFields = this.loadPasswordFields(pageDetails, true, true, false); const passwordFields = this.loadPasswordFields(pageDetails, true, true, false, false);
if (passwordFields.length === 0) { if (passwordFields.length === 0) {
return formData; return formData;
} }
@ -174,6 +174,7 @@ export default class AutofillService implements AutofillServiceInterface {
skipUsernameOnlyFill: options.skipUsernameOnlyFill || false, skipUsernameOnlyFill: options.skipUsernameOnlyFill || false,
onlyEmptyFields: options.onlyEmptyFields || false, onlyEmptyFields: options.onlyEmptyFields || false,
onlyVisibleFields: options.onlyVisibleFields || false, onlyVisibleFields: options.onlyVisibleFields || false,
fillNewPassword: options.fillNewPassword || false,
cipher: options.cipher, cipher: options.cipher,
}); });
@ -241,6 +242,7 @@ export default class AutofillService implements AutofillServiceInterface {
skipUsernameOnlyFill: !fromCommand, skipUsernameOnlyFill: !fromCommand,
onlyEmptyFields: !fromCommand, onlyEmptyFields: !fromCommand,
onlyVisibleFields: !fromCommand, onlyVisibleFields: !fromCommand,
fillNewPassword: fromCommand,
}); });
} }
@ -326,10 +328,12 @@ export default class AutofillService implements AutofillServiceInterface {
return fillScript; return fillScript;
} }
let passwordFields = this.loadPasswordFields(pageDetails, false, false, options.onlyEmptyFields); let passwordFields = this.loadPasswordFields(pageDetails, false, false, options.onlyEmptyFields,
options.fillNewPassword);
if (!passwordFields.length && !options.onlyVisibleFields) { if (!passwordFields.length && !options.onlyVisibleFields) {
// not able to find any viewable password fields. maybe there are some "hidden" ones? // not able to find any viewable password fields. maybe there are some "hidden" ones?
passwordFields = this.loadPasswordFields(pageDetails, true, true, options.onlyEmptyFields); passwordFields = this.loadPasswordFields(pageDetails, true, true, options.onlyEmptyFields,
options.fillNewPassword);
} }
for (const formKey in pageDetails.forms) { for (const formKey in pageDetails.forms) {
@ -891,7 +895,7 @@ export default class AutofillService implements AutofillServiceInterface {
} }
private loadPasswordFields(pageDetails: AutofillPageDetails, canBeHidden: boolean, canBeReadOnly: boolean, private loadPasswordFields(pageDetails: AutofillPageDetails, canBeHidden: boolean, canBeReadOnly: boolean,
mustBeEmpty: boolean) { mustBeEmpty: boolean, fillNewPassword: boolean) {
const arr: AutofillField[] = []; const arr: AutofillField[] = [];
pageDetails.fields.forEach((f) => { pageDetails.fields.forEach((f) => {
const isPassword = f.type === 'password'; const isPassword = f.type === 'password';
@ -927,7 +931,8 @@ export default class AutofillService implements AutofillServiceInterface {
return false; return false;
}; };
if (!f.disabled && (canBeReadOnly || !f.readonly) && (isPassword || isLikePassword()) if (!f.disabled && (canBeReadOnly || !f.readonly) && (isPassword || isLikePassword())
&& (canBeHidden || f.viewable) && (!mustBeEmpty || f.value == null || f.value.trim() === '')) { && (canBeHidden || f.viewable) && (!mustBeEmpty || f.value == null || f.value.trim() === '')
&& (fillNewPassword || f.autoCompleteType !== 'new-password')) {
arr.push(f); arr.push(f);
} }
}); });