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

[PM-17780] Running the exposed passwords synchronously #13163

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export type WeakPasswordScore = {
* How many times a password has been exposed
*/
export type ExposedPasswordDetail = {
cipherId: string;
exposedXTimes: number;
} | null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export class RiskInsightsReportService {
): Promise<CipherHealthReportDetail[]> {
const cipherHealthReports: CipherHealthReportDetail[] = [];
const passwordUseMap = new Map<string, number>();
const exposedDetails = await this.findExposedPasswords(ciphers);
for (const cipher of ciphers) {
if (this.validateCipher(cipher)) {
const weakPassword = this.findWeakPassword(cipher);
Expand All @@ -189,7 +190,7 @@ export class RiskInsightsReportService {
passwordUseMap.set(cipher.login.password, 1);
}

const exposedPassword = await this.findExposedPassword(cipher);
const exposedPassword = exposedDetails.find((x) => x.cipherId === cipher.id);

// Get the cipher members
const cipherMembers = memberDetails.filter((x) => x.cipherId === cipher.id);
Expand Down Expand Up @@ -255,13 +256,29 @@ export class RiskInsightsReportService {
return appReports;
}

private async findExposedPassword(cipher: CipherView): Promise<ExposedPasswordDetail> {
const exposedCount = await this.auditService.passwordLeaked(cipher.login.password);
if (exposedCount > 0) {
const exposedDetail = { exposedXTimes: exposedCount } as ExposedPasswordDetail;
return exposedDetail;
}
return null;
private async findExposedPasswords(ciphers: CipherView[]): Promise<ExposedPasswordDetail[]> {
const exposedDetails: ExposedPasswordDetail[] = [];
const promises: Promise<void>[] = [];

ciphers.forEach((ciph) => {
if (this.validateCipher(ciph)) {
const promise = this.auditService
.passwordLeaked(ciph.login.password)
.then((exposedCount) => {
if (exposedCount > 0) {
const detail = {
exposedXTimes: exposedCount,
cipherId: ciph.id,
} as ExposedPasswordDetail;
exposedDetails.push(detail);
}
});
promises.push(promise);
}
});
await Promise.all(promises);
Comment on lines +276 to +279
Copy link
Contributor

Choose a reason for hiding this comment

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

๐ŸŒฑ As we are using this pattern over a couple of services (password-health.service and exposed-password-report), could you please looking into merging this into a single service, than can be called from the different components/services that need it.


return exposedDetails;
}

private findWeakPassword(cipher: CipherView): WeakPasswordDetail {
Expand Down