Merge pull request #1400 from bitwarden/fix/auto-auto-fill-should-ignore-new-password

Ensure auto auto-fill ignores new-password
This commit is contained in:
Chad Scharf 2020-09-22 08:31:51 -04:00 committed by GitHub
commit 3f76eae543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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({
cipher: this.main.loginToAutoFill,
pageDetails: this.pageDetailsToAutoFill,
fillNewPassword: true
});
if (totpCode != null) {

View File

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

View File

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

View File

@ -126,7 +126,7 @@ export default class AutofillService implements AutofillServiceInterface {
getFormsWithPasswordFields(pageDetails: AutofillPageDetails): 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) {
return formData;
}
@ -174,6 +174,7 @@ export default class AutofillService implements AutofillServiceInterface {
skipUsernameOnlyFill: options.skipUsernameOnlyFill || false,
onlyEmptyFields: options.onlyEmptyFields || false,
onlyVisibleFields: options.onlyVisibleFields || false,
fillNewPassword: options.fillNewPassword || false,
cipher: options.cipher,
});
@ -241,6 +242,7 @@ export default class AutofillService implements AutofillServiceInterface {
skipUsernameOnlyFill: !fromCommand,
onlyEmptyFields: !fromCommand,
onlyVisibleFields: !fromCommand,
fillNewPassword: fromCommand,
});
}
@ -326,10 +328,12 @@ export default class AutofillService implements AutofillServiceInterface {
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) {
// 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) {
@ -891,7 +895,7 @@ export default class AutofillService implements AutofillServiceInterface {
}
private loadPasswordFields(pageDetails: AutofillPageDetails, canBeHidden: boolean, canBeReadOnly: boolean,
mustBeEmpty: boolean) {
mustBeEmpty: boolean, fillNewPassword: boolean) {
const arr: AutofillField[] = [];
pageDetails.fields.forEach((f) => {
const isPassword = f.type === 'password';
@ -927,7 +931,8 @@ export default class AutofillService implements AutofillServiceInterface {
return false;
};
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);
}
});