1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 23:03:32 +00:00

Throttle calls to HIBP api (#25)

Randomly failing to check by passwords, I'm pretty sure its because ~2000 connections are made at the same time.
This commit is contained in:
Fred Cox
2019-02-02 17:17:44 +02:00
committed by Kyle Spearrin
parent ff0e166755
commit db37a831e4
3 changed files with 169 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ import { ApiService } from '../abstractions/api.service';
import { AuditService as AuditServiceAbstraction } from '../abstractions/audit.service';
import { CryptoFunctionService } from '../abstractions/cryptoFunction.service';
import { throttle } from '../misc/throttle';
import { Utils } from '../misc/utils';
import { BreachAccountResponse } from '../models/response/breachAccountResponse';
@@ -12,6 +13,7 @@ const PwnedPasswordsApi = 'https://api.pwnedpasswords.com/range/';
export class AuditService implements AuditServiceAbstraction {
constructor(private cryptoFunctionService: CryptoFunctionService, private apiService: ApiService) { }
@throttle(100, () => 'passwordLeaked')
async passwordLeaked(password: string): Promise<number> {
const hashBytes = await this.cryptoFunctionService.hash(password, 'sha1');
const hash = Utils.fromBufferToHex(hashBytes).toUpperCase();