Skip to content

Commit

Permalink
hide empty ciphers from autofill
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Bassler authored and Evan Bassler committed Dec 19, 2024
1 parent 6eb30c9 commit 6d09fd9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions apps/browser/src/autofill/background/overlay.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { InlineMenuFormFieldData } from "../services/abstractions/autofill-overl
import { AutofillService, PageDetail } from "../services/abstractions/autofill.service";
import { InlineMenuFieldQualificationService } from "../services/abstractions/inline-menu-field-qualifications.service";
import {
areKeyValuesNull,
generateDomainMatchPatterns,
generateRandomChars,
isInvalidResponseStatusCode,
Expand Down Expand Up @@ -556,6 +557,28 @@ export class OverlayBackground implements OverlayBackgroundInterface {

for (let cipherIndex = 0; cipherIndex < inlineMenuCiphersArray.length; cipherIndex++) {
const [inlineMenuCipherId, cipher] = inlineMenuCiphersArray[cipherIndex];

switch (cipher.type) {
case CipherType.Card:
if (areKeyValuesNull(cipher.card)) {
continue;
}
break;

case CipherType.Identity:
if (areKeyValuesNull(cipher.identity)) {
continue;
}
break;

case CipherType.Login:
if (
areKeyValuesNull(cipher.login, ["username", "password", "totp", "fido2Credentials"])
) {
continue;
}
break;
}
if (!this.focusedFieldMatchesFillType(cipher.type)) {
continue;
}
Expand Down
17 changes: 17 additions & 0 deletions apps/browser/src/autofill/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,20 @@ export const specialCharacterToKeyMap: Record<string, string> = {
"?": "questionCharacterDescriptor",
"/": "forwardSlashCharacterDescriptor",
};

/**
* Checks if all the values corresponding to the specified keys in an object are null.
* If no keys are specified, checks all keys in the object.
*
* @param obj - The object to check.
* @param keys - An optional array of keys to check in the object. Defaults to all keys.
* @returns Returns true if all values for the specified keys (or all keys if none are provided) are null; otherwise, false.
*/
export function areKeyValuesNull<T extends Record<string, any>>(
obj: T,
keys?: Array<keyof T>,
): boolean {
const keysToCheck = keys && keys.length > 0 ? keys : (Object.keys(obj) as Array<keyof T>);

return keysToCheck.every((key) => obj[key] == null);
}

0 comments on commit 6d09fd9

Please sign in to comment.